ibrain-auth 0.3.14 → 0.3.16
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 +3 -1
- data/app/repositories/firebase_repository.rb +15 -1
- data/app/repositories/line_repository.rb +49 -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: 60a113e3b1a3c4a9d36537db0135bb75cdcfde931553aad2cfcaf5c6f61d2eb3
|
4
|
+
data.tar.gz: 047755a00465c7718633deee0ae819f13d7eb91cbb13ff8c63bb7615a16edfad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c65958057e091667cf5aff4c6fae97ab0d99d4a905817e16f3c0457b2795e08efb42e1622f752c431f4afb19a37856ca0ab93c66a0dea379b9505299daf7eae4
|
7
|
+
data.tar.gz: df1ed03ef6ed2ca98697df98c27ef82b0f9d7b464c189ca72d957cb40d635e0a181b583f77a61102a88ef439276b36287740ecd389228db8fc4e634fb30a2845
|
@@ -4,7 +4,9 @@ module Ibrain
|
|
4
4
|
module Types
|
5
5
|
module Input
|
6
6
|
class GenerateFirebaseTokenInput < Ibrain::Types::BaseInputObject
|
7
|
-
argument :
|
7
|
+
argument :code, String, required: false
|
8
|
+
argument :redirect_uri, String, required: false
|
9
|
+
argument :access_token, String, required: false
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
@@ -14,6 +14,9 @@ class FirebaseRepository < Ibrain::BaseRepository
|
|
14
14
|
def generate_custom_token!
|
15
15
|
iat = Time.now.to_i
|
16
16
|
exp = 60.minutes.from_now.to_i
|
17
|
+
uid = retrieve_uid_execution
|
18
|
+
|
19
|
+
raise IbrainErrors::UnknownError.new I18n.t("ibrain.errors.custom_token.not_retrieve_uid") unless uid
|
17
20
|
|
18
21
|
payload = {
|
19
22
|
iss: firebase_owner_email,
|
@@ -21,7 +24,7 @@ class FirebaseRepository < Ibrain::BaseRepository
|
|
21
24
|
aud: Ibrain::Auth::Config.firebase_auth_url,
|
22
25
|
iat: iat,
|
23
26
|
exp: exp,
|
24
|
-
uid:
|
27
|
+
uid: uid,
|
25
28
|
claims: {}
|
26
29
|
}
|
27
30
|
|
@@ -52,4 +55,15 @@ class FirebaseRepository < Ibrain::BaseRepository
|
|
52
55
|
|
53
56
|
File.open(Ibrain::Auth::Config.firebase_private_key_path).read
|
54
57
|
end
|
58
|
+
|
59
|
+
def retrieve_uid_execution
|
60
|
+
if params[:access_token].present?
|
61
|
+
return LineRepository.singleton.retrieve_uid_by_access_token(access_token: params[:access_token])
|
62
|
+
end
|
63
|
+
|
64
|
+
LineRepository.singleton.retrieve_uid(
|
65
|
+
code: params[:code],
|
66
|
+
redirect_uri: params[:redirect_uri]
|
67
|
+
)
|
68
|
+
end
|
55
69
|
end
|
@@ -1,17 +1,57 @@
|
|
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)
|
29
|
+
end
|
30
|
+
|
31
|
+
def retrieve_uid(redirect_uri:, code:)
|
32
|
+
token = retrieve_access_token(
|
33
|
+
redirect_uri: redirect_uri,
|
34
|
+
code: code
|
35
|
+
)
|
36
|
+
|
37
|
+
response = HTTParty.get(
|
38
|
+
LINE_INFORMATION_URL,
|
39
|
+
headers: LINE_BASE_HEADERS.merge({
|
40
|
+
'Authorization' => "Bearer #{token}"
|
41
|
+
})
|
42
|
+
)
|
43
|
+
|
44
|
+
response.try(:fetch, 'userId', nil)
|
9
45
|
end
|
10
46
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
47
|
+
def retrieve_uid_by_access_token(access_token:)
|
48
|
+
response = HTTParty.get(
|
49
|
+
LINE_INFORMATION_URL,
|
50
|
+
headers: LINE_BASE_HEADERS.merge({
|
51
|
+
'Authorization' => "Bearer #{access_token}"
|
52
|
+
})
|
53
|
+
)
|
14
54
|
|
15
|
-
|
55
|
+
response.try(:fetch, 'userId', nil)
|
16
56
|
end
|
17
57
|
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.16
|
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-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise
|