lol_auth 0.1.11 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3aaaa250f2e7c3e807e6d0c95ecedaa139240be735efda9a88a1065ca79161b1
4
- data.tar.gz: cea1792e29bcf9acf219b9678641403a894a2f0f3326912687b3a99c14324c32
3
+ metadata.gz: 352a007dc98b7d65e1ee01ac6644b7db8e6941e78260cbc5248e6722db3c7fb1
4
+ data.tar.gz: b61a73538a23be860870fb30ebc7995bfc41cc56b249cc51d098a480bb3af8c7
5
5
  SHA512:
6
- metadata.gz: 88d5778d02a9a1522b7c404ff2abe07097a10efd9f9c6ea9fcc31ff3eafcf5f74f655c14bda7fda826436e91ded0ea2c74428d85a3ee1f92d18cf0568820461b
7
- data.tar.gz: a504fa61aa7844e4d9a8429fd73f3d4a0764a668c2d12d37a47af1ccc1e02e5eb4d40a36b846ace77e52e4dedcd216653d36ebf7655f80104709b38126c90f31
6
+ metadata.gz: 3bf53fb2d6b62b4175c52b5ac6a381f5ea3e3af0f320b8f7287fc0c939099c5352dde3f32d59abcea1524725b0210d7bbd85f364d42736e1410ec9a8413d786e
7
+ data.tar.gz: c8a97df9c2779e08acb174d9957c943e5b4a33564d68091364f7514be2d7f4db9ec6ebd287c7f5808cdce453b44b9824fff3c1d1edaa6305355763c9c8a8720a
@@ -2,7 +2,7 @@ require_dependency "lol_auth/application_controller"
2
2
 
3
3
  module LolAuth
4
4
  class UsersController < ApplicationController
5
- skip_before_action :authenticate_api_v1_user!, only: [:facebook_signin, :apple_signin]
5
+ skip_before_action :authenticate_api_v1_user!, only: [:facebook_signin, :apple_signin, :google_signin]
6
6
 
7
7
  def facebook_signin
8
8
  @manager = Facebook::Login.new()
@@ -27,6 +27,18 @@ module LolAuth
27
27
 
28
28
  render :success, status: 201
29
29
  end
30
+
31
+ def google_signin
32
+ @manager = Google::Login.new(params)
33
+
34
+ @user = @manager.process()
35
+
36
+ sign_in(:user, @user, store: false, bypass: true)
37
+
38
+ response.headers.merge!(@manager.auth_header)
39
+
40
+ render :success, status: 201
41
+ end
30
42
  end
31
43
 
32
44
  def update_avatar
@@ -0,0 +1,44 @@
1
+ module Google
2
+ class Login
3
+ attr_accessor :auth_header
4
+
5
+ def initialize(options={})
6
+ @info = options[:resource]
7
+
8
+ @user_type = options[:user_type] || 'User'
9
+ end
10
+
11
+ def process
12
+ user = @user_type.constantize.find_or_create_by(uid: @info['user']['id']) do |user|
13
+ user.email = @info['user']['email']
14
+ user.password = build_pasword()
15
+ user.name = @info['user']['name']
16
+ user.remote_avatar_url = @info['user']['photo']
17
+ user.provider = :google
18
+ end
19
+
20
+ build_token(user)
21
+
22
+ user.reload
23
+ end
24
+
25
+ private
26
+ def build_pasword
27
+ Devise.friendly_token[0,20]
28
+ end
29
+
30
+ def build_token(user)
31
+ client_id = SecureRandom.urlsafe_base64(nil, false)
32
+ token = SecureRandom.urlsafe_base64(nil, false)
33
+
34
+ user.tokens[client_id] = {
35
+ token: BCrypt::Password.create(token),
36
+ expiry: (Time.now + DeviseTokenAuth.token_lifespan).to_i
37
+ }
38
+
39
+ user.save
40
+
41
+ @auth_header = user.create_new_auth_token(client_id)
42
+ end
43
+ end
44
+ end
data/config/routes.rb CHANGED
@@ -13,6 +13,8 @@ Rails.application.routes.draw do
13
13
  post '/users/facebook/signin', to: '/lol_auth/users#facebook_signin'
14
14
  # USER SIGNUP APPLE
15
15
  post '/users/apple/signin' , to: '/lol_auth/users#apple_signin'
16
+ # USER SIGNUP GOOGLE
17
+ post '/users/google/signin' , to: '/lol_auth/users#google_signin'
16
18
  end
17
19
  end
18
20
  end
@@ -1,3 +1,3 @@
1
1
  module LolAuth
2
- VERSION = '0.1.11'
2
+ VERSION = '0.1.12'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lol_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Zaghi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-16 00:00:00.000000000 Z
11
+ date: 2020-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -201,6 +201,7 @@ files:
201
201
  - app/managers/apple/login.rb
202
202
  - app/managers/facebook/base.rb
203
203
  - app/managers/facebook/login.rb
204
+ - app/managers/google/login.rb
204
205
  - app/managers/user_reset_password_manager.rb
205
206
  - app/models/lol_auth/application_record.rb
206
207
  - app/models/user.rb