Module: Warden::JWTAuth::PayloadUserHelper
- Defined in:
- lib/warden/jwt_auth/payload_user_helper.rb
Overview
Helper functions to deal with user info present in a decode payload
Class Method Summary collapse
-
.aud_matches?(payload, aud) ⇒ Boolean
Returns whether given aud matches with the one encoded in the payload.
-
.find_user(payload) ⇒ Interfaces::User
Returns user encoded in given payload.
-
.payload_for_user(user, scope) ⇒ Hash
Returns the payload to encode for a given user in a scope.
-
.scope_matches?(payload, scope) ⇒ Boolean
Returns whether given scope matches with the one encoded in the payload.
Class Method Details
.aud_matches?(payload, aud) ⇒ Boolean
Returns whether given aud matches with the one encoded in the payload
28 29 30 |
# File 'lib/warden/jwt_auth/payload_user_helper.rb', line 28 def self.aud_matches?(payload, aud) payload['aud'] == aud end |
.find_user(payload) ⇒ Interfaces::User
Returns user encoded in given payload
11 12 13 14 15 16 |
# File 'lib/warden/jwt_auth/payload_user_helper.rb', line 11 def self.find_user(payload) config = JWTAuth.config scope = payload['scp'].to_sym user_repo = config.mappings[scope] user_repo.find_for_jwt_authentication(payload['sub']) end |
.payload_for_user(user, scope) ⇒ Hash
Returns the payload to encode for a given user in a scope
:reek:ManualDispatch
38 39 40 41 42 43 44 |
# File 'lib/warden/jwt_auth/payload_user_helper.rb', line 38 def self.payload_for_user(user, scope) sub = user.jwt_subject payload = { 'sub' => String(sub), 'scp' => scope.to_s } return payload unless user.respond_to?(:jwt_payload) user.jwt_payload.merge(payload) end |
.scope_matches?(payload, scope) ⇒ Boolean
Returns whether given scope matches with the one encoded in the payload
21 22 23 |
# File 'lib/warden/jwt_auth/payload_user_helper.rb', line 21 def self.scope_matches?(payload, scope) payload['scp'] == scope.to_s end |