Method: JWT.encode

Defined in:
lib/jwt.rb

.encode(payload, key, algorithm = 'HS256', header_fields = {}) ⇒ String

Encodes a payload into a JWT.

Parameters:

  • payload (Hash)

    the payload to encode.

  • key (String)

    the key used to sign the JWT.

  • algorithm (String) (defaults to: 'HS256')

    the algorithm used to sign the JWT.

  • header_fields (Hash) (defaults to: {})

    additional headers to include in the JWT.

Returns:

  • (String)

    the encoded JWT.



31
32
33
34
35
36
# File 'lib/jwt.rb', line 31

def encode(payload, key, algorithm = 'HS256', header_fields = {})
  Encode.new(payload: payload,
             key: key,
             algorithm: algorithm,
             headers: header_fields).segments
end