2016-07-23 232 views
0

我正在嘗試構建基本的Spring Boot應用程序,該應用程序允許將用戶身份驗證的工作委託給外部OAuth2提供程序(如Facebook)。使用Spring Boot進行OAuth2身份驗證後無法正確重定向

我有兩個主要問題:

  1. 一旦認證過程完成後,我得到:

GET request for " https://graph.facebook.com/me " resulted in 200 (OK)

我還可以得到以下幾點:

Reading [interface java.util.Map] as "application/json" using [org.springfr[email protected]2a7ce52b] Delegating to org.springframework.security.w[email protected]4f061f45 SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.

這就好像分析和存儲返回的憑證有問題。

  • 有時我得到一個401錯誤:
  • Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Could not obtain access token

    它是某種碰運氣的,我無法追蹤下來的問題。它也發生在使用Google OAuth2時。

    我基本上使用的@ EnableOAuth2Sso註釋,並使用application.yml文件中配置的憑據:

    security: 
        oauth2: 
        client: 
         clientId: 123 
         clientSecret: bla 
         accessTokenUri: https://graph.facebook.com/oauth/access_token 
         userAuthorizationUri: https://www.facebook.com/dialog/oauth 
         tokenName: oauth_token 
         authenticationScheme: query 
         clientAuthenticationScheme: form 
        resource: 
         userInfoUri: https://graph.facebook.com/me 
         preferTokenInfo: false 
    

    任何幫助是非常讚賞:)

    回答

    0

    最後我設法解決這個問題, spring-boot-starter-tomcat maven dependency已被標記爲<scope>provided</scope>,因此干擾了正確初始化嵌入式tomcat中的spring上下文對象的能力。

    相關問題