Аутентификация клиента не удалась: client_idJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Аутентификация клиента не удалась: client_id

Сообщение Anonymous »

Я следую книге
Spring Security в действии, второе издание, глава 14.2. Выполнение типа предоставления кода авторизации.
Я считаю, что четко следовал инструкциям, но я продолжайте получать исключения
org.springframework.security.oauth2.core.OAuth2AuthenticationException: Client authentication failed: client_id

Это мой поток. Получите код из первого URL-адреса, после чего я использую код и передаю его в запросе на завивку
http://localhost:8080/oauth2/authorize? ... ethod=S256

curl -X POST 'http://localhost:8080/oauth2/token?clie ... lkymMyXlJo' --header 'Authorization: Basic YmlsbDpwYXNzd29yZA=='

Вот моя конфигурация
@Configuration
public class SecurityConfig {

@Bean
@Order(1)
public SecurityFilterChain asFilterChain(HttpSecurity http)
throws Exception {

OAuth2AuthorizationServerConfiguration
.applyDefaultSecurity(http);

http.getConfigurer(OAuth2AuthorizationServerConfigurer.class)
.oidc(Customizer.withDefaults());

http.exceptionHandling((e) ->
e.authenticationEntryPoint(
new LoginUrlAuthenticationEntryPoint("/login"))
);

return http.build();
}

@Bean
@Order(2)
public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http)
throws Exception {

http.formLogin(Customizer.withDefaults());

http.authorizeHttpRequests(
c -> c.anyRequest().authenticated()
);

return http.build();
}

@Bean
public UserDetailsService userDetailsService() {
UserDetails userDetails = User.withUsername("bill")
.password("password")
.roles("USER")
.build();

return new InMemoryUserDetailsManager(userDetails);
}

@Bean
public PasswordEncoder passwordEncoder() {
return NoOpPasswordEncoder.getInstance();

}

/*
* code_challenge=QYPAZ5NU8yvtlQ…—If using the authorization code enhanced with PKCE
* (discussed in chapter 13), you must provide the code challenge with the authorization request.
* When requesting the token, the client must send the verifier pair to prove they are the same application
* that initially sent this request. The PKCE flow is enabled by default.
* */

@Bean
public RegisteredClientRepository registeredClientRepository() {
RegisteredClient registeredClient = RegisteredClient
.withId(UUID.randomUUID().toString())
.clientId("client")
.clientSecret("secret")
.clientAuthenticationMethod(
ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
.authorizationGrantType(
AuthorizationGrantType.AUTHORIZATION_CODE)
.redirectUri("https://www.manning.com/authorized")
.tokenSettings(
TokenSettings.builder()
.accessTokenFormat(OAuth2TokenFormat.REFERENCE)
.accessTokenTimeToLive(Duration.ofHours(24))
.build()
)
.scope(OidcScopes.OPENID)
.build();

return new InMemoryRegisteredClientRepository(registeredClient);
}

@Bean
public JWKSource jwkSource()
throws NoSuchAlgorithmException {

KeyPairGenerator keyPairGenerator =
KeyPairGenerator.getInstance("RSA");

keyPairGenerator.initialize(2048);
KeyPair keyPair = keyPairGenerator.generateKeyPair();

RSAPublicKey publicKey =
(RSAPublicKey) keyPair.getPublic();
RSAPrivateKey privateKey =
(RSAPrivateKey) keyPair.getPrivate();

RSAKey rsaKey = new RSAKey.Builder(publicKey)
.privateKey(privateKey)
.keyID(UUID.randomUUID().toString())
.build();
JWKSet jwkSet = new JWKSet(rsaKey);
return new ImmutableJWKSet(jwkSet);
}

@Bean
public AuthorizationServerSettings authorizationServerSettings() {

return AuthorizationServerSettings.builder()
.build();
}
}


Подробнее здесь: https://stackoverflow.com/questions/792 ... -client-id
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

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