forked from spring-projects/spring-authorization-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add how-to guide for dynamic client registration with custom metadata
Fixes spring-projectsgh-1044
- Loading branch information
Showing
11 changed files
with
588 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
docs/src/main/java/sample/registration/basic/ClientRegistrar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2020-2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package sample.registration.basic; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.List; | ||
public class ClientRegistrar { | ||
// @fold:on | ||
private final WebClient webClient; | ||
|
||
public ClientRegistrar(WebClient webClient) { | ||
this.webClient = webClient; | ||
} | ||
// @fold:off | ||
|
||
public record ClientRegistrationRequest( // <1> | ||
@JsonProperty("client_name") String clientName, | ||
@JsonProperty("grant_types") List<String> grantTypes, | ||
@JsonProperty("redirect_uris") List<String> redirectUris, | ||
String scope) { | ||
} | ||
|
||
public record ClientRegistrationResponse( // <2> | ||
@JsonProperty("registration_access_token") String registrationAccessToken, | ||
@JsonProperty("registration_client_uri") String registrationClientUri, | ||
@JsonProperty("client_name") String clientName, | ||
@JsonProperty("client_id") String clientId, | ||
@JsonProperty("client_secret") String clientSecret, | ||
@JsonProperty("grant_types") List<String> grantTypes, | ||
@JsonProperty("redirect_uris") List<String> redirectUris, | ||
String scope) { | ||
} | ||
|
||
public ClientRegistrationResponse registerClient(String initialAccessToken, ClientRegistrationRequest request) { // <3> | ||
return this.webClient | ||
.post() | ||
.uri("/connect/register") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer %s".formatted(initialAccessToken)) | ||
.body(Mono.just(request), ClientRegistrationRequest.class) | ||
.retrieve() | ||
.bodyToMono(ClientRegistrationResponse.class) | ||
.block(); | ||
} | ||
|
||
public ClientRegistrationResponse retrieveClient(String registrationAccessToken, String registrationClientUri) { // <4> | ||
return this.webClient | ||
.get() | ||
.uri(registrationClientUri) | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer %s".formatted(registrationAccessToken)) | ||
.retrieve() | ||
.bodyToMono(ClientRegistrationResponse.class) | ||
.block(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.