Java Spring Security: 401 Unauthorized for token OAuth2 end point

Turns out I wasn't hitting the end point correctly. I was sending all of my data, client credentials included, via HTTP POST.

POST http://localhost:8080/oauth/token
...
client_id=client_id&secret=secret&scope=read&grant_type=password&username=user&password=password

I needed to use HTTP Basic Auth to send my client credentials rather than POSTing them:

POST http://localhost:8080/oauth/token
Authorization: Basic Y2xpZW50X2lkOnNlY3JldA==
...
scope=read&grant_type=password&username=user&password=password

try changing your password encoder from your AuthorizationServerConfig class with this simple encoder(it doesn't encrypt passwords).because you don't save your client secret in InMemory storage with encryption.

private PasswordEncoder getPasswordEncoder() {
    return new PasswordEncoder() {
        public String encode (CharSequence charSequence) {
            return charSequence.toString();
        }
        public boolean matches(CharSequence charSequence, String s) {
            return true;
        }
    };
}

hope it will work.