java - Spring oauth2 /oauth/token invalid credentials -


here's application.java

@springbootapplication @restcontroller @enableresourceserver @enableauthorizationserver public class application {      @requestmapping(value = { "/user" }, produces = "application/json")     public map<string, object> user(oauth2authentication user) {         map<string, object> userinfo = new hashmap<>();         userinfo.put("user", user.getuserauthentication().getprincipal());         userinfo.put("authorities", authorityutils.authoritylisttoset(user.getuserauthentication().getauthorities()));         return userinfo;     }       public static void main(string[] args) {         springapplication.run(application.class, args);     }   } 

websecurityconfigurer.java

@configuration public class websecurityconfigurer extends websecurityconfigureradapter {     @override     @bean     public authenticationmanager authenticationmanagerbean() throws exception {         return super.authenticationmanagerbean();     }     @override     protected void configure(httpsecurity http) throws exception {         http.csrf().disable().authorizerequests()                 .antmatchers("/oauth/token").permitall().anyrequest().authenticated().and().formlogin().and().httpbasic();     }      @override     @bean     public userdetailsservice userdetailsservicebean() throws exception {         return super.userdetailsservicebean();     }      @override     protected void configure(authenticationmanagerbuilder auth) throws exception {         auth                 .inmemoryauthentication()                 .withuser("john.carnell").password("password1").roles("user")                 .and()                 .withuser("william.woodward").password("password2").roles("user", "admin");     } } 

my oauth2config

@configuration public class oauth2config extends authorizationserverconfigureradapter {      @autowired     private authenticationmanager authenticationmanager;      @autowired     private userdetailsservice userdetailsservice;      @override     public void configure(clientdetailsserviceconfigurer clients) throws exception {         clients.inmemory()                 .withclient("eagleeye")                 .secret("thisissecret")                 .authorizedgranttypes("refresh_token", "password", "client_credentials")                 .scopes("webclient", "mobileclient");     }      @override     public void configure(authorizationserverendpointsconfigurer endpoints) throws exception {         endpoints                 .authenticationmanager(authenticationmanager)                 .userdetailsservice(userdetailsservice);     } } 

i trying retrieve access token though postman however, error keeps showing up

 {   "timestamp": 1491436452371,   "status": 401,   "error": "unauthorized",   "message": "bad credentials",   "path": "/oauth/token/" } 

these values i'm passing in through postman

enter image description here

enter image description here

as can i'm passing in correct values doubt it's credentials that's causing error

i agree luke bajada. had same problem , fix had add @componentscan annotation , import module writing code parent module adding dependency.


Comments