|
| 1 | += Authentication Changes |
| 2 | + |
| 3 | +== Opaque Token Credentials Will Be Encoded For You |
| 4 | + |
| 5 | +In order to comply more closely with the Introspection RFC, Spring Security's opaque token support will encode the client id and secret before creating the authorization header. |
| 6 | +This change means you will no longer have to encode the client id and secret yourself. |
| 7 | + |
| 8 | +If your client id or secret contain URL-unsafe characters, then you can prepare yourself for this change by doing the following: |
| 9 | + |
| 10 | +=== Replace Usage of `introspectionClientCredentials` |
| 11 | + |
| 12 | +Since Spring Security can now do the encoding for you, replace xref:servlet/oauth2/resource-server/opaque-token.adoc#oauth2resourceserver-opaque-introspectionuri-dsl[using `introspectionClientCredentials`] with publishing the following `@Bean`: |
| 13 | + |
| 14 | +[tabs] |
| 15 | +====== |
| 16 | +Java:: |
| 17 | ++ |
| 18 | +[source,java,role="primary"] |
| 19 | +---- |
| 20 | +@Bean |
| 21 | +OpaqueTokenIntrospector introspector() { |
| 22 | + return SpringOpaqueTokenIntrospector.withIntrospectionUri(introspectionUri) |
| 23 | + .clientId(unencodedClientId).clientSecret(unencodedClientSecret).build(); |
| 24 | +} |
| 25 | +---- |
| 26 | +
|
| 27 | +Kotlin:: |
| 28 | ++ |
| 29 | +[source,kotlin,role="secondary"] |
| 30 | +---- |
| 31 | +@Bean |
| 32 | +fun introspector(): OpaqueTokenIntrospector { |
| 33 | + return SpringOpaqueTokenIntrospector.withIntrospectionUri(introspectionUri) |
| 34 | + .clientId(unencodedClientId).clientSecret(unencodedClientSecret).build() |
| 35 | +} |
| 36 | +---- |
| 37 | +====== |
| 38 | + |
| 39 | +The above will be the default in 7.0. |
| 40 | + |
| 41 | +If this setting gives you trouble or you cannot apply it for now, you can use the `RestOperations` constructor instead: |
| 42 | + |
| 43 | +[tabs] |
| 44 | +====== |
| 45 | +Java:: |
| 46 | ++ |
| 47 | +[source,java,role="primary"] |
| 48 | +---- |
| 49 | +@Bean |
| 50 | +OpaqueTokenIntrospector introspector() { |
| 51 | + RestTemplate rest = new RestTemplate(); |
| 52 | + rest.addInterceptor(new BasicAuthenticationInterceptor(encodedClientId, encodedClientSecret)); |
| 53 | + return new SpringOpaqueTokenIntrospector(introspectionUri, rest); |
| 54 | +} |
| 55 | +---- |
| 56 | +
|
| 57 | +Kotlin:: |
| 58 | ++ |
| 59 | +[source,kotlin,role="secondary"] |
| 60 | +---- |
| 61 | +@Bean |
| 62 | +fun introspector(): OpaqueTokenIntrospector { |
| 63 | + val rest = RestTemplate() |
| 64 | + rest.addInterceptor(BasicAuthenticationInterceptor(encodedClientId, encodedClientSecret)) |
| 65 | + return SpringOpaqueTokenIntrospector(introspectionUri, rest) |
| 66 | +} |
| 67 | +---- |
| 68 | +====== |
0 commit comments