Module: Devise::Api::Controllers::Helpers
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/devise/api/controllers/helpers.rb
Instance Method Summary collapse
- #authenticate_devise_api_token! ⇒ Object
- #current_devise_api_refresh_token ⇒ Object
- #current_devise_api_token ⇒ Object
- #current_devise_api_user ⇒ Object
Instance Method Details
#authenticate_devise_api_token! ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/devise/api/controllers/helpers.rb', line 11 def authenticate_devise_api_token! if current_devise_api_token.blank? error_response = Devise::Api::Responses::ErrorResponse.new(request, error: :invalid_token, resource_class: resource_class) return render json: error_response.body, status: error_response.status end if current_devise_api_token.expired? error_response = Devise::Api::Responses::ErrorResponse.new(request, error: :expired_token, resource_class: resource_class) return render json: error_response.body, status: error_response.status end return unless current_devise_api_token.revoked? error_response = Devise::Api::Responses::ErrorResponse.new(request, error: :revoked_token, resource_class: resource_class) render json: error_response.body, status: error_response.status end |
#current_devise_api_refresh_token ⇒ Object
34 35 36 37 38 |
# File 'lib/devise/api/controllers/helpers.rb', line 34 def current_devise_api_refresh_token token = find_devise_api_token Devise.api.config.base_token_model.constantize.find_by(refresh_token: token) end |
#current_devise_api_token ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/devise/api/controllers/helpers.rb', line 40 def current_devise_api_token return @current_devise_api_token if @current_devise_api_token token = find_devise_api_token devise_api_token_model = Devise.api.config.base_token_model.constantize @current_devise_api_token = devise_api_token_model.find_by(access_token: token) end |
#current_devise_api_user ⇒ Object
48 49 50 |
# File 'lib/devise/api/controllers/helpers.rb', line 48 def current_devise_api_user current_devise_api_token&.resource_owner end |