Module: DeviseRailsApiAuthentication::Context
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/devise_rails_api_authentication/context.rb
Instance Method Summary collapse
- #authenticate_user_from_token! ⇒ Object
- #not_authenticated_error ⇒ Object
- #user ⇒ Object
- #user_email ⇒ Object
- #user_token ⇒ Object
Instance Method Details
#authenticate_user_from_token! ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/devise_rails_api_authentication/context.rb', line 13 def authenticate_user_from_token! return if Rails.env.development? if user && Devise.secure_compare(user.authentication_token, user_token) warden.set_user(user, scope: :user, store: false) else not_authenticated_error end end |
#not_authenticated_error ⇒ Object
31 32 33 34 |
# File 'lib/devise_rails_api_authentication/context.rb', line 31 def not_authenticated_error response.headers['WWW-Authenticate'] = 'Token' head status: 401 end |
#user ⇒ Object
36 37 38 |
# File 'lib/devise_rails_api_authentication/context.rb', line 36 def user fail NotImplementedError end |
#user_email ⇒ Object
23 24 25 |
# File 'lib/devise_rails_api_authentication/context.rb', line 23 def user_email request.headers['HTTP_X_USER_EMAIL'] end |
#user_token ⇒ Object
27 28 29 |
# File 'lib/devise_rails_api_authentication/context.rb', line 27 def user_token request.headers['HTTP_X_USER_TOKEN'] end |