Class: Motion::Authentication::DeviseSimpleTokenAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/project/strategies/devise_simple_token_auth.rb

Class Method Summary collapse

Class Method Details

.authorization_headerObject



28
29
30
31
32
# File 'lib/project/strategies/devise_simple_token_auth.rb', line 28

def authorization_header
  token = MotionKeychain.get :auth_token
  email = MotionKeychain.get :auth_email
  %Q|Token token="#{token}", email="#{email}"|
end

.sign_in(sign_in_url, params, &block) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/project/strategies/devise_simple_token_auth.rb', line 5

def (, params, &block)
  HTTP.post(, json: { user: params }) do |response|
    if response.success?
      store_auth_tokens(response.object)
    end
    block.call(response)
  end
end

.sign_out(&block) ⇒ Object



38
39
40
41
42
# File 'lib/project/strategies/devise_simple_token_auth.rb', line 38

def sign_out(&block)
  MotionKeychain.remove :auth_email
  MotionKeychain.remove :auth_token
  block.call
end

.sign_up(sign_up_url, params, &block) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/project/strategies/devise_simple_token_auth.rb', line 14

def (, params, &block)
  HTTP.post(, json: { user: params }) do |response|
    if response.success?
      store_auth_tokens(response.object)
    end
    block.call(response)
  end
end

.signed_in?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/project/strategies/devise_simple_token_auth.rb', line 34

def signed_in?
  !! MotionKeychain.get(:auth_token)
end

.store_auth_tokens(data) ⇒ Object



23
24
25
26
# File 'lib/project/strategies/devise_simple_token_auth.rb', line 23

def store_auth_tokens(data)
  MotionKeychain.set :auth_email, data["email"]
  MotionKeychain.set :auth_token, data["token"]
end