【问题标题】:Unable to properly redirect after OAuth2 authentication using Spring Boot使用 Spring Boot 进行 OAuth2 身份验证后无法正确重定向
【发布时间】:2016-11-27 10:14:34
【问题描述】:

我正在尝试构建一个基本的 Spring Boot 应用程序,它允许我将验证用户的工作委托给外部 OAuth2 提供程序,例如 Facebook。

我有两个主要问题:

  1. 身份验证过程完成后,我得到:

对“https://graph.facebook.com/me”的 GET 请求结果为 200(OK)

我还得到以下信息:

使用 [interface java.util.Map] 作为“application/json”读取 [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@2a7ce52b] 委托给 org.springframework.security.web.authentication.session.ChangeSessionIdAuthenticationStrategy@4f061f45 SecurityContext 为空或内容是匿名的 - 上下文不会存储在 HttpSession 中。

就好像解析和存储返回的凭据有问题。

  1. 有时我会收到 401 错误:

身份验证请求失败: org.springframework.security.authentication.BadCredentialsException: 无法获取访问令牌

这是一种偶然事件,我无法追查问题所在。改用 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

非常感谢任何帮助:)

【问题讨论】:

    标签: java spring facebook spring-boot oauth2


    【解决方案1】:

    最后我设法解决了这个问题,spring-boot-starter-tomcat maven 依赖已被标记为<scope>provided</scope>,从而干扰了在嵌入式 tomcat 中正确初始化 spring 上下文对象的能力。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-02
      • 2017-10-01
      • 2016-08-20
      • 2019-08-08
      • 2021-01-21
      • 2011-04-30
      • 2022-01-05
      相关资源
      最近更新 更多