使用Spring Boot进行OAuth2身份验证后无法正确重定向

Shlomi Uziel

我正在尝试构建一个基本的Spring Boot应用程序,该应用程序将允许我将对用户进行身份验证的工作委派给外部OAuth2提供程序(例如Facebook)。

我有两个主要问题:

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

GET请求“ https://graph.facebook.com/me ”,结果为200(确定)

我也得到以下信息:

使用[org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@2a7ce52b]将[interface java.util.Map]读取为“ application / json”,委托给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

任何帮助深表感谢 :)

Shlomi Uziel

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用OAuth2以编程方式向Google进行身份验证

使用Spring Security进行身份验证失败后重定向到原始页面

无法使用包“ golang.org/x/oauth2”与facebook进行身份验证:“缺少redirect_uri参数”

使用软件包“ golang.org/x/oauth2”对oauth2进行身份验证

如何使用Spring Boot伪装客户端进行Oauth2身份验证?

Spring Boot + oauth2:访问此资源需要完全身份验证

如何使用Spring Boot + Angular处理外部OAuth2身份验证

使用OAuth2在Office 365中进行IMAP身份验证

使用Spring Security oauth2进行两因素身份验证

在ASP.Net MVC中使用OpenIdConnect进行身份验证后重定向用户

在Spring Boot OAuth2授权服务器中使用Active Directory身份验证

OAuth2:使用电子邮件(而不是用户名)进行身份验证

使用Spring Security进行gRPC和OAuth2身份验证

使用OAuth2进行Geoserver身份验证

如何使用REST API使用OAuth2和React Native进行身份验证?

使用jwt身份验证登录后如何重定向

spring boot oauth2-使用基本身份验证时无法获取访问令牌

使用Azure AD通过OAuth2对Azure API管理进行身份验证

在iOS上使用OAuth2进行身份验证

OAuth2 Spring 身份验证有效,但方式不正确

使用 oauth2 进行静默身份验证(提示 = 无)

使用 JHipster、Spring Security 和 oauth2 控制身份验证重定向

如何在 Spring Boot 中使用预定义的令牌绕过 Oauth2 身份验证?

Spring Boot 2 + OAuth2:配置令牌的身份验证代码交换

Spring boot、Security、OAuth2:是否可以使用自定义 AuthorizationCodeResourceDetails?身份验证服务器需要重定向 url 中的特定参数

Javascript WebApp 的 Spring Security Oauth2 身份验证

使用 spring-boot-starter-oauth2-client 检索 OAuth2 3-legged 身份验证的访问令牌

通过 Spring Security OAuth2 客户端成功匿名身份验证后重定向到特定 URL

使用 totp 进行身份验证和重定向(speakeasy)