20.3 DECODE Function

This function decodes a raw token value.

Syntax

function decode (
    p_value         in varchar2,
    p_signature_key in raw      default null )
return t_token;

Parameters

Table 20-3 DECODE Function Parameters

Parameter Description

p_value

A raw token value contains 3 base64-encoded parts, which are separated by '.'. The parts are header, payload and signature.

p_signature_key

If not null, validate p_value's signature using this key and the algorithm specified in header. The algorithms 'HS256' and 'none' are supported, but 'HS256' requires 12c or higher.

Returns

A t_token.

Raises

VALUE_ERROR: The input value is invalid.

WWV_FLOW_CRYPTO.UNSUPPORTED_FUNCTION: The token is signed using an unsupported function.

Example

This example decodes an encoded token and print it's contents.

declare
    l_token apex_jwt.t_token;
    l_keys apex_t_varchar2;
begin
    l_token := apex_jwt.decode (
                   p_value => 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsb2dnZWRJbkFzIjoiYWRtaW4iLCJpYXQiOjE0MjI3Nzk2Mzh9.gzSraSYS8EXBxLN_oWnFSRgCzcmJmMjLiuyu5CSpyHI' );
    sys.dbms_output.put_line('--- Header ---');
    apex_json.parse(l_token.header);
    l_keys := apex_json.get_members('.');
    for i in 1 .. l_keys.count loop
        sys.dbms_output.put_line(l_keys(i)||'='||apex_json.get_varchar2(l_keys(i));
    end loop;
    sys.dbms_output.put_line('--- Payload ---');
    apex_json.parse(l_token.payload);
    l_keys := apex_json.get_members('.');
    for i in 1 .. l_keys.count loop
        sys.dbms_output.put_line(l_keys(i)||'='||apex_json.get_varchar2(l_keys(i));
    end loop;
end;

Output:

--- Header ---
alg=HS256
typ=JWT
--- Payload ---
loggedInAs=admin
iat=1422779638