Spring启动3.0不一致OAuth2

kb5ga3dv  于 2023-02-21  发布在  Spring
关注(0)|答案(1)|浏览(162)

我想为我的网站做一个Discord OAuth2登录。
我在GitHub https://github.com/fourscouts/blog/tree/master/oauth2-discord上找到了旧版Spring的以下代码,因为新的Spring版本,我不得不在配置中添加SecurityFilterChain。我现在的问题是,当我进入http://localhost:8080/login时,我可以访问Discord登录页面,但当我从Discord重定向时,我会看到错误消息,如图所示。Error after Discord redirect我还在控制台中收到以下消息:Response 400 BAD_REQUEST No event was found for the exception org.springframework.security.oauth2.core.OAuth2AuthenticationException我不知道接下来应该尝试什么。我把代码上传到github,这样你就可以看到它了:https://github.com/mrmrmystery/somewhatweb

xxls0lw8

xxls0lw81#

在Spring中,我使用www.example.com中的以下配置完成了这一任务application.properties

# OAuth2 Discord Registration
spring.security.oauth2.client.registration.discord.provider=discord
spring.security.oauth2.client.registration.discord.client-id=CLIENT_ID
spring.security.oauth2.client.registration.discord.client-secret=SECRET
spring.security.oauth2.client.registration.discord.client-authentication-method=post
spring.security.oauth2.client.registration.discord.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.discord.scope[0]=identify
spring.security.oauth2.client.registration.discord.redirect-uri=http://localhost:8080/login/oauth2/code/discord

# OAuth2 Sign-In-With-Discord
spring.security.oauth2.client.provider.discord.authorization-uri=https://discordapp.com/api/oauth2/authorize
spring.security.oauth2.client.provider.discord.token-uri=https://discordapp.com/api/oauth2/token
spring.security.oauth2.client.provider.discord.user-info-uri=https://discordapp.com/api/users/@me
spring.security.oauth2.client.provider.discord.user-name-attribute=username

相关问题