module Slots::JWT::AuthenticationHelper::ClassMethods
Public Instance Methods
_check_to_reject?(con, only, except, block)
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 135 def _check_to_reject?(con, only, except, block) return false unless only == ALL || only.any? { |o| o.to_sym == con.action_name.to_sym } return false if except != ALL && except.any? { |e| e.to_sym == con.action_name.to_sym } con.instance_eval(&block) end
_reject_token?(con)
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 132 def _reject_token?(con) (@_reject_token ||= []).any? { |o, e, b| _check_to_reject?(con, o, e, b) } || _superclass_reject_token?(con) end
_superclass_reject_token?(con)
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 141 def _superclass_reject_token?(con) self.superclass.respond_to?('_reject_token?') && self.superclass._reject_token?(con) end
catch_access_denied(response: {errors: {authorization: ["can't access"]}}, status: :forbidden)
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 119 def catch_access_denied(response: {errors: {authorization: ["can't access"]}}, status: :forbidden) rescue_from Slots::JWT::AccessDenied do |exception| render json: response, status: status end end
catch_invalid_login(response: {errors: {authentication: ['login or password is invalid']}}, status: :unauthorized)
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 107 def catch_invalid_login(response: {errors: {authentication: ['login or password is invalid']}}, status: :unauthorized) rescue_from Slots::JWT::AuthenticationFailed do |exception| render json: response, status: status end end
catch_invalid_token(response: {errors: {authentication: ['invalid or missing token']}}, status: :unauthorized)
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 113 def catch_invalid_token(response: {errors: {authentication: ['invalid or missing token']}}, status: :unauthorized) rescue_from Slots::JWT::InvalidToken do |exception| render json: response, status: status end end
ignore_login!(**options)
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 100 def ignore_login!(**options) skip_before_action :require_valid_user, **options skip_before_action :require_load_user, **options, raise: false skip_before_action :update_expired_session_tokens, **options, raise: false skip_after_action :set_token_header!, **options, raise: false end
reject_token(only: ALL, except: ALL, &block)
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 125 def reject_token(only: ALL, except: ALL, &block) raise 'Cant pass both only and except' unless only == ALL || except == ALL only = Array(only) if only != ALL except = Array(except) if except != ALL (@_reject_token ||= []).push([only, except, block]) end
require_login!(load_user: false, **options)
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 87 def require_login!(load_user: false, **options) before_action :require_load_user, **options if load_user before_action :require_valid_user, **options end
require_user_load!(**options)
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 92 def require_user_load!(**options) prepend_before_action :require_load_user, **options end
skip_callback!(**options)
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 96 def skip_callback!(**options) prepend_before_action :ignore_callbacks, **options end
update_expired_session_tokens!(**options)
click to toggle source
# File lib/slots/jwt/authentication_helper.rb, line 82 def update_expired_session_tokens!(**options) prepend_before_action :update_expired_session_tokens, **options after_action :set_token_header!, **options end