I have integrated IdentityServer4 in spring Boot project.
I want to know how to add code_verifier to call "/connect/token" of IdentityServer?
I receive code in the redirecturl as follows,
First Redirect: https://idsrv4test.com/connect/authorize?response_type=code&client_id=client_id&scope=id_number%20openid%20email%20roles%20profile&state=SDGHMnvw0UJZyylFr752jBAWS2ahGIwBiavF0YsRtoI%3D&redirect_uri=https://127.0.0.1:9443/signin-oidc&code_challenge_method=S256&nonce=_8fJthx0jlqX_2tJKSkwvs_r4RfxIjU4NokGGpSZIF0&code_challenge=<this_encrypted_text>
I construct a resttemplate in my project to call "/connect/token" as per
POST /connect/token CONTENT-TYPE application/x-www-form-urlencoded
client_id=client_id&
client_secret=secret&
grant_type=authorization_code&
code=returned_code&
redirect_uri=https://127.0.0.1:9443/signin-oidc
code_verifier=<this_encrypted_text>
In the requestBody I set code_verifier=<this_encrypted_text> But I get "invalid_grant". It means as per the spec docs https://datatracker.ietf.org/doc/html/rfc7636#page-10 code_verifier == code_challenge. is flase
For your reference SecurityConfig class is as such
@EnableWebSecurity
public class ConfigSecurity extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
PortMapperImpl portMapper = new PortMapperImpl();
portMapper.setPortMappings(Collections.singletonMap("9443","9443"));
PortResolverImpl portResolver = new PortResolverImpl();
portResolver.setPortMapper(portMapper);
LoginUrlAuthenticationEntryPoint entryPoint = new LoginUrlAuthenticationEntryPoint(
"/login");
entryPoint.setPortMapper(portMapper);
entryPoint.setPortResolver(portResolver);
http.exceptionHandling()
.authenticationEntryPoint(entryPoint)
.and()
.authorizeRequests()
.antMatchers("/login","/css/*", "/images/*","/signin-oidc","/test")
.permitAll()
.anyRequest()
.authenticated()
.and()
.oauth2Login()
.loginPage("/login")
.and()
.logout().logoutUrl("/logout")
.logoutSuccessHandler(oidcLogoutSuccessHandler());
}
@Autowired
private ClientRegistrationRepository clientRegistrationRepository;
private LogoutSuccessHandler oidcLogoutSuccessHandler() {
OidcClientInitiatedLogoutSuccessHandler oidcLogoutSuccessHandler =
new OidcClientInitiatedLogoutSuccessHandler(
this.clientRegistrationRepository);
oidcLogoutSuccessHandler.setPostLogoutRedirectUri(
URI.create("http://localhost:9443"));
return oidcLogoutSuccessHandler;
}
}
And my application.yml is as follows,
server:
port: 9443
ssl:
key-store: classpath:asif1.jks
key-store-password: xxxxx
key-store-type: pkcs12
key-store-alias: server
spring:
security:
oauth2:
client:
registration:
idsrv4:
client-name: client_name_test
client-id: client_id_test
client-secret: Marines
client-authentication-method: none
authorization-grant-type: authorization_code
redirect-uri: "https://127.0.0.1:9443/signin-oidc"
scope: "id_number,openid,email,roles,profile"
provider:
idsrv4:
authorization-uri: https://idsrv4test.com/connect/authorize
issuer-uri: https://idsrv4test.com
token-uri: https://idsrv4test.com/connect/token
user-info-uri: https://idsrv4test.com/connect/userinfo
user-name-attribute: sub
jwk-set-uri: https://idsrv4test.com/.well-known/openid-configuration/jwks
Any help ?