| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 
 | NAME
    Mojo::JWT - JSON Web Token the Mojo way
SYNOPSIS
      my $jwt = Mojo::JWT->new(claims => {...}, secret => 's3cr3t')->encode;
      my $claims = Mojo::JWT->new(secret => 's3cr3t')->decode($jwt);
DESCRIPTION
    JSON Web Token is described in https://tools.ietf.org/html/rfc7519.
    Mojo::JWT implements that standard with an API that should feel
    familiar to Mojolicious users (though of course it is useful
    elsewhere). Indeed, JWT is much like Mojolicious::Sessions except that
    the result is a url-safe text string rather than a cookie.
    In JWT, the primary payload is called the claims, and a few claims are
    reserved, as seen in the IETF document. The header and the claims are
    signed when stringified to guard against tampering. Note that while
    signed, the data is not encrypted, so don't use it to send secrets over
    clear channels.
ATTRIBUTES
    Mojo::JWT inherits all of the attributes from Mojo::Base and implements
    the following new ones.
 algorithm
    The algorithm to be used to sign a JWT during encoding or else the
    algorithm that was used for the most recent decoding. Defaults to HS256
    until a decode is performed.
    none is an acceptable encoding algorithm, however for it to be used to
    decode, "allow_none" must be set.
 allow_none
    To prevent spoofing attacks, allow_none must be explicitly set to a
    true value otherwise decoding a JWT which specifies the none algorithm
    will result in an exception. The default is of course false.
 claims
    The payload to be encoded or else the claims from the most recent
    decoding. This must be a hash reference, array references are not
    allowed as the top-level JWT claims.
 expires
    The epoch time value after which the JWT value should not be considered
    valid. This value (if set and not undefined) will be used as the exp
    key in the claims or was extracted from the claims during the most
    recent decoding.
 header
    You may set your own headers when encoding the JWT bypassing a hash
    reference to the "header" attribute. Please note that there are two
    default headers set. alg is set to the value of "algorithm" or 'HS256'
    and typ is set to 'JWT'. These cannot be overridden.
 not_before
    The epoch time value before which the JWT value should not be
    considered valid. This value (if set and not undefined) will be used as
    the nbf key in the claims or was extracted from the claims during the
    most recent decoding.
 public
    The public key to be used in decoding an asymmetrically signed JWT (eg.
    RSA). This can be any public key in a string format accepted by
    Crypt::PK::RSA or a Crypt::PK::RSA object (if used a
    Crypt::OpenSSL::RSA object will be converted).
 secret
    The symmetric secret (eg. HMAC) or else the private key used in
    encoding an asymmetrically signed JWT (eg. RSA). Symmetric secrets
    should be a string. A private key can be in a string format accepted by
    Crypt::PK::RSA or a Crypt::PK::RSA object (if used a
    Crypt::OpenSSL::RSA object will be converted).
 set_iat
    If true (false by default), then the iat claim will be set to the value
    of "now" during "encode".
 jwks
    An arrayref of JWK objects used by decode to verify the input token
    when matching with the JWTs kid field.
        my $jwks = Mojo::UserAgent->new->get('https://example.com/oidc/jwks.json')->result->json('/keys');
        my $jwt = Mojo::JWT->new(jwks => $jwks);
        $jwk->decode($token);
METHODS
    Mojo::JWT inherits all of the methods from Mojo::Base and implements
    the following new ones.
 add_jwkset
        my $jwkset = Mojo::UserAgent->new->get('https://example.com/oidc/jwks.json')->result->json;
        my $jwt = Mojo::JWT->new->add_jwkset($jwksset);
        $jwk->decode($token);
    Helper for appending a jwkset to the "jwks". Accepts a hashref with a
    keys field that is an arrayref of jwks and also an arrayref directly.
    Appends the JWKs to "jwks". Returns the instance.
 decode
      my $claims = $jwt->decode($token);
    
      my $peek = sub { my ($jwt, $claims) = @_; ... };
      my $claims = $jwt->decode($token, $peek);
    Decode and parse a JSON Web Token string and return the claims hashref.
    Calling this function immediately sets the "token" to the passed in
    token. It also sets "algorithm" to undef and unsets "claims", "expires"
    and "not_before". These values are then set as part of the parsing
    process.
    Parsing occurs as follows
      * The "algorithm" is extracted from the header and set, if not
      present or permissible an exception is thrown
      * Any JWKs in /jwks are checked against the headers and if one is
      found then it is set in "public" or "secret" as appropriate to the
      "algorithm"
      * If a $peek callback is provided, it is called with the instance and
      claims as arguments
      * The signature is verified or an exception is thrown
      * The timing claims ("expires" and "not_before"), if present, are
      evaluated, failures result in exceptions. On success the values are
      set in the relevant attributes
      * The "claims" attribute is set and the claims are returned.
    Note that when the $peek callback is invoked, the claims have not yet
    been verified. This callback is most likely to be used to inspect the
    iss or issuer claim to determine a secret or key for decoding. The
    return value is ignored, changes should be made to the instances
    attributes directly. Since the "algorithm" has already been parsed, it
    is available via the instance attribute as well.
 encode
      my $token = $jwt->encode;
    Encode the data expressed in the instance attributes: "algorithm",
    "claims", "expires", "not_before". Note that if the timing attributes
    are given, they override existing keys in the "claims". Calling encode
    immediately clears the "token" and upon completion sets it to the
    result as well as returning it.
    Note also that due to Perl's hash randomization, repeated encoding is
    not guaranteed to result in the same encoded string. However any
    encoded string will survive an encode/decode roundtrip.
 header
      my $header = $jwt->header;
    Returns a hash reference representing the JWT header, constructed from
    instance attributes (see "algorithm").
 now
      my $time = $jwt->now;
    Returns the current time, currently implemented as the core time
    function.
 sign_hmac
      my $signature = $jwt->sign_hmac($size, $payload);
    Returns the HMAC SHA signature for the given size and payload. The
    "secret" attribute is used as the symmetric key. The result is not yet
    base64 encoded. This method is provided mostly for the purposes of
    subclassing.
 sign_rsa
      my $signature = $jwt->sign_rsa($size, $payload);
    Returns the RSA signature for the given size and payload. The "secret"
    attribute is used as the private key. The result is not yet base64
    encoded. This method is provided mostly for the purposes of
    subclassing.
 token
    The most recently encoded or decoded token. Note that any attribute
    modifications are not taken into account until "encode" is called
    again.
 verify_rsa
      my $bool = $jwt->verify_rsa($size, $payload, $signature);
    Returns true if the given RSA size algorithm validates the given
    payload and signature. The "public" attribute is used as the public
    key. This method is provided mostly for the purposes of subclassing.
SEE ALSO
    Acme::JWT
    JSON::WebToken
    http://jwt.io/
SOURCE REPOSITORY
    http://github.com/jberger/Mojo-JWT
AUTHOR
    Joel Berger, <joel.a.berger@gmail.com>
CONTRIBUTORS
    Christopher Raa (mishanti1)
    Cameron Daniel (ccakes)
COPYRIGHT AND LICENSE
    Copyright (C) 2015 by "AUTHOR" and "CONTRIBTORS".
    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.
 |