Class: Warden::Auth0::TokenDecoder

Inherits:
Object
  • Object
show all
Defined in:
lib/warden/auth0/token_decoder.rb

Overview

Decodes a JWT into a hash payload. Algorithm and JWKS are provided by the strategy config.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(algorithm:, jwks:) ⇒ TokenDecoder

Returns a new instance of TokenDecoder.

Parameters:

  • algorithm (String)

    algorithm (e.g. 'RS256')

  • jwks (Object)

    JWKS used to verify (e.g. JWT::JWK::Set)



13
14
15
16
# File 'lib/warden/auth0/token_decoder.rb', line 13

def initialize(algorithm:, jwks:)
  @algorithm = algorithm
  @jwks = jwks
end

Instance Attribute Details

#algorithmObject (readonly)

Returns the value of attribute algorithm.



9
10
11
# File 'lib/warden/auth0/token_decoder.rb', line 9

def algorithm
  @algorithm
end

#jwksObject (readonly)

Returns the value of attribute jwks.



9
10
11
# File 'lib/warden/auth0/token_decoder.rb', line 9

def jwks
  @jwks
end

Instance Method Details

#call(token) ⇒ Hash

Decodes the payload from a JWT as a hash

Parameters:

  • token (String)

    a JWT

Returns:

  • (Hash)

    payload decoded from the JWT



22
23
24
# File 'lib/warden/auth0/token_decoder.rb', line 22

def call(token)
  JWT.decode(token, nil, true, algorithms: algorithm, jwks: jwks)[0]
end