lol_auth 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44f98b93a2ed22807c5f443c298b458dc5b190df1d313b753c6b9887ab300586
4
- data.tar.gz: 065c140969ab130ee254a759446c0cd9a167cf56f7ce97ccf31a7c26bb812ebd
3
+ metadata.gz: 3aaaa250f2e7c3e807e6d0c95ecedaa139240be735efda9a88a1065ca79161b1
4
+ data.tar.gz: cea1792e29bcf9acf219b9678641403a894a2f0f3326912687b3a99c14324c32
5
5
  SHA512:
6
- metadata.gz: 24806b2ab0c68da582354a4720619d769fdc511e9d055f22ff76637809d1a7d26f3c9214dc84de5e1df16e64101d8b48c2f9407c2f1a27eb2da5a46068787143
7
- data.tar.gz: efabe19996429337d0af2b8f67cc584668e8c0ddf22a9218348a15a39a98345e8953ee269c67317426ebedc21a9ff3c9c54a18c263d85e84f8a63369d3c478a7
6
+ metadata.gz: 88d5778d02a9a1522b7c404ff2abe07097a10efd9f9c6ea9fcc31ff3eafcf5f74f655c14bda7fda826436e91ded0ea2c74428d85a3ee1f92d18cf0568820461b
7
+ data.tar.gz: a504fa61aa7844e4d9a8429fd73f3d4a0764a668c2d12d37a47af1ccc1e02e5eb4d40a36b846ace77e52e4dedcd216653d36ebf7655f80104709b38126c90f31
@@ -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]
5
+ skip_before_action :authenticate_api_v1_user!, only: [:facebook_signin, :apple_signin]
6
6
 
7
7
  def facebook_signin
8
8
  @manager = Facebook::Login.new()
@@ -14,7 +14,19 @@ module LolAuth
14
14
  response.headers.merge!(@manager.auth_header)
15
15
 
16
16
  render :success, status: 201
17
- end
17
+ end
18
+
19
+ def apple_signin
20
+ @manager = Apple::Login.new(params)
21
+
22
+ @user = @manager.process()
23
+
24
+ sign_in(:user, @user, store: false, bypass: true)
25
+
26
+ response.headers.merge!(@manager.auth_header)
27
+
28
+ render :success, status: 201
29
+ end
18
30
  end
19
31
 
20
32
  def update_avatar
@@ -0,0 +1,43 @@
1
+ module Apple
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['email']) do |user|
13
+ user.email = @info['email']
14
+ user.password = build_pasword()
15
+ user.name = @info['name']
16
+ user.provider = :apple
17
+ end
18
+
19
+ build_token(user)
20
+
21
+ user.reload
22
+ end
23
+
24
+ private
25
+ def build_pasword
26
+ Devise.friendly_token[0,20]
27
+ end
28
+
29
+ def build_token(user)
30
+ client_id = SecureRandom.urlsafe_base64(nil, false)
31
+ token = SecureRandom.urlsafe_base64(nil, false)
32
+
33
+ user.tokens[client_id] = {
34
+ token: BCrypt::Password.create(token),
35
+ expiry: (Time.now + DeviseTokenAuth.token_lifespan).to_i
36
+ }
37
+
38
+ user.save
39
+
40
+ @auth_header = user.create_new_auth_token(client_id)
41
+ end
42
+ end
43
+ end
@@ -11,6 +11,8 @@ Rails.application.routes.draw do
11
11
 
12
12
  # USER SIGNUP FACEBOOK
13
13
  post '/users/facebook/signin', to: '/lol_auth/users#facebook_signin'
14
+ # USER SIGNUP APPLE
15
+ post '/users/apple/signin' , to: '/lol_auth/users#apple_signin'
14
16
  end
15
17
  end
16
18
  end
@@ -1,3 +1,3 @@
1
1
  module LolAuth
2
- VERSION = '0.1.10'
2
+ VERSION = '0.1.11'
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.10
4
+ version: 0.1.11
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-08-08 00:00:00.000000000 Z
11
+ date: 2019-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -198,6 +198,7 @@ files:
198
198
  - app/helpers/lol_auth/users_helper.rb
199
199
  - app/jobs/lol_auth/application_job.rb
200
200
  - app/mailers/lol_auth/application_mailer.rb
201
+ - app/managers/apple/login.rb
201
202
  - app/managers/facebook/base.rb
202
203
  - app/managers/facebook/login.rb
203
204
  - app/managers/user_reset_password_manager.rb