2016-09-13 115 views
1

我使用Spring Oauth2.0,使用Google作为授权提供者。我有以下的配置,我application.yml文件Spring OAuth2.0:spring在哪里存储访问令牌?

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 

这是我的主类

@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(); 
    } 

} 

这个我需要访问谷歌的API来得到一些用户信息后,但是这需要一个访问令牌。 Spring存储这个令牌的地方在哪里?我如何检索它?提前致谢 !!

+0

你应该有一个类来配置OAuth2,然后你可以定义一个可以在内存或数据库上的tokenStore。 –

+0

查看'TokenStore' http://docs.spring.io/spring-security/oauth/apidocs/org/springframework/security/oauth2/provider/token/TokenStore.html –

+0

有用的链接[如何获取访问令牌](http://stackoverflow.com/questions/23759529/android-how-to-get-google-plus-access-token) –

回答

0

您可以看到有关Spring和社交登录的this文档,那么当您获得更多经验时可以尝试放置auth微服务,将您的令牌存储在redis上。我在Outlook中使用网关模式,并且必须在客户端配置中指定一个url,oauth服务器将检索该请求中指定的令牌和一些数据。

我希望它有帮助。