Class: Warden::JWTAuth::UserEncoder
- Inherits:
-
Object
- Object
- Warden::JWTAuth::UserEncoder
- 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
-
#helper ⇒ Object
readonly
Returns the value of attribute helper.
Instance Method Summary collapse
-
#call(user, scope, aud) ⇒ String
Encodes a user for given scope into a JWT.
-
#initialize ⇒ UserEncoder
constructor
A new instance of UserEncoder.
Constructor Details
#initialize ⇒ UserEncoder
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
#helper ⇒ Object (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, aud) ⇒ String
Encodes a user for given scope into a JWT.
Payload generated includes:
-
a ‘sub` claim which is build calling `jwt_subject` in `user`
-
an ‘aud` claim taken as it is in the `aud` parameter
-
a custom ‘scp` claim taken as the value of the `scope` parameter
as a string.
The result of calling ‘jwt_payload` in user is also merged into the payload.
31 32 33 34 35 |
# File 'lib/warden/jwt_auth/user_encoder.rb', line 31 def call(user, scope, aud) payload = helper.payload_for_user(user, scope).merge('aud' => aud) token = TokenEncoder.new.call(payload) [token, payload] end |