Сложность интеграции API LinkedIn с безопасностью Spring для Oauth2JAVA

Программисты JAVA общаются здесь
Anonymous
Сложность интеграции API LinkedIn с безопасностью Spring для Oauth2

Сообщение Anonymous »

Я пытаюсь настроить Spring Security для входа в систему с помощью oauth2 для Facebook, Google и Linkedin. Facebook, кажется, работает нормально, как и Google. Но LinkedIn доставляет мне неприятности. Я получаю эту ошибку:

Код: Выделить всё

[missing_signature_verifier] Failed to find a Signature Verifier for Client Registration: 'linkedin'. Check to ensure you have configured the JwkSet URI.
Мне нужна помощь, чтобы решить эту проблему для успешной аутентификации Linkedin. У меня есть разрешение в приложении Linkedin для профиля, openid и электронной почты.
Я просмотрел другие ответы на stackoverflow, но ни одно из решений не помогло. После того, как я ответил на как можно больше вопросов о переполнении стека, вот код моего приложения на данный момент:
application.yml

Код: Выделить всё

server:
port: 8081
spring:
security:
oauth2:
client:
registration:
linkedin:
clientId: ?
clientSecret: ?
scope: profile, email, openid
authorizationGrantType: authorization_code
redirect-uri: "https://0a47-2405-201-a805-7211-4d70-a5b5-611c-fa27.ngrok-free.app/login/oauth2/code/linkedin"
client-name: LinkedIn
clientAuthenticationMethod: client_secret_post
provider:
linkedin:
tokenUri: https://www.linkedin.com/oauth/v2/accessToken
authorizationUri: https://www.linkedin.com/oauth/v2/authorization
userInfoUri: https://api.linkedin.com/v2/userinfo
userNameAttribute: id

logging:
level:
org.springframework.security: TRACE
WebSecurityConfig.java

Код: Выделить всё

@Configuration
@EnableWebSecurity
public class WebSecurityConfig {

@Autowired
private ClientRegistrationRepository clientRegistrationRepository;

@Bean
public  SecurityFilterChain defaultSecurityFilterChain(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.authorizeHttpRequests((authorize) -> authorize
.requestMatchers("/login", "/resources/**", "/logout")
.permitAll()
.anyRequest().authenticated()
)
.oauth2Login(oauthLoginConfig -> oauthLoginConfig
.authorizationEndpoint((authorizationEndpointConfig ->
authorizationEndpointConfig.authorizationRequestResolver(
requestResolver(this.clientRegistrationRepository)
))
)
.tokenEndpoint(tokenEndpointConfig -> tokenEndpointConfig
.accessTokenResponseClient(linkedinTokenResponseClient())
)
);
return httpSecurity.build();
}

private static OAuth2AccessTokenResponseClient linkedinTokenResponseClient() {
var defaultMapConverter = new DefaultMapOAuth2AccessTokenResponseConverter();
Converter linkedinMapConverter = tokenResponse -> {
var withTokenType = new HashMap(tokenResponse);
withTokenType.put(OAuth2ParameterNames.TOKEN_TYPE, OAuth2AccessToken.TokenType.BEARER.getValue());
return defaultMapConverter.convert(withTokenType);
};

var httpConverter = new OAuth2AccessTokenResponseHttpMessageConverter();
httpConverter.setAccessTokenResponseConverter(linkedinMapConverter);

var restOperations = new RestTemplate(List.of(new FormHttpMessageConverter(), httpConverter));
restOperations.setErrorHandler(new OAuth2ErrorResponseErrorHandler());
var client = new DefaultAuthorizationCodeTokenResponseClient();
client.setRestOperations(restOperations);
return client;
}

private static DefaultOAuth2AuthorizationRequestResolver requestResolver
(ClientRegistrationRepository clientRegistrationRepository) {
DefaultOAuth2AuthorizationRequestResolver requestResolver =
new DefaultOAuth2AuthorizationRequestResolver(clientRegistrationRepository,
"/oauth2/authorization");
requestResolver.setAuthorizationRequestCustomizer(c ->
c.attributes(stringObjectMap -> stringObjectMap.remove(OidcParameterNames.NONCE))
.parameters(params -> params.remove(OidcParameterNames.NONCE))
);

return requestResolver;
}
}
Благодарю вашу помощь. Заранее спасибо.

Подробнее здесь: https://stackoverflow.com/questions/783 ... for-oauth2

Вернуться в «JAVA»