Class: GrapeDeviseAuth::TokenAuthorizer

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/grape_devise_auth/token_authorizer.rb

Instance Method Summary collapse

Constructor Details

#initialize(data, devise_interface) ⇒ TokenAuthorizer

Returns a new instance of TokenAuthorizer.



5
6
7
8
# File 'lib/grape_devise_auth/token_authorizer.rb', line 5

def initialize(data, devise_interface)
  @data = data
  @devise_interface = devise_interface
end

Instance Method Details

#authenticate_from_token(mapping = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/grape_devise_auth/token_authorizer.rb', line 10

def authenticate_from_token(mapping = nil)
  @resource_class =  devise_interface.mapping_to_class(mapping)
  return nil unless resource_class

  # client id is not required
  client_id = data.client_id || 'default'

  resource_from_existing_devise_user
  return resource if correct_resource_type_logged_in? &&
                     resource_does_not_have_client_token?(client_id)

  return nil unless data.token_prerequisites_present?
  load_user_from_uid
  return nil unless user_authenticated?

  user
end