Class: Motion::Authentication::DeviseTokenAuth
- Inherits:
-
Object
- Object
- Motion::Authentication::DeviseTokenAuth
- Defined in:
- lib/project/strategies/devise_token_auth_gem.rb
Class Method Summary collapse
- .authorization_header ⇒ Object
- .deserialize(mystring, arr_sep = ',', key_sep = '·') ⇒ Object
- .set_current_user ⇒ Object
- .sign_in(sign_in_url, params, &block) ⇒ Object
- .sign_out(&block) ⇒ Object
- .sign_up(sign_up_url, params, &block) ⇒ Object
- .signed_in? ⇒ Boolean
- .store_auth_tokens(response, headers) ⇒ Object
Class Method Details
.authorization_header ⇒ Object
45 46 47 48 49 50 |
# File 'lib/project/strategies/devise_token_auth_gem.rb', line 45 def token = MotionKeychain.get :auth_token uid = MotionKeychain.get :auth_uid client = MotionKeychain.get :auth_client {"access-token" => token, "uid" => uid, "client" => client } end |
.deserialize(mystring, arr_sep = ',', key_sep = '·') ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/project/strategies/devise_token_auth_gem.rb', line 64 def deserialize(mystring, arr_sep=',', key_sep='·') array = mystring.split(arr_sep) hash = {} array.each do |e| key_value = e.split(key_sep) hash[key_value[0]] = key_value[1] end return hash end |
.set_current_user ⇒ Object
41 42 43 |
# File 'lib/project/strategies/devise_token_auth_gem.rb', line 41 def set_current_user deserialize(MotionKeychain.get :current_user) end |
.sign_in(sign_in_url, params, &block) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/project/strategies/devise_token_auth_gem.rb', line 5 def sign_in(sign_in_url, params, &block) HTTP.post(sign_in_url, json: params) do |response| if response.success? store_auth_tokens(response.object, response.headers) end block.call(response) end end |
.sign_out(&block) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/project/strategies/devise_token_auth_gem.rb', line 56 def sign_out(&block) MotionKeychain.remove :auth_uid MotionKeychain.remove :auth_token MotionKeychain.remove :auth_client MotionKeychain.remove :current_user block.call end |
.sign_up(sign_up_url, params, &block) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/project/strategies/devise_token_auth_gem.rb', line 14 def sign_up(sign_up_url, params, &block) HTTP.post(sign_up_url, json: params) do |response| if response.success? store_auth_tokens(response.object, response.headers) end block.call(response) end end |
.signed_in? ⇒ Boolean
52 53 54 |
# File 'lib/project/strategies/devise_token_auth_gem.rb', line 52 def signed_in? !! MotionKeychain.get(:auth_token) end |
.store_auth_tokens(response, headers) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/project/strategies/devise_token_auth_gem.rb', line 23 def store_auth_tokens(response, headers) MotionKeychain.set :auth_uid, headers["uid"] MotionKeychain.set :auth_token, headers["access-token"] MotionKeychain.set :auth_client, headers["client"] serialized_response = "" response["data"].each do |key, value| case key when "assets" value.each do |eachasset| serialized_response << eachasset["name"] + "·" + eachasset["qty"].to_s + "," end else serialized_response << key + "·" + value.to_s + "," end end MotionKeychain.set :current_user, serialized_response end |