Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

I'm trying to open page ( /zoom endpoint) my app redirects me to Zoom. Here I'm entering into zoom account and Spring redirects me to the error page:

[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

Redirect URL for OAuth: http://{my_host_name}/login/oauth2/code/zoom

Whitelist Urls: http://{my_host_name}/zoom

Also my app has endpoint at /zoom

like image 429
Andrei Koch Avatar asked Nov 14 '25 13:11

Andrei Koch


2 Answers

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.

Regards

like image 165
DanyRic Avatar answered Nov 17 '25 08:11

DanyRic


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. I had missing property:

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

which is described in spring Oauth2 documentation

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

like image 41
Damian JK Avatar answered Nov 17 '25 08:11

Damian JK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!