OAuth2 Spring boot Отсутствует необходимое "имя пользователя" - PullRequest
0 голосов
/ 09 мая 2020

Я пытаюсь использовать 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

Не знаю, как с этим бороться. Вот мой код

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

В приложении Zoom я настроил

URL-адрес перенаправления для OAuth: http://{my_host_name}/login/oauth2/code/zoom

URL-адреса в белом списке: http://{my_host_name}/zoom

Также мое приложение имеет конечную точку /zoom

1 Ответ

0 голосов
/ 27 мая 2020

Вы должны добавить userNameAttributeName в ClientRegistration и установить правильный атрибут имени пользователя, это может быть «sub» для openId, но также может быть что-то другое, например «email», «id», проверьте https://api.zoom.us/v2/user ответ, чтобы найти подходящий атрибут.

С уважением

...