JSONWebToken#

SYNOPSIS#

Support for JSON web tokens (JWT).

PUBLIC INTERFACE#

new()#

Don't use the constructor directly, use the ObjectManager instead:

my $JWTObject = $Kernel::OM->Get('Kernel::System::JSONWebToken');

IsSupported()#

Checks (and requires) Crypt::JWT module needed for JWT support.

my $JWTObjectIsSupported = $JWTObject->IsSupported();

Returns true value if JWT is supported.

Encode()#

Encodes a JSON web token with the given data.

my $JWT = $JWTObject->Encode(
    Payload => {

        # arbitrary data
        Subject       => '...',
        SomeOtherData => {
            # ...
        },
    },
    Algorithm   => 'RS512', # see https://metacpan.org/pod/Crypt::JWT#alg

    # Key or key file
    Key         => '...', # see https://metacpan.org/pod/Crypt::JWT#key1
    KeyFilePath => '/home/user1/key.pem',

    KeyPassword          => '...', # optional, password for the key
    AdditionalHeaderData => { # optional

        # arbitrary data
        Type => '...',
    },

    # Optional: Use this hash to give additional parameters to Crypt::JWT.
    CryptJWTParameters => {

        # see https://metacpan.org/pod/Crypt::JWT#encode_jwt
        enc => '...',

        # ...
    },

    # Optional: Data to be placed in placeholders in given Payload and AdditionalHeaderData parameters.
    # All values of the given payload and additional header data hash will be searched
    # for all the given placeholders and their values be replaced.
    PlaceholderData => {
        OTRS_JWT_CertSubject         => '...',
        OTRS_JWT_ExpirationTimestamp => '9999999999999',

        # ...
    },
);

Returns a JSON web token string on success.

Decode()#

Decodes a JSON web token.

my $JWT = $JWTObject->Decode(
    Token       => '...',

    # Key or KeyFilePath
    Key         => '...', # see https://metacpan.org/pod/Crypt::JWT#key1
    KeyFilePath => '/home/user1/key.pem',

    KeyPassword => '...', # optional, password for the key

    # Optional: Use this hash to give additional parameters to Crypt::JWT.
    CryptJWTParameters => {

        # see https://metacpan.org/pod/Crypt::JWT#decode_jwt
        # '...' => '...',

        # ...
    },
);

Returns decoded data of the given JSON web token.