authentication.adoc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. = Authentication Changes
  2. == Opaque Token Credentials Will Be Encoded For You
  3. 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.
  4. This change means you will no longer have to encode the client id and secret yourself.
  5. If your client id or secret contain URL-unsafe characters, then you can prepare yourself for this change by doing the following:
  6. === Replace Usage of `introspectionClientCredentials`
  7. 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`:
  8. [tabs]
  9. ======
  10. Java::
  11. +
  12. [source,java,role="primary"]
  13. ----
  14. @Bean
  15. OpaqueTokenIntrospector introspector() {
  16. return SpringOpaqueTokenIntrospector.withIntrospectionUri(introspectionUri)
  17. .clientId(unencodedClientId).clientSecret(unencodedClientSecret).build();
  18. }
  19. ----
  20. Kotlin::
  21. +
  22. [source,kotlin,role="secondary"]
  23. ----
  24. @Bean
  25. fun introspector(): OpaqueTokenIntrospector {
  26. return SpringOpaqueTokenIntrospector.withIntrospectionUri(introspectionUri)
  27. .clientId(unencodedClientId).clientSecret(unencodedClientSecret).build()
  28. }
  29. ----
  30. ======
  31. The above will be the default in 7.0.
  32. If this setting gives you trouble or you cannot apply it for now, you can use the `RestOperations` constructor instead:
  33. [tabs]
  34. ======
  35. Java::
  36. +
  37. [source,java,role="primary"]
  38. ----
  39. @Bean
  40. OpaqueTokenIntrospector introspector() {
  41. RestTemplate rest = new RestTemplate();
  42. rest.addInterceptor(new BasicAuthenticationInterceptor(encodedClientId, encodedClientSecret));
  43. return new SpringOpaqueTokenIntrospector(introspectionUri, rest);
  44. }
  45. ----
  46. Kotlin::
  47. +
  48. [source,kotlin,role="secondary"]
  49. ----
  50. @Bean
  51. fun introspector(): OpaqueTokenIntrospector {
  52. val rest = RestTemplate()
  53. rest.addInterceptor(BasicAuthenticationInterceptor(encodedClientId, encodedClientSecret))
  54. return SpringOpaqueTokenIntrospector(introspectionUri, rest)
  55. }
  56. ----
  57. ======