and I try to apply authorization_code flow. I have managed to call the server and got the code which will be used to fetch the token but when the endpoint /oauth2/audience/v1/token is called, it miss the client_id in the body.
I have tried to add it in a custom class(customAuthorizationCodeTokenResponseClient) but it is never called.
Above, my main config. Do you have any ideas? Thanks by advance:
@Configuration @EnableWebSecurity
public class SecurityConfig {
private final ClientRegistrationRepository clientRegistrationRepository;
private final Environment env;
public SecurityConfig(ClientRegistrationRepository clientRegistrationRepository, Environment env) {
this.clientRegistrationRepository = clientRegistrationRepository;
this.env = env;
}
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeRequests(authorizeRequests -> authorizeRequests.anyRequest().fullyAuthenticated())
.oauth2Login(oauth2Login -> {
oauth2Login.authorizationEndpoint(authorizationEndpoint ->
authorizationEndpoint.authorizationRequestResolver(customAuthorizationRequestResolver(clientRegistrationRepository))
).tokenEndpoint(tokenEndpoint ->
tokenEndpoint.accessTokenResponseClient(customAuthorizationCodeTokenResponseClient())
);
})
.csrf(csrf -> csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())); // Example CSRF token repository
return http.build();
}
@Bean
public OAuth2AuthorizationRequestResolver customAuthorizationRequestResolver(ClientRegistrationRepository clientRegistrationRepository) {
return new CustomAuthorizationRequestResolver(clientRegistrationRepository, "/oauth2/authorization");
}
@Bean
public CustomAuthorizationCodeTokenResponseClient customAuthorizationCodeTokenResponseClient() {
return new CustomAuthorizationCodeTokenResponseClient();
}
In your Spring Boot application, you’re encountering an issue where the client_id is missing when calling the /oauth2/audience/v1/token endpoint to exchange an authorization code for an access token. This problem might be due to the way your custom OAuth2AccessTokenResponseClient is implemented or configured. Ensure that your custom client correctly includes the client_id in the request body when making the call to the token endpoint. Verify that your application’s application.properties or application.yml file is properly configured with Okta’s details, including the client-id, client-secret, and token endpoint URI. Additionally, check your Okta configuration to make sure the server is correctly set up to handle the token request. Adding detailed logging to capture request and response details can also help diagnose the issue. If these steps do not resolve the issue, consider updating your dependencies or consulting Okta’s support for further assistance.
Hi melvas66,
I assume that in my application.yml, I got this values:
okta:
oauth2:
client-id: ${okta_client_id}
client-secret: ${okta_client_secret}
issuer: https://${namespace}/oauth2/${okta_audience_id}
redirect-uri: /authorization-code/callback
scopes:
- offline_access
- openid
I have followed the request exchange in my browser console and did not manage to see the token exchange query(cf screenshot), but I can see it in my java log.
I have also tried to put some interceptor to catch every queries send from my app but without success.
Do you have any idea how to catch the RestTemplate Post which is used to ask the token?
regards
May I know if you are seeing any other errors in the browser Console? Also, please confirm what value you are using for the okta_audience_id in the issuer. Is it the Authorization server ID or anything else.