Skip to content

Commit f520dc8

Browse files
committed
Implement OpenID client registration endpoint
See: https://openid.net/specs/openid-connect-registration-1_0.html#ClientRegistration Fixes gh-57
1 parent a90d98a commit f520dc8

File tree

11 files changed

+1437
-2
lines changed

11 files changed

+1437
-2
lines changed

oauth2-authorization-server/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/server/authorization/OAuth2AuthorizationServerConfigurer.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2TokenRevocationAuthenticationProvider;
4747
import org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository;
4848
import org.springframework.security.oauth2.server.authorization.config.ProviderSettings;
49+
import org.springframework.security.oauth2.server.authorization.oidc.web.OidcClientRegistrationEndpointFilter;
4950
import org.springframework.security.oauth2.server.authorization.oidc.web.OidcProviderConfigurationEndpointFilter;
5051
import org.springframework.security.oauth2.server.authorization.web.NimbusJwkSetEndpointFilter;
5152
import org.springframework.security.oauth2.server.authorization.web.OAuth2AuthorizationEndpointFilter;
@@ -80,6 +81,7 @@
8081
* @see NimbusJwkSetEndpointFilter
8182
* @see OidcProviderConfigurationEndpointFilter
8283
* @see OAuth2ClientAuthenticationFilter
84+
* @see OidcClientRegistrationEndpointFilter
8385
*/
8486
public final class OAuth2AuthorizationServerConfigurer<B extends HttpSecurityBuilder<B>>
8587
extends AbstractHttpConfigurer<OAuth2AuthorizationServerConfigurer<B>, B> {
@@ -89,12 +91,14 @@ public final class OAuth2AuthorizationServerConfigurer<B extends HttpSecurityBui
8991
private RequestMatcher tokenRevocationEndpointMatcher;
9092
private RequestMatcher jwkSetEndpointMatcher;
9193
private RequestMatcher oidcProviderConfigurationEndpointMatcher;
94+
private RequestMatcher oidcClientRegistrationEndpointMatcher;
9295
private final RequestMatcher endpointsMatcher = (request) ->
9396
this.authorizationEndpointMatcher.matches(request) ||
9497
this.tokenEndpointMatcher.matches(request) ||
9598
this.tokenRevocationEndpointMatcher.matches(request) ||
9699
this.jwkSetEndpointMatcher.matches(request) ||
97-
this.oidcProviderConfigurationEndpointMatcher.matches(request);
100+
this.oidcProviderConfigurationEndpointMatcher.matches(request) ||
101+
this.oidcClientRegistrationEndpointMatcher.matches(request);
98102

99103
/**
100104
* Sets the repository of registered clients.
@@ -217,6 +221,12 @@ public void configure(B builder) {
217221
builder.addFilterBefore(postProcess(oidcProviderConfigurationEndpointFilter), AbstractPreAuthenticatedProcessingFilter.class);
218222
}
219223

224+
RegisteredClientRepository registeredClientRepository = getRegisteredClientRepository(builder);
225+
226+
OidcClientRegistrationEndpointFilter oidcClientRegistrationEndpointFilter =
227+
new OidcClientRegistrationEndpointFilter(registeredClientRepository);
228+
builder.addFilterBefore(postProcess(oidcClientRegistrationEndpointFilter), AbstractPreAuthenticatedProcessingFilter.class);
229+
220230
JWKSource<SecurityContext> jwkSource = getJwkSource(builder);
221231
NimbusJwkSetEndpointFilter jwkSetEndpointFilter = new NimbusJwkSetEndpointFilter(
222232
jwkSource,
@@ -235,7 +245,7 @@ public void configure(B builder) {
235245

236246
OAuth2AuthorizationEndpointFilter authorizationEndpointFilter =
237247
new OAuth2AuthorizationEndpointFilter(
238-
getRegisteredClientRepository(builder),
248+
registeredClientRepository,
239249
getAuthorizationService(builder),
240250
providerSettings.authorizationEndpoint());
241251
builder.addFilterBefore(postProcess(authorizationEndpointFilter), AbstractPreAuthenticatedProcessingFilter.class);
@@ -269,6 +279,9 @@ private void initEndpointMatchers(ProviderSettings providerSettings) {
269279
providerSettings.jwkSetEndpoint(), HttpMethod.GET.name());
270280
this.oidcProviderConfigurationEndpointMatcher = new AntPathRequestMatcher(
271281
OidcProviderConfigurationEndpointFilter.DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI, HttpMethod.GET.name());
282+
this.oidcClientRegistrationEndpointMatcher = new AntPathRequestMatcher(
283+
OidcClientRegistrationEndpointFilter.DEFAULT_OIDC_CLIENT_REGISTRATION_ENDPOINT,
284+
HttpMethod.POST.name());
272285
}
273286

274287
private static void validateProviderSettings(ProviderSettings providerSettings) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2020-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.security.oauth2.core.oidc;
17+
18+
import org.springframework.security.oauth2.core.ClaimAccessor;
19+
20+
import java.util.List;
21+
22+
/**
23+
* @author Ovidiu Popa
24+
* @since 0.0.4
25+
*/
26+
public interface OidcClientMetadataClaimAccessor extends ClaimAccessor {
27+
28+
default List<String> getRedirectUris(){
29+
return getClaimAsStringList(OidcClientMetadataClaimNames.REDIRECT_URIS);
30+
}
31+
32+
default List<String> getResponseTypes(){
33+
return getClaimAsStringList(OidcClientMetadataClaimNames.RESPONSE_TYPES);
34+
}
35+
36+
default List<String> getGrantTypes(){
37+
return getClaimAsStringList(OidcClientMetadataClaimNames.GRANT_TYPES);
38+
}
39+
40+
default String getClientName(){
41+
return getClaimAsString(OidcClientMetadataClaimNames.CLIENT_NAME);
42+
}
43+
44+
default String getScope(){
45+
return getClaimAsString(OidcClientMetadataClaimNames.SCOPE);
46+
}
47+
48+
default String getTokenEndpointAuthenticationMethod() {
49+
return getClaimAsString(OidcClientMetadataClaimNames.TOKEN_ENDPOINT_AUTH_METHOD);
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2020-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.security.oauth2.core.oidc;
17+
18+
/**
19+
* @author Ovidiu Popa
20+
* @since 0.0.4
21+
*/
22+
public interface OidcClientMetadataClaimNames {
23+
24+
//request
25+
String REDIRECT_URIS = "redirect_uris";
26+
27+
String RESPONSE_TYPES = "response_types";
28+
29+
String GRANT_TYPES = "grant_types";
30+
31+
String CLIENT_NAME = "client_name";
32+
33+
String SCOPE = "scope";
34+
35+
String TOKEN_ENDPOINT_AUTH_METHOD = "token_endpoint_auth_method";
36+
37+
//response
38+
String CLIENT_ID = "client_id";
39+
40+
String CLIENT_SECRET = "client_secret";
41+
42+
String CLIENT_ID_ISSUED_AT = "client_id_issued_at";
43+
44+
String CLIENT_SECRET_EXPIRES_AT = "client_secret_expires_at";
45+
}

0 commit comments

Comments
 (0)