Class: Warden::JWTAuth::UserDecoder

Inherits:
Object
  • Object
show all
Defined in:
lib/warden/jwt_auth/user_decoder.rb

Overview

Layer above token decoding which directly decodes a user from a JWT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ UserDecoder

Returns a new instance of UserDecoder.



13
14
15
16
# File 'lib/warden/jwt_auth/user_decoder.rb', line 13

def initialize(*args)
  super
  @helper = PayloadUserHelper
end

Instance Attribute Details

#helperObject (readonly)

Returns the value of attribute helper.



11
12
13
# File 'lib/warden/jwt_auth/user_decoder.rb', line 11

def helper
  @helper
end

Instance Method Details

#call(token, scope, aud) ⇒ Interfaces::User

Returns the user that is encoded in a JWT. The scope is used to choose the user repository to which send ‘#find_for_jwt_authentication(sub)` with decoded `sub` claim.

encoded user argument

Parameters:

  • token (String)

    a JWT

  • scope (Symbol)

    Warden scope

  • aud (String)

    Expected aud claim

Returns:

Raises:



32
33
34
35
36
37
38
# File 'lib/warden/jwt_auth/user_decoder.rb', line 32

def call(token, scope, aud)
  payload = TokenDecoder.new.call(token)
  check_valid_claims(payload, scope, aud)
  user = helper.find_user(payload)
  check_valid_user(payload, user, scope)
  user
end