简体   繁体   English

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

[英]Unable to properly redirect after OAuth2 authentication using Spring Boot

I'm trying to build a basic Spring Boot app that will allow me delegate the work of authenticating users to an external OAuth2 provider such as Facebook. 我正在尝试构建一个基本的Spring Boot应用程序,该应用程序将允许我将对用户进行身份验证的工作委派给外部OAuth2提供程序,例如Facebook。

I've got two main issues: 我有两个主要问题:

  1. Once the authentication process is complete, and I get: 身份验证过程完成后,我得到:

GET request for " https://graph.facebook.com/me " resulted in 200 (OK) GET请求“ https://graph.facebook.com/me ”,结果为200(确定)

I also get the following: 我也得到以下信息:

Reading [interface java.util.Map] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@2a7ce52b] Delegating to org.springframework.security.web.authentication.session.ChangeSessionIdAuthenticationStrategy@4f061f45 SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession. 使用[org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@2a7ce52b]将[interface java.util.Map]读取为“ application / json”,委托给org.springframework.security.web.authentication.session.ChangeSessionIdAuthenticationStrategy@4f061f45为空或内容为匿名-上下文将不会存储在HttpSession中。

It is as if something is wrong with parsing and storing the returned credentials. 好像解析和存储返回的凭据有问题。

  1. Sometimes I get a 401 error: 有时我会收到401错误:

Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Could not obtain access token 身份验证请求失败:org.springframework.security.authentication.BadCredentialsException:无法获取访问令牌

It is a some sort of hit and miss, and I could not trace down the problem. 这是一种偶然,我无法找到问题所在。 It also happened when using Google OAuth2 instead. 改为使用Google OAuth2时也会发生。

I Basically used the @EnableOAuth2Sso annotation, and configured the credentials using the application.yml file: 我基本上使用@ 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

Any help is much appreciated :) 任何帮助深表感谢 :)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Spring Boot在oauth2中进行用户身份验证 - User authentication in oauth2 with Spring Boot Spring开机、zuul、oauth2认证问题 - Spring boot, zuul, oauth2 authentication problem Spring引导oauth2管理httpbasic认证 - Spring boot oauth2 management httpbasic authentication 在 Spring 引导应用程序上启用 Spring JWT 身份验证和 OAuth2 身份验证 - Enable Spring JWT Authentication and OAuth2 Authentication on Spring Boot Application 使用Azure Active Directory作为Spring-boot REST服务的OAUTH2身份验证服务 - Using Azure Active Directory as an OAUTH2 Authentication service for a Spring-boot REST service Spring Boot Security OAuth2身份验证服务器和业务服务器的拆分 - Spring Boot Security OAuth2 Authentication server and business server splitting Spring Boot OAuth2具有基本身份验证和自定义UserDetailsS​​ervice - Spring Boot OAuth2 with basic authentication and custom UserDetailsService Spring引导基本身份验证和OAuth2在同一个项目中? - Spring boot Basic Authentication and OAuth2 in same project? 如何使用 Spring Boot feign 客户端进行 Oauth2 身份验证? - How to use Spring Boot feign client for Oauth2 authentication? 如何使用Spring Boot将OAuth2身份验证与前端绑定 - How bind angular front with oauth2 authentication with spring boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM