Class NimbusJwtEncoder

java.lang.Object
org.springframework.security.oauth2.jwt.NimbusJwtEncoder
All Implemented Interfaces:
JwtEncoder

public final class NimbusJwtEncoder extends Object implements JwtEncoder
An implementation of a JwtEncoder that encodes a JSON Web Token (JWT) using the JSON Web Signature (JWS) Compact Serialization format. The private/secret key used for signing the JWS is supplied by the com.nimbusds.jose.jwk.source.JWKSource provided via the constructor.

NOTE: This implementation uses the Nimbus JOSE + JWT SDK.

Since:
5.6
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    NimbusJwtEncoder(com.nimbusds.jose.jwk.source.JWKSource<com.nimbusds.jose.proc.SecurityContext> jwkSource)
    Constructs a NimbusJwtEncoder using the provided parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    Encode the JWT to it's compact claims representation format.
    void
    setJwkSelector(org.springframework.core.convert.converter.Converter<List<com.nimbusds.jose.jwk.JWK>,com.nimbusds.jose.jwk.JWK> jwkSelector)
    Use this strategy to reduce the list of matching JWKs when there is more than one.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NimbusJwtEncoder

      public NimbusJwtEncoder(com.nimbusds.jose.jwk.source.JWKSource<com.nimbusds.jose.proc.SecurityContext> jwkSource)
      Constructs a NimbusJwtEncoder using the provided parameters.
      Parameters:
      jwkSource - the com.nimbusds.jose.jwk.source.JWKSource
  • Method Details

    • setJwkSelector

      public void setJwkSelector(org.springframework.core.convert.converter.Converter<List<com.nimbusds.jose.jwk.JWK>,com.nimbusds.jose.jwk.JWK> jwkSelector)
      Use this strategy to reduce the list of matching JWKs when there is more than one.

      For example, you can call setJwkSelector(List::getFirst) in order to have this encoder select the first match.

      By default, the class with throw an exception.

      Since:
      6.5
    • encode

      public Jwt encode(JwtEncoderParameters parameters) throws JwtEncodingException
      Description copied from interface: JwtEncoder
      Encode the JWT to it's compact claims representation format.
      Specified by:
      encode in interface JwtEncoder
      Parameters:
      parameters - the parameters containing the JOSE header and JWT Claims Set
      Returns:
      a Jwt
      Throws:
      JwtEncodingException - if an error occurs while attempting to encode the JWT