ibrain-auth 0.3.13 → 0.3.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/graphql/ibrain/mutations/generate_firebase_token_mutation.rb +1 -1
- data/app/graphql/ibrain/types/input/generate_firebase_token_input.rb +2 -1
- data/app/models/ibrain/user.rb +4 -0
- data/app/repositories/auth_repository.rb +3 -1
- data/app/repositories/firebase_repository.rb +12 -4
- data/app/repositories/line_repository.rb +37 -9
- data/config/locales/en.yml +3 -1
- data/config/locales/ja.yml +3 -1
- data/config/locales/vi.yml +3 -1
- data/lib/generators/ibrain/auth/install/templates/config/initializers/ibrain_auth.rb.tt +6 -0
- data/lib/ibrain/auth/version.rb +1 -1
- data/lib/ibrain/auth_configuration.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cede940ab1a8cb4dcf23bfef0f27135f108b06cd91c04a9f65a08b525581b369
|
4
|
+
data.tar.gz: bb24a581ed8195dea78d4497024665b93ae7e9e92654c6b199a157c9eb2967e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acae84052ab448f7d874c14fc23adfc8116ceaed35c7f2f572ace7597ca675fd7e960128f7b2d51cc975690acec3c5b551e58b34aa57bf30bb8f7ba25a03c988
|
7
|
+
data.tar.gz: d5aa7e5f8ceea119e0721f909a73c1c13cd5d436e45ae357f70fba561b6eeb85f5907615eb21bf78fd39538da8f1cdb8f5d9580d80eb19787abb20947fb54a32
|
data/app/models/ibrain/user.rb
CHANGED
@@ -68,6 +68,10 @@ module Ibrain
|
|
68
68
|
user.skip_confirmation! unless user&.confirmed?
|
69
69
|
user
|
70
70
|
end
|
71
|
+
|
72
|
+
def random_password
|
73
|
+
(('A'..'Z').to_a.sample(4) + ["~", "!", "@", "#", "$", "%", "^", "&", "*", "_", "-"].sample(1) + ('0'..'9').to_a.sample(2) + ('a'..'z').to_a.sample(4)).join
|
74
|
+
end
|
71
75
|
end
|
72
76
|
end
|
73
77
|
end
|
@@ -68,12 +68,14 @@ class AuthRepository < Ibrain::BaseRepository
|
|
68
68
|
try(:gsub, '.com', '')
|
69
69
|
raise ActionController::InvalidAuthenticityToken, I18n.t('ibrain.errors.account.not_found') if uid.blank?
|
70
70
|
|
71
|
+
provider = 'custom' if user_information.try(:fetch, 'customAuth', false) && provider.blank?
|
72
|
+
|
71
73
|
collection.social_find_or_initialize({
|
72
74
|
uid: uid,
|
73
75
|
provider: provider,
|
74
76
|
remote_avatar_url: user_information.try(:fetch, 'photoUrl', nil),
|
75
77
|
email: user_information.try(:fetch, 'email', nil),
|
76
|
-
password:
|
78
|
+
password: collection.random_password
|
77
79
|
})
|
78
80
|
end
|
79
81
|
|
@@ -12,15 +12,23 @@ class FirebaseRepository < Ibrain::BaseRepository
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def generate_custom_token!
|
15
|
-
|
15
|
+
iat = Time.now.to_i
|
16
|
+
exp = 60.minutes.from_now.to_i
|
17
|
+
|
18
|
+
uid = LineRepository.singleton.retrieve_uid(
|
19
|
+
code: params[:code],
|
20
|
+
redirect_uri: params[:redirect_uri]
|
21
|
+
)
|
22
|
+
|
23
|
+
raise IbrainErrors::UnknownError.new I18n.t("ibrain.errors.custom_token.not_retrieve_uid") unless uid
|
16
24
|
|
17
25
|
payload = {
|
18
26
|
iss: firebase_owner_email,
|
19
27
|
sub: firebase_owner_email,
|
20
28
|
aud: Ibrain::Auth::Config.firebase_auth_url,
|
21
|
-
iat:
|
22
|
-
exp:
|
23
|
-
uid:
|
29
|
+
iat: iat,
|
30
|
+
exp: exp,
|
31
|
+
uid: uid,
|
24
32
|
claims: {}
|
25
33
|
}
|
26
34
|
|
@@ -1,18 +1,46 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class LineRepository
|
4
|
-
|
5
|
-
|
3
|
+
class LineRepository
|
4
|
+
LINE_BASE_HEADERS = {
|
5
|
+
'Content-Type': "application/x-www-form-urlencoded"
|
6
|
+
}.freeze
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
LINE_TOKEN_URL = "https://api.line.me/oauth2/v2.1/token"
|
9
|
+
LINE_INFORMATION_URL = "https://api.line.me/v2/profile"
|
10
|
+
|
11
|
+
def self.singleton
|
12
|
+
@singleton ||= new
|
13
|
+
end
|
14
|
+
|
15
|
+
def retrieve_access_token(redirect_uri:, code:)
|
16
|
+
response = HTTParty.post(
|
17
|
+
LINE_TOKEN_URL,
|
18
|
+
headers: LINE_BASE_HEADERS,
|
19
|
+
body: URI.encode_www_form({
|
20
|
+
grant_type: "authorization_code",
|
21
|
+
code: code,
|
22
|
+
redirect_uri: redirect_uri,
|
23
|
+
client_id: Ibrain::Auth::Config.line_client_id,
|
24
|
+
client_secret: Ibrain::Auth::Config.line_client_secret
|
25
|
+
})
|
26
|
+
)
|
27
|
+
|
28
|
+
response.try(:fetch, "access_token", nil)
|
9
29
|
end
|
10
30
|
|
11
|
-
def
|
12
|
-
|
31
|
+
def retrieve_uid(redirect_uri:, code:)
|
32
|
+
token = retrieve_access_token(
|
33
|
+
redirect_uri: redirect_uri,
|
34
|
+
code: code
|
35
|
+
)
|
13
36
|
|
14
|
-
|
37
|
+
response = HTTParty.get(
|
38
|
+
LINE_INFORMATION_URL,
|
39
|
+
headers: LINE_BASE_HEADERS.merge({
|
40
|
+
'Authorization' => "Bearer #{token}"
|
41
|
+
})
|
42
|
+
)
|
15
43
|
|
16
|
-
|
44
|
+
response.try(:fetch, 'userId', nil)
|
17
45
|
end
|
18
46
|
end
|
data/config/locales/en.yml
CHANGED
@@ -11,4 +11,6 @@ en:
|
|
11
11
|
account:
|
12
12
|
not_found: Account not found
|
13
13
|
incorrect: Username or Password is incorrect!
|
14
|
-
not_verified: Please verify your account before login
|
14
|
+
not_verified: Please verify your account before login
|
15
|
+
custom_token:
|
16
|
+
not_retrieve_uid: Can not retrieve uid
|
data/config/locales/ja.yml
CHANGED
data/config/locales/vi.yml
CHANGED
@@ -11,4 +11,6 @@ vi:
|
|
11
11
|
account:
|
12
12
|
not_found: Không tìm thấy tài khoản
|
13
13
|
incorrect: Tài khoản hoặc mật khẩu không chính xác!
|
14
|
-
not_verified: Vui lòng xác minh tài khoản của bạn trước khi đăng nhập
|
14
|
+
not_verified: Vui lòng xác minh tài khoản của bạn trước khi đăng nhập
|
15
|
+
custom_token:
|
16
|
+
not_retrieve_uid: Lấy thông tin uid của người dùng thất bại
|
@@ -34,4 +34,10 @@ Ibrain::Auth.config do |config|
|
|
34
34
|
|
35
35
|
# devise social providers setting
|
36
36
|
config.devise_omniauth_providers = %i[apple facebook twitter line]
|
37
|
+
|
38
|
+
# line client id
|
39
|
+
config.line_client_id = nil
|
40
|
+
|
41
|
+
# line client secret
|
42
|
+
config.line_client_secret = nil
|
37
43
|
end
|
data/lib/ibrain/auth/version.rb
CHANGED
@@ -35,5 +35,11 @@ module Ibrain
|
|
35
35
|
|
36
36
|
# devise social providers setting
|
37
37
|
preference :devise_omniauth_providers, :array, default: %i[apple facebook twitter line]
|
38
|
+
|
39
|
+
# line client id
|
40
|
+
preference :line_client_id, :string, default: nil
|
41
|
+
|
42
|
+
# line client secret
|
43
|
+
preference :line_client_secret, :string, default: nil
|
38
44
|
end
|
39
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ibrain-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tai Nguyen Van
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise
|