gpt4 book ai didi

spring-boot - Spring boot + oauth2 + HttpClientErrorException 401 未经授权

转载 作者:行者123 更新时间:2023-12-01 05:57:45 24 4
gpt4 key购买 nike

我使用 spring boot 教程作为基础( https://spring.io/guides/tutorials/spring-boot-oauth2/ )
测试 Oauth2。

但是,我的身份验证服务器不是 facebook,而是 Netiq Access Manager (NAM)。
我设法被重定向到 NAM 登录页面,但登录后,我收到以下错误:

Whitelabel Error

日志显示:

o.s.b.a.s.o.r.UserInfoTokenServices      : Could not fetch user details: class org.springframework.web.client.HttpClientErrorException, 401 Unauthorized

这是项目:

Project structure

应用程序代码:
package com.example.springoauthdemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;

@SpringBootApplication
@EnableOAuth2Sso
public class SocialApplication {

public static void main(String[] args) {
SpringApplication.run(SocialApplication.class, args);
}
}

应用程序.yml
security:
oauth2:
client:
clientId: 55bb61f1-4384-4939-9cd0-fa7d76af9a0c
clientSecret: fdUjegFlCJjnD778RUSuS4SqMRey4IKVDOkadi4hjN6YbhC1xCInxoxobf-a-p-po8rt1wfZM2BPqJHpcZ-FGs
accessTokenUri: https://nam.example.com/nidp/oauth/nam/token
userAuthorizationUri: https://nam.example.com/nidp/oauth/nam/authz
tokenName: oauth_token
authenticationScheme: query
clientAuthenticationScheme: form
resource:
userInfoUri: https://localhost:8443/index.html
#userInfoUri: https://nam.example.com/nidp/oauth/nam/userinfo

server:
port: 8443
ssl:
enabled: true
key-alias: tomcat-localhost
key-password: changeit
key-store: classpath:keystore.jks
key-store-provider: SUN
key-store-type: JKS
key-store-password: changeit

据我所知,使用 this以 Oauth2 流程为例,步骤 1、2 和 3 似乎没问题,所以问题是尝试获取访问 token ?

有任何想法吗?

提前致谢!

最佳答案

当您通过身份验证并且拥有一个用户时,您可以根据 userInfoUri 对其进行验证,它返回 oauth 的 Principal 对象。

您正在针对 html 设置此值:

resource:
userInfoUri: https://localhost:8443/index.html

它应该是这样的:
resource:
userInfoUri: https://localhost:8443/userinfo

该服务响应必须返回如下内容:
@RequestMapping("/userinfo")
Principal getUser(Principal user) {
return user;
}

关于spring-boot - Spring boot + oauth2 + HttpClientErrorException 401 未经授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48207095/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com