-
Notifications
You must be signed in to change notification settings - Fork 6.1k
ClientRegistrations.fromIssuerLocation for Oauth2 AuthorizationServer requires jwks url even though jwks is not required in the metadata spec #7512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I remember working on Both JwtDecodersTests.java and ClientRegistrationsTests.java have a I would love to make a pull request should we decide to refactor/add null-check 🙂 |
Thanks for the report @knutejoh. Adding a null-check makes sense. @rhamedy sounds great, it's yours! Since OIDC Discovery does require Let's also please address what is probably a similar issue in |
@jzheaux Thank you for the info. A question before I get started What's your suggestion when it comes to checking whether it's Assuming that validation could go in
If we cannot rely on response We might have to |
@rhamedy Good questions.
No, I don't think we should sniff the response to try and detect the type of request. Instead, it'd probably be best to validate at the time the request is made since we know the type of endpoint at that time. Something like this might work: Change: private static URI oidc(URI issuer) { to private static Supplier<ClientRegistration.Builder> oidc(URI issuer) { It would return a There are probably other ways to do it, too, but that would hopefully place the majority of the custom code for a given endpoint type in one spot. |
@jzheaux
I am struggling to understand how your proposed solution is going to work? Could you please give a little bit more insights into your vision for switch to The solution I have in mind is as follow: AssumptionThe OpenID Connect Discovery endpoint will always have Code changesUpdate the
with
Add a new method that conditionally validates
and finally, update the
with
With the above changes, in the tests, we just have to remove the
ConcernThe Not sure if this is an ideal solution and whether it covers some edges cases or not. Regardless, curious to hear more about Sorry for the long reply 😐 |
Hi, @jzheaux created a draft pull request since we are still in discussions around an ideal solution. The draft pull request showcases the changes for the fix I had in mind, however, I would be happy to re-purpose the pull request once I get a little more clarity in the |
I believe this: Map<String, Object> configuration = getConfiguration(issuer, oidc(uri), oidcRfc8414(uri), oauth(uri)); would change to: ClientRegistration.Builder clientRegistration = getConfiguration(issuer, oidc(uri), oidcRfc8414(uri), oauth(uri)); The idea here is that we already know it is an OIDC call when we are inside the I think the private static Supplier<ClientRegistration.Builder> oidc(URI issuer) {
URI uri = UriComponentsBuilder.fromUri(issuer)
.replacePath(issuer.getPath() + OIDC_METADATA_PATH).build(Collections.emptyMap());
return () -> {
RequestEntity<Void> request = RequestEntity.get(uri).build();
Map<String, Object> response = rest.exchange(request, typeReference).getBody();
OIDCProviderMetadata metadata = parse(response, OIDCProviderMetadata::parse);
return withProviderConfiguration(metadata, issuer.toASCIIString())
.jwkSetUri(metadata.getJWKSetURI().toASCIIString())
.userInfoUri(metadata.getUserInfoEndpointURI().toASCIIString());
};
} |
Thanks, @jzheaux, I have pushed my changes up. Looking forward to hearing your thoughts 👍 |
OpenID Connect Discovery 1.0 expects the OpenId Provider Metadata response is expected to return a valid jwks_uri, however, this field is optional in the Authorization Server Metadata response as per RFC 8414 specification. Fixes spring-projectsgh-7512
Summary
When using ClientRegistrations.fromIssuerLocation for setting up Oauth2 AuthorizationServer the code requires jwks url to be a part of the returned metadata in the .well-known/oauth-authorization-server even though this is not required in the metadata spec (see https://tools.ietf.org/html/rfc8414)
Actual Behavior
Nullpointer thrown from line 222 (.jwkSetUri(metadata.getJWKSetURI().toASCIIString())) in org.springframework.security.oauth2.client.registration.ClientRegistrations
Expected Behavior
No nullpointer and the client configured correctly with the provided metadata
Configuration
Here is an example metadata file that should work
{
"issuer": "https://issuerurl:port",
"authorization_endpoint": "https://issuerurl:port/oauth/authorize",
"token_endpoint": "https://issuerurl:port/oauth/token",
"scopes_supported": [
"user:check-access",
"user:full",
"user:info",
"user:list-projects",
"user:list-scoped-projects"
],
"response_types_supported": [
"code",
"token"
],
"grant_types_supported": [
"authorization_code",
"implicit"
],
"code_challenge_methods_supported": [
"plain",
"S256"
]
}
Version
Spring Securiy Oauth2 Client 5.2.0.RELEASE
Sample
The text was updated successfully, but these errors were encountered: