java - OAuth2 Spring boot缺少必需的“用户名
问题描述
我正在尝试使用 Spring Boot OAuth 通过 Zoom ( https://marketplace.zoom.us/docs/guides/auth/oauth )在我的应用程序中进行授权
我正在尝试打开页面(/zoom
端点),我的应用程序将我重定向到 Zoom。在这里,我进入缩放帐户,Spring 将我重定向到错误页面:
[missing_user_name_attribute] Missing required "user name" attribute name in UserInfoEndpoint for Client Registration: zoom
不知道如何处理它。这是我的代码
配置
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/", "/login**", "/error**").permitAll()
.anyRequest().authenticated()
.and().logout().logoutUrl("/logout").logoutSuccessUrl("/")
.and().oauth2Login();
}
@Bean
public ClientRegistrationRepository clientRegistrationRepository() {
List<ClientRegistration> registrations = new ArrayList<>();
registrations.add(zoomClientRegistration());
return new InMemoryClientRegistrationRepository(registrations);
}
private ClientRegistration zoomClientRegistration() {
return ClientRegistration.withRegistrationId("zoom")
.clientId(/**myClientId**/)
.clientSecret(/**{myClientSecret}**/)
.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC)
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
.redirectUriTemplate("{baseUrl}/login/oauth2/code/{registrationId}")
.authorizationUri("https://zoom.us/oauth/authorize")
.tokenUri("https://zoom.us/oauth/token")
.userInfoUri("https://api.zoom.us/v2/user")
.clientName("Zoom").build();
}
}
在 Zoom 应用程序中,我已配置
OAuth 的重定向 URL:http://{my_host_name}/login/oauth2/code/zoom
白名单网址:http://{my_host_name}/zoom
我的应用程序也有端点/zoom
解决方案
您必须在 ClientRegistration 添加 userNameAttributeName 并设置为正确的用户名属性,它可以是 openId 的“子”,但也可以是“电子邮件”、“id”等不同的东西,请检查https://api.zoom.us/v2 /user响应以查找匹配的属性。
问候
推荐阅读
- sql - 随时间改变支付频率的客户百分比
- d3.js - D3.js折线图连续但想要不连续
- java - 在 Spring Boot 2.0.3 中设置 SSL 安全性
- python - 现有模型中未找到模型错误
- javascript - 唯一的 DataTable 列标题工具提示
- php - JSON 日期转 PHP 日期
- c# - 机器人框架 DialogContext.Continue 不起作用
- angularjs - Angularjs 控制器已定义但从未使用过
- c++ - 是否有任何 2 补码平台/编译器,其中带符号的移位不做通常的事情?
- python - Selenium 被检测到,并且在第一次打开Bloomberg URL 后立即弹出验证码