【问题标题】:Spring Security OAuth2 supporting Facebook appsecret_proofSpring Security OAuth2 支持 Facebook appsecret_proof
【发布时间】:2020-10-26 15:48:23
【问题描述】:

只有在 Facebook Developer 应用程序配置中禁用 "Require App Secret" 选项时,我才能使用 Facebook 登录到我的 SpringBoot 应用程序。
当启用额外的(推荐的)安全检查时,我得到一个错误

org.springframework.security.oauth2.core.OAuth2AuthenticationException: [invalid_user_info_response]
 An error occurred while attempting to retrieve the UserInfo Resource: Error details: [UserInfo Uri: 
   https://graph.facebook.com/me?fields=id,name,email, Error Code: {message=API calls from the server 
    require an appsecret_proof argument, type=GraphMethodException, code=100, fbtrace_id=xxxx}]

很明显,Spring Security 尝试访问 Facebook(调用 https://graph.facebook.com/me?fields=id,name,email)以检索经过身份验证的用户,但未能传递额外参数 appsecret_proof

目前尚不清楚(在深入研究 SpringSecurity 文档和论坛之后)我如何让 Spring 添加额外的令牌。

【问题讨论】:

标签: spring-boot facebook spring-oauth2


【解决方案1】:

我遇到了非常相似的情况 - 我无法使用 facebook 用户帐户登录我的应用程序。

首先确保给定的客户端 ID 和机密 ID 正确(有时可能会与您的其他项目混淆)。如果您确定输入的数据没问题,我会先检查可用的许可证。所以打开 facebook login 插件面板(屏幕右侧应该有一个标签)。

对于我来说,以下配置就足够了:

此外,检查可用的权限和功能:

public_profile 需要访问才能提取想要登录您网站的用户的基本信息。此外,还值得添加电子邮件请求。

同时检查 facebook 客户端的配置,它允许您获取用户令牌:

spring:
  security:
    oauth2:
      client:
        registration:
          facebook:
            clientId: your-client-id
            clientSecret: your-client-secret
            redirectUri: "{baseUrl}/api/oauth2/callback/{registrationId}" # Note that facebook now mandates the use of https redirect URIs, so make sure your app supports https in production
            scope:
              - email
              - public_profile
        provider:
          facebook:
            authorizationUri: https://www.facebook.com/v3.0/dialog/oauth
            tokenUri: https://graph.facebook.com/v3.0/oauth/access_token
            userInfoUri: https://graph.facebook.com/v3.0/me?fields=id,first_name,middle_name,last_name,name,email

就我而言,上述配置足以让用户在外部网站上授权自己。

【讨论】:

    猜你喜欢
    • 2020-05-26
    • 2012-04-11
    • 2012-05-27
    • 2017-12-16
    • 2019-09-25
    • 2013-10-18
    • 2019-05-24
    • 2019-04-29
    • 2017-09-11
    相关资源
    最近更新 更多