oauth2.adoc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. = OAuth 2.0 Migrations
  2. == Validate `typ` Header with `JwtTypeValidator`
  3. If when following the 6.5 preparatory steps you set `validateTypes` to `false`, you can now remove it.
  4. You can also remove explicitly adding `JwtTypeValidator` to the list of defaults.
  5. For example, change this:
  6. [tabs]
  7. ======
  8. Java::
  9. +
  10. [source,java,role="primary"]
  11. ----
  12. @Bean
  13. JwtDecoder jwtDecoder() {
  14. NimbusJwtDecoder jwtDecoder = NimbusJwtDecoder.withIssuerLocation(location)
  15. .validateTypes(false) <1>
  16. // ... your remaining configuration
  17. .build();
  18. jwtDecoder.setJwtValidator(JwtValidators.createDefaultWithValidators(
  19. new JwtIssuerValidator(location), JwtTypeValidator.jwt())); <2>
  20. return jwtDecoder;
  21. }
  22. ----
  23. Kotlin::
  24. +
  25. [source,kotlin,role="secondary"]
  26. ----
  27. @Bean
  28. fun jwtDecoder(): JwtDecoder {
  29. val jwtDecoder = NimbusJwtDecoder.withIssuerLocation(location)
  30. .validateTypes(false) <1>
  31. // ... your remaining configuration
  32. .build()
  33. jwtDecoder.setJwtValidator(JwtValidators.createDefaultWithValidators(
  34. JwtIssuerValidator(location), JwtTypeValidator.jwt())) <2>
  35. return jwtDecoder
  36. }
  37. ----
  38. ======
  39. <1> - Switch off Nimbus verifying the `typ`
  40. <2> - Add the default `typ` validator
  41. to this:
  42. [tabs]
  43. ======
  44. Java::
  45. +
  46. [source,java,role="primary"]
  47. ----
  48. @Bean
  49. JwtDecoder jwtDecoder() {
  50. NimbusJwtDecoder jwtDecoder = NimbusJwtDecoder.withIssuerLocation(location)
  51. // ... your remaining configuration <1>
  52. .build();
  53. jwtDecoder.setJwtValidator(JwtValidators.createDefaultWithIssuer(location)); <2>
  54. return jwtDecoder;
  55. }
  56. ----
  57. Kotlin::
  58. +
  59. [source,kotlin,role="secondary"]
  60. ----
  61. @Bean
  62. fun jwtDecoder(): JwtDecoder {
  63. val jwtDecoder = NimbusJwtDecoder.withIssuerLocation(location)
  64. // ... your remaining configuration
  65. .build()
  66. jwtDecoder.setJwtValidator(JwtValidators.createDefaultWithIssuer(location)) <2>
  67. return jwtDecoder
  68. }
  69. ----
  70. ======
  71. <1> - `validateTypes` now defaults to `false`
  72. <2> - `JwtTypeValidator#jwt` is added by all `createDefaultXXX` methods