|
1 | 1 | [[oauth2Client-client-auth-support]]
|
2 | 2 | = Client Authentication Support
|
3 | 3 |
|
| 4 | +[[oauth2Client-client-credentials-auth]] |
| 5 | +== Client Credentials |
| 6 | + |
| 7 | +=== Authenticate using `client_secret_basic` |
| 8 | + |
| 9 | +Client Authentication with HTTP Basic is supported out of the box and no customization is necessary to enable it. |
| 10 | +The default implementation is provided by `DefaultOAuth2TokenRequestHeadersConverter`. |
| 11 | + |
| 12 | +Given the following Spring Boot properties for an OAuth 2.0 client registration: |
| 13 | + |
| 14 | +[source,yaml] |
| 15 | +---- |
| 16 | +spring: |
| 17 | + security: |
| 18 | + oauth2: |
| 19 | + client: |
| 20 | + registration: |
| 21 | + okta: |
| 22 | + client-id: client-id |
| 23 | + client-secret: client-secret |
| 24 | + client-authentication-method: client_secret_basic |
| 25 | + authorization-grant-type: authorization_code |
| 26 | + ... |
| 27 | +---- |
| 28 | + |
| 29 | +The following example shows how to configure `DefaultAuthorizationCodeTokenResponseClient` to disable URL encoding of the client credentials: |
| 30 | + |
| 31 | +[tabs] |
| 32 | +====== |
| 33 | +Java:: |
| 34 | ++ |
| 35 | +[source,java,role="primary"] |
| 36 | +---- |
| 37 | +DefaultOAuth2TokenRequestHeadersConverter<OAuth2AuthorizationCodeGrantRequest> headersConverter = |
| 38 | + new DefaultOAuth2TokenRequestHeadersConverter<>(); |
| 39 | +headersConverter.setEncodeClientCredentials(false); |
| 40 | +
|
| 41 | +OAuth2AuthorizationCodeGrantRequestEntityConverter requestEntityConverter = |
| 42 | + new OAuth2AuthorizationCodeGrantRequestEntityConverter(); |
| 43 | +requestEntityConverter.setHeadersConverter(headersConverter); |
| 44 | +
|
| 45 | +DefaultAuthorizationCodeTokenResponseClient tokenResponseClient = |
| 46 | + new DefaultAuthorizationCodeTokenResponseClient(); |
| 47 | +tokenResponseClient.setRequestEntityConverter(requestEntityConverter); |
| 48 | +---- |
| 49 | +
|
| 50 | +Kotlin:: |
| 51 | ++ |
| 52 | +[source,kotlin,role="secondary"] |
| 53 | +---- |
| 54 | +val headersConverter = DefaultOAuth2TokenRequestHeadersConverter<OAuth2AuthorizationCodeGrantRequest>() |
| 55 | +headersConverter.setEncodeClientCredentials(false) |
| 56 | +
|
| 57 | +val requestEntityConverter = OAuth2AuthorizationCodeGrantRequestEntityConverter() |
| 58 | +requestEntityConverter.setHeadersConverter(headersConverter) |
| 59 | +
|
| 60 | +val tokenResponseClient = DefaultAuthorizationCodeTokenResponseClient() |
| 61 | +tokenResponseClient.setRequestEntityConverter(requestEntityConverter) |
| 62 | +---- |
| 63 | +====== |
| 64 | + |
| 65 | +=== Authenticate using `client_secret_post` |
| 66 | + |
| 67 | +Client Authentication with client credentials included in the request-body is supported out of the box and no customization is necessary to enable it. |
| 68 | + |
| 69 | +The following Spring Boot properties for an OAuth 2.0 client registration demonstrate the configuration: |
| 70 | + |
| 71 | +[source,yaml] |
| 72 | +---- |
| 73 | +spring: |
| 74 | + security: |
| 75 | + oauth2: |
| 76 | + client: |
| 77 | + registration: |
| 78 | + okta: |
| 79 | + client-id: client-id |
| 80 | + client-secret: client-secret |
| 81 | + client-authentication-method: client_secret_post |
| 82 | + authorization-grant-type: authorization_code |
| 83 | + ... |
| 84 | +---- |
4 | 85 |
|
5 | 86 | [[oauth2Client-jwt-bearer-auth]]
|
6 | 87 | == JWT Bearer
|
@@ -203,3 +284,28 @@ converter.setJwtClientAssertionCustomizer { context ->
|
203 | 284 | }
|
204 | 285 | ----
|
205 | 286 | ======
|
| 287 | + |
| 288 | +[[oauth2Client-public-auth]] |
| 289 | +== Public Authentication |
| 290 | + |
| 291 | +Public Client Authentication is supported out of the box and no customization is necessary to enable it. |
| 292 | + |
| 293 | +The following Spring Boot properties for an OAuth 2.0 client registration demonstrate the configuration: |
| 294 | + |
| 295 | +[source,yaml] |
| 296 | +---- |
| 297 | +spring: |
| 298 | + security: |
| 299 | + oauth2: |
| 300 | + client: |
| 301 | + registration: |
| 302 | + okta: |
| 303 | + client-id: client-id |
| 304 | + client-authentication-method: none |
| 305 | + authorization-grant-type: authorization_code |
| 306 | + ... |
| 307 | +---- |
| 308 | + |
| 309 | +[NOTE] |
| 310 | +Public Clients are supported using https://tools.ietf.org/html/rfc7636[Proof Key for Code Exchange] (PKCE). |
| 311 | +PKCE will automatically be used when `client-authentication-method` is set to "none" (`ClientAuthenticationMethod.NONE`). |
0 commit comments