module Slots::JWT::AuthenticationHelper
Constants
- ALL
Public Instance Methods
access_denied!()
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 64 def access_denied! raise Slots::JWT::AccessDenied end
current_user()
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 37 def current_user return @_current_user if instance_variable_defined?(:@_current_user) @_current_user = jw_token ? Slots::JWT.configuration.authentication_model.from_sloken(jw_token!) : nil end
ignore_callbacks()
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 60 def ignore_callbacks @_ignore_callbacks = true end
jw_token()
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 14 def jw_token return @_jw_token if instance_variable_defined?(:@_jw_token) token = authenticate_with_http_token { |t, _| t } @_jw_token = token ? Slots::JWT::Slokens.decode(token) : nil end
jw_token!()
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 20 def jw_token! jw_token&.valid! end
load_user()
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 41 def load_user current_user&.valid_in_database? && current_user.allowed_new_token? end
new_session_token()
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 30 def new_session_token _current_user = Slots::JWT.configuration.authentication_model.from_sloken(@_jw_token) return false unless _current_user&.update_session @_current_user = _current_user true end
new_token!(session)
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 72 def new_token!(session) current_user.create_token(session) set_token_header! end
require_load_user()
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 55 def require_load_user # Use varaible so that if this action is prepended it will still only be called when checking for valid user, # i.e. so its not called before update_expired_session_tokens if set @_require_load_user = true end
require_valid_user()
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 50 def require_valid_user # Load user will make sure it is in the database and valid in the database raise Slots::JWT::InvalidToken, "User doesnt exist" if @_require_load_user && !load_user access_denied! unless current_user && (@_ignore_callbacks || token_allowed?) end
set_token_header!()
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 45 def set_token_header! # check if current user for logout response.set_header('authorization', "Bearer token=#{current_user.token}") if current_user&.new_token? end
token_allowed?()
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 68 def token_allowed? !(self.class._reject_token?(self)) end
update_expired_session_tokens()
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 24 def update_expired_session_tokens return false unless Slots::JWT.configuration.session_lifetime return false unless jw_token&.expired? && jw_token.session.present? new_session_token end
update_token!()
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 77 def update_token! current_user.update_token end