See Java.Crypto.Jwts

Hierarchy

  • Builder

Constructors

Methods

  • Sets an arbitrary claim (a.k.a. body) param, if a parameter has already been set for that key then this method will override it.

    NOTE: If you pass a Java.Time.Date value, this library will convert that date value into the number of seconds since epoch

    Parameters

    • claimKey: string

      the key in the claim segment to write to

    • claimValue: string | number | Date

      the value to assign

    Returns Builder

  • Generates the final JWT with the configuration parameters and key signatures as set.

    Returns string

  • Sets the value for standard "aud" parameter in the JWT's claim segment (Also known as the Body). If this property has already been set, then this method will override it. This is the same as calling claim("aud", "your value here");

    Parameters

    • aud: string

      the value to assign

    Returns Builder

  • Sets an arbitrary header param, if a parameter for that key is already set, then this method will override it.

    Parameters

    • key: string

      they key for this parameter

    • value: string

      the value to write over it

    Returns Builder

  • Sets the value for standard "jti" parameter in the JWT's claim segment (Also known as the Body). If this property has already been set, then this method will override it. This is the same as calling claim("jti", "your value here");

    Parameters

    • jti: string

      the value to assign

    Returns Builder

  • Sets the value for standard "iat" parameter in the JWT's claim segment (Also known as the Body). If this property has already been set, then this method will override it. This is the same as calling claim("iat", "your value here");

    NOTE: While it may seem confusing to pass a Java.Time.Date object, the library automatically converts that value into a number representing that date value as the number of seconds since epoch

    Parameters

    • iat: Date

      the value to assign

    Returns Builder

  • Sets the value for standard "iss" parameter in the JWT's claim segment (Also known as the Body). If this property has already been set, then this method will override it. This is the same as calling `claim("iss", "your value here");

    Parameters

    • iss: string

      the value to assign

    Returns Builder

  • Sets the value for standard "nbf" parameter in the JWT's claim segment (Also known as the Body). If this property has already been set, then this method will override it. This is the same as calling claim("nbf", "your value here");

    Parameters

    • nbf: number

      the value to assign

    Returns Builder

  • Sets the value for standard "sub" parameter in the JWT's claim segment (Also known as the Body). If this property has already been set, then this method will override it. This is the same as calling claim("sub", "your value here");

    Parameters

    • sub: string

      the value to assign

    Returns Builder

  • set the key with which you are going to sign this token

    Parameters

    Returns Builder

    Example

    const pKey = B.crypto.createPrivateKeyFromPKCS8("RSA", privKey);
    const jwtBuilder = B.crypto.jwts.Jwts.builder();
    const fullJsonWebToken = jwtBuilder
    .claim("key","value")
    .signWith(pKey)
    .compact(); // the compact method converts it to a string

    NOTE: When you sign with a private key, this library will automatically overwrite the header parameter "alg" with "RS512"

Generated using TypeDoc