2016-09-13 51 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服務器將檢索該請求中指定的令牌和一些數據。

我希望它有幫助。