简体   繁体   English

OAuth2 Spring boot 缺少必需的“用户名”

[英]OAuth2 Spring boot Missing required "user name

I'm trying to use Spring Boot OAuth to make authorize at my app through Zoom ( https://marketplace.zoom.us/docs/guides/auth/oauth )我正在尝试使用 Spring Boot OAuth 通过 Zoom 在我的应用程序上进行授权( https://marketplace.zoom.us/docs/guides/auth

I'm trying to open page ( /zoom endpoint) my app redirects me to Zoom.我正在尝试打开页面( /zoom端点),我的应用程序将我重定向到 Zoom。 Here I'm entering into zoom account and Spring redirects me to the error page:在这里,我进入缩放帐户,Spring 将我重定向到错误页面:

[missing_user_name_attribute] Missing required "user name" attribute name in UserInfoEndpoint for Client Registration: zoom

No idea how to deal with it.不知道如何处理它。 Here's my code这是我的代码

Config配置

@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();
    }
}

At Zoom Application I've configured在 Zoom 应用程序中,我已配置

Redirect URL for OAuth: http://{my_host_name}/login/oauth2/code/zoom为 OAuth 重定向 URL: http://{my_host_name}/login/oauth2/code/zoom

Whitelist Urls: http://{my_host_name}/zoom白名单网址: http://{my_host_name}/zoom

Also my app has endpoint at /zoom我的应用程序在/zoom也有端点

You've to add userNameAttributeName at ClientRegistration and set to the correct username attribute, it could be "sub" for openId, but also something different as "email", "id" check the https://api.zoom.us/v2/user response to find which attribute match.您必须在 ClientRegistration 添加 userNameAttributeName 并设置为正确的用户名属性,它可以是 openId 的“sub”,但也可以是“email”、“id”检查https://api.zoom.us/v2 /user响应以查找匹配的属性。

Regards问候

For me exception occurs when I tried get into authenticated endpoints (in my java app) using spotify Oauth2.0 with Spring Boot 2.5.4.对我来说,当我尝试使用Spotify Oauth2.0 和 Spring Boot 2.5.4 进入经过身份验证的端点(在我的 java 应用程序中)时,会发生异常。 I had missing property:我缺少财产:

spring.security.oauth2.client.provider.spotify.userNameAttribute=email

which is described in spring Oauth2 documentation这在spring Oauth2 文档中有所描述

Similar exception occurs for missing property:缺少属性也会发生类似的异常:

spring.security.oauth2.client.provider.spotify.user-info-uri=https://api.spotify.com/v1/me then exception is thrown: [missing_user_info_uri] Missing required UserInfo Uri in UserInfoEndpoint for Client Registration: spotify spring.security.oauth2.client.provider.spotify.user-info-uri=https://api.spotify.com/v1/me然后抛出异常: [missing_user_info_uri] Missing required UserInfo Uri in UserInfoEndpoint for Client Registration: spotify

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM