Skip to content

Commit fce99ea

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 39ed820 commit fce99ea

File tree

10 files changed

+1201
-2
lines changed

10 files changed

+1201
-2
lines changed

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

+14-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> {
@@ -99,6 +101,10 @@ public final class OAuth2AuthorizationServerConfigurer<B extends HttpSecurityBui
99101
NimbusJwkSetEndpointFilter.DEFAULT_JWK_SET_ENDPOINT_URI, HttpMethod.GET.name());
100102
private final RequestMatcher oidcProviderConfigurationEndpointMatcher = new AntPathRequestMatcher(
101103
OidcProviderConfigurationEndpointFilter.DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI, HttpMethod.GET.name());
104+
private final RequestMatcher oidcClientRegistrationEndpointMatcher = new AntPathRequestMatcher(
105+
OidcClientRegistrationEndpointFilter.DEFAULT_OIDC_CLIENT_REGISTRATION_ENDPOINT,
106+
HttpMethod.POST.name()
107+
);
102108

103109
/**
104110
* Sets the repository of registered clients.
@@ -145,7 +151,7 @@ public List<RequestMatcher> getEndpointMatchers() {
145151
// TODO Initialize matchers using URI's from ProviderSettings
146152
return Arrays.asList(this.authorizationEndpointMatcher, this.tokenEndpointMatcher,
147153
this.tokenRevocationEndpointMatcher, this.jwkSetEndpointMatcher,
148-
this.oidcProviderConfigurationEndpointMatcher);
154+
this.oidcProviderConfigurationEndpointMatcher, this.oidcClientRegistrationEndpointMatcher);
149155
}
150156

151157
@Override
@@ -211,6 +217,12 @@ public void configure(B builder) {
211217
builder.addFilterBefore(postProcess(oidcProviderConfigurationEndpointFilter), AbstractPreAuthenticatedProcessingFilter.class);
212218
}
213219

220+
RegisteredClientRepository registeredClientRepository = getRegisteredClientRepository(builder);
221+
222+
OidcClientRegistrationEndpointFilter oidcClientRegistrationEndpointFilter =
223+
new OidcClientRegistrationEndpointFilter(registeredClientRepository);
224+
builder.addFilterBefore(postProcess(oidcClientRegistrationEndpointFilter), AbstractPreAuthenticatedProcessingFilter.class);
225+
214226
JWKSource<SecurityContext> jwkSource = getJwkSource(builder);
215227
NimbusJwkSetEndpointFilter jwkSetEndpointFilter = new NimbusJwkSetEndpointFilter(
216228
jwkSource,
@@ -227,7 +239,7 @@ public void configure(B builder) {
227239

228240
OAuth2AuthorizationEndpointFilter authorizationEndpointFilter =
229241
new OAuth2AuthorizationEndpointFilter(
230-
getRegisteredClientRepository(builder),
242+
registeredClientRepository,
231243
getAuthorizationService(builder),
232244
providerSettings.authorizationEndpoint());
233245
builder.addFilterBefore(postProcess(authorizationEndpointFilter), AbstractPreAuthenticatedProcessingFilter.class);
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)