1

I am using Spring Oauth2.0 using Google as authorization provider. I have the following configuration in my application.yml file

security:
  oauth2:
    client:
      clientId: xxxxxxxxxxxxxxxxxxxx
      clientSecret: xxxxxxxxxxxxxxxxxx
      accessTokenUri: https://accounts.google.com/o/oauth2/token
      userAuthorizationUri: https://accounts.google.com/o/oauth2/auth
      authenticationScheme: query
      clientAuthenticationScheme: query
      scope: https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/userinfo.profile
    resource:
      userInfoUri: https://www.googleapis.com/oauth2/v3/userinfo
      preferTokenInfo: false

And this is my main class

@SpringBootApplication
@EnableOAuth2Sso
public class App 
{
    public static void main(String[] args) throws Exception {
        SpringApplication.run(App.class, args);    
    }

    @Bean public RequestContextListener requestContextListener(){
        return new RequestContextListener();
    }

}

After this I need to access google api to get some user info but that requires an access token. Where does Spring store this token? How can I retrieve it? Thanks in advance !!

varunkr
  • 5,364
  • 11
  • 50
  • 99
  • you should have a class to configure OAuth2 then you can define a tokenStore that can be on memory or database. – Paulo Galdo Sandoval Sep 13 '16 at 18:17
  • Take a look at `TokenStore` http://docs.spring.io/spring-security/oauth/apidocs/org/springframework/security/oauth2/provider/token/TokenStore.html – Ali Dehghani Sep 13 '16 at 18:24
  • Useful link [how to get access token](http://stackoverflow.com/questions/23759529/android-how-to-get-google-plus-access-token) – Abdelghani Roussi Sep 13 '16 at 21:47
  • @AbelRoussi Thanks for the comment. But I am not able to make it work. It says GoogleAuthUtil not resolved even though I imported the appropriate lib. Looks like this works only for Android. You sure this will work with spring? – varunkr Sep 13 '16 at 22:48
  • @PauloGaldoSandoval thanks for the comment, can u provide link to some tutorial or example. I didn't find any related to tokenStore. Thanks !! – varunkr Sep 14 '16 at 05:44

1 Answers1

0

You can see this documentation about Spring and social login, then when you get more experience could try to put an auth micro service that store your tokens on redis. I use a gateway pattern with Outlook and have to specify a url in the client configuration where the oauth server will retrieve the token and some data specified in the request.

I hope it helps.

Diego Rojas
  • 237
  • 5
  • 11