Class: Warden::JWTAuth::UserEncoder

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

Overview

Layer above token encoding which directly encodes a user to a JWT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUserEncoder

Returns a new instance of UserEncoder.



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

def initialize
  @helper = PayloadUserHelper
end

Instance Attribute Details

#helperObject (readonly)

Returns the value of attribute helper.



9
10
11
# File 'lib/warden/jwt_auth/user_encoder.rb', line 9

def helper
  @helper
end

Instance Method Details

#call(user, scope) ⇒ String

Encodes a user for given scope into a JWT. Payload generated includes a ‘sub` claim which is build calling `jwt_subject` in `user`, and a custom `scp` claim which value is `scope` as a string. The result of calling `jwt_payload` in user is also merged into the payload.

Parameters:

  • user (Interfaces::User)

    an user, whatever it is

  • scope (Symbol)

    Warden scope

Returns:

  • (String)

    encoded JWT



23
24
25
26
# File 'lib/warden/jwt_auth/user_encoder.rb', line 23

def call(user, scope)
  payload = helper.payload_for_user(user, scope)
  TokenEncoder.new.call(payload)
end