mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-05-31 09:12:14 +00:00
Add registered OAuth2 authorized client Kotlin samples
Issue gh-8172
This commit is contained in:
parent
324d6795c9
commit
380a11566e
@ -10,7 +10,9 @@ A working example can be found in {gh-samples-url}/boot/oauth2webclient-webflux[
|
|||||||
|
|
||||||
After configuring Spring Security for <<webflux-oauth2-login,OAuth2 Login>> or as an <<webflux-oauth2-client,OAuth2 Client>>, an `OAuth2AuthorizedClient` can be resolved using the following:
|
After configuring Spring Security for <<webflux-oauth2-login,OAuth2 Login>> or as an <<webflux-oauth2-client,OAuth2 Client>>, an `OAuth2AuthorizedClient` can be resolved using the following:
|
||||||
|
|
||||||
[source,java]
|
====
|
||||||
|
.Java
|
||||||
|
[source,java,role="primary"]
|
||||||
----
|
----
|
||||||
@GetMapping("/explicit")
|
@GetMapping("/explicit")
|
||||||
Mono<String> explicit(@RegisteredOAuth2AuthorizedClient("client-id") OAuth2AuthorizedClient authorizedClient) {
|
Mono<String> explicit(@RegisteredOAuth2AuthorizedClient("client-id") OAuth2AuthorizedClient authorizedClient) {
|
||||||
@ -18,6 +20,16 @@ Mono<String> explicit(@RegisteredOAuth2AuthorizedClient("client-id") OAuth2Autho
|
|||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
|
.Kotlin
|
||||||
|
[source,kotlin,role="secondary"]
|
||||||
|
----
|
||||||
|
@GetMapping("/explicit")
|
||||||
|
fun explicit(@RegisteredOAuth2AuthorizedClient("client-id") authorizedClient: OAuth2AuthorizedClient?): Mono<String> {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
----
|
||||||
|
====
|
||||||
|
|
||||||
This integrates into Spring Security to provide the following features:
|
This integrates into Spring Security to provide the following features:
|
||||||
|
|
||||||
* Spring Security will automatically refresh expired tokens (if a refresh token is present)
|
* Spring Security will automatically refresh expired tokens (if a refresh token is present)
|
||||||
@ -28,7 +40,9 @@ This integrates into Spring Security to provide the following features:
|
|||||||
If the user authenticated using `oauth2Login()`, then the `client-id` is optional.
|
If the user authenticated using `oauth2Login()`, then the `client-id` is optional.
|
||||||
For example, the following would work:
|
For example, the following would work:
|
||||||
|
|
||||||
[source,java]
|
====
|
||||||
|
.Java
|
||||||
|
[source,java,role="primary"]
|
||||||
----
|
----
|
||||||
@GetMapping("/implicit")
|
@GetMapping("/implicit")
|
||||||
Mono<String> implicit(@RegisteredOAuth2AuthorizedClient OAuth2AuthorizedClient authorizedClient) {
|
Mono<String> implicit(@RegisteredOAuth2AuthorizedClient OAuth2AuthorizedClient authorizedClient) {
|
||||||
@ -36,4 +50,14 @@ Mono<String> implicit(@RegisteredOAuth2AuthorizedClient OAuth2AuthorizedClient a
|
|||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
|
.Kotlin
|
||||||
|
[source,kotlin,role="secondary"]
|
||||||
|
----
|
||||||
|
@GetMapping("/implicit")
|
||||||
|
fun implicit(@RegisteredOAuth2AuthorizedClient authorizedClient: OAuth2AuthorizedClient?): Mono<String> {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
----
|
||||||
|
====
|
||||||
|
|
||||||
This is convenient if the user always authenticates with OAuth2 Login and an access token from the same authorization server is needed.
|
This is convenient if the user always authenticates with OAuth2 Login and an access token from the same authorization server is needed.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user