java - Trying to use Feign to log into Spring OAuth2 server -


i'm looking make grant_type = password login service feign spring oauth2 server. i've confirmed oauth2 server works when make normal rest call. when trying feign, fails.

in service have:

@component @scope("prototype") @feignclient(url = "http://localhost:9999/uaa") public interface authclient {      @requestmapping(value="/oauth/token", method=requestmethod.post)     @headers({"authorization: basic some_base64encoded_client_secret_here=="})     public loginresponse login(             @param("username") string username, @param("password") string password, @param("grant_type") string granttype);  } 

i error: java.lang.classcastexception: cannot cast com.sun.proxy.$proxy129 org.springframework.web.bind.annotation.requestmapping

most examples find show how intercept feign use oauth headers/etc. , assume access token exists. not issue. don't have access token yet because i'm trying access token logging in. ideas on how can log in using feign?

you can map own response this:

@component @feignclient(name = "authclient", url = "http://localhost:8080") public interface authclient {      @requestmapping(value="/oauth/token", method= requestmethod.post)     authresponse login(@requestparam("grant_type") string granttype, @requestparam("username") string username,                    @requestparam("password") string password, @requestparam("scope") string scope);      @jsonautodetect(fieldvisibility = jsonautodetect.visibility.any)     class authresponse {         string access_token;         string token_type;         string refresh_token;         string expires_in;     } }  public class authservice {      private final authclient authclient;      public authservice(authclient authclient) {         this.authclient = authclient;     }      public authclient.authresponse authenticate(string login, string password, string scopes) {         return this.authclient.login("password", "admin", "admin", "read+write");     } } 

you can register request interceptor add authorization headers @ every request:

@bean public basicauthrequestinterceptor basicauthrequestinterceptor() {     return new basicauthrequestinterceptor("clientid", "clientsecret"); } 

this code works sample spring security oauth2 server.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -