Background
I am modifying my existing Spring-secured API (not Spring-Boot) to work with bearer tokens that were issued to the client by Okta. Since every example I could find uses Spring-Boot, I tried getting it to work with the okta-spring-boot-starter artifact, but I’m stuck.
I have setup an Okta developer account and I am able to get a valid token by POST
ing to https://<my dev subdomain>.oktapreview.com/oauth2/default/v1/token
I can validate the token by POST
ing to https://<my dev subdomain>.oktapreview.com/oauth2/default/v1/introspect
:
{
"active": true,
"scope": "customScope",
"exp": 1541536634,
"iat": 1541533034,
"sub": "<my client id>",
"aud": "api://default",
"iss": "https://<my dev subdomain>.oktapreview.com/oauth2/default",
"jti": "AT.OrvTA0dVK7eoN8upzz9U50C4kMsXMCXb5FZcQB5i4lI",
"token_type": "Bearer",
"client_id": "<my client id>"
}
I then use that token as a Bearer token in the Authorization header in a call to my protected resource.
My Code
@Configuration
@EnableResourceServer
public class OauthResourceConfig extends ResourceServerConfigurerAdapter {
@Value("${okta.oauth2.clientId}")
String resourceId;
@Value("${okta.oauth2.baseUrl}/oauth2/v1/keys")
String jwksUrl;
@Override
public void configure(HttpSecurity http) throws Exception {
http
.httpBasic().disable()
.requestMatchers().antMatchers("/fortellis/**").and()
.authorizeRequests().antMatchers("/").permitAll().and()
.csrf().disable();
}
@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources
.tokenServices(tokenServices())
.resourceId(resourceId);
}
@Primary
@Bean
public DefaultTokenServices tokenServices() throws Exception {
DefaultTokenServices tokenServices = new DefaultTokenServices();
tokenServices.setTokenStore(tokenStore());
return tokenServices;
}
@Bean
public TokenStore tokenStore() {
return new JwkTokenStore(jwksUrl); //
}
}
Here are the properties:
// Okta Oauth2 Properties
setProperty("okta.oauth2.baseUrl", "https://<my dev subdomain>.oktapreview.com");
setProperty("okta.oauth2.issuer", "https://<my dev subdomain>.oktapreview.com/oauth2/default/v1");
setProperty("okta.oauth2.clientId", "<my client id>");
setProperty("okta.oauth2.audience", "api://default");
setProperty("okta.oauth2.scopeClaim", "customScope");
setProperty("okta.oauth2.rolesClaim", "groups");
The Problem
When I issue a request to my secured URL I get this error:
{
"error": "invalid_token",
"error_description": "Invalid JOSE Header kid (iAzphTQ0ksc7h4fwgVAW71-f4uRXZPOs0MEElBG6hhc)"
}
Any help getting me going down the right path would be much appreciated. I’m three days into this already.