Class: GrapeDeviseAuth::DeviseInterface
- Inherits:
-
Object
- Object
- GrapeDeviseAuth::DeviseInterface
- Defined in:
- lib/grape_devise_auth/devise_interface.rb
Instance Method Summary collapse
- #exisiting_warden_user(resource_class) ⇒ Object
-
#initialize(data) ⇒ DeviseInterface
constructor
A new instance of DeviseInterface.
- #mapping_to_class(m) ⇒ Object
-
#set_user_in_warden(scope, resource) ⇒ Object
extracted and simplified from Devise.
Constructor Details
#initialize(data) ⇒ DeviseInterface
Returns a new instance of DeviseInterface.
3 4 5 6 |
# File 'lib/grape_devise_auth/devise_interface.rb', line 3 def initialize(data) @warden = data.warden @client_id = data.client_id end |
Instance Method Details
#exisiting_warden_user(resource_class) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/grape_devise_auth/devise_interface.rb', line 19 def exisiting_warden_user(resource_class) warden_user = warden.user(resource_class.to_s.underscore.to_sym) return unless warden_user && warden_user.tokens[@client_id].nil? resource = warden_user resource.create_new_auth_token resource end |
#mapping_to_class(m) ⇒ Object
14 15 16 17 |
# File 'lib/grape_devise_auth/devise_interface.rb', line 14 def mapping_to_class(m) mapping = m ? Devise.mappings[m] : Devise.mappings.values.first @resource_class = mapping.to end |
#set_user_in_warden(scope, resource) ⇒ Object
extracted and simplified from Devise
9 10 11 12 |
# File 'lib/grape_devise_auth/devise_interface.rb', line 9 def set_user_in_warden(scope, resource) scope = Devise::Mapping.find_scope!(scope) warden.set_user(resource, scope: scope, store: false) end |