module Warden::JWTAuth::PayloadUserHelper
Helper functions to deal with user info present in a decode payload
Public Class Methods
aud_matches?(payload, aud)
click to toggle source
Returns whether given aud matches with the one encoded in the payload @param payload [Hash] JWT payload @return [Boolean]
# File lib/warden/jwt_auth/payload_user_helper.rb, line 28 def self.aud_matches?(payload, aud) payload['aud'] == aud end
find_user(payload)
click to toggle source
Returns user encoded in given payload
@param payload [Hash] JWT payload @return [Interfaces::User] an user, whatever it is
# 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)
click to toggle source
Returns the payload to encode for a given user in a scope
@param user [Interfaces::User] an user, whatever it is @param scope [Symbol] A Warden
scope @return [Hash] payload to encode :reek: ManualDispatch
# 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)
click to toggle source
Returns whether given scope matches with the one encoded in the payload @param payload [Hash] JWT payload @return [Boolean]
# File lib/warden/jwt_auth/payload_user_helper.rb, line 21 def self.scope_matches?(payload, scope) payload['scp'] == scope.to_s end