ibrain-auth 0.3.14 → 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/repositories/firebase_repository.rb +8 -1
- data/app/repositories/line_repository.rb +38 -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 +1 -1
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
|
@@ -15,13 +15,20 @@ class FirebaseRepository < Ibrain::BaseRepository
|
|
15
15
|
iat = Time.now.to_i
|
16
16
|
exp = 60.minutes.from_now.to_i
|
17
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
|
24
|
+
|
18
25
|
payload = {
|
19
26
|
iss: firebase_owner_email,
|
20
27
|
sub: firebase_owner_email,
|
21
28
|
aud: Ibrain::Auth::Config.firebase_auth_url,
|
22
29
|
iat: iat,
|
23
30
|
exp: exp,
|
24
|
-
uid:
|
31
|
+
uid: uid,
|
25
32
|
claims: {}
|
26
33
|
}
|
27
34
|
|
@@ -1,17 +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
|
9
13
|
end
|
10
14
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
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
|
+
)
|
14
43
|
|
15
|
-
|
44
|
+
response.try(:fetch, 'userId', nil)
|
16
45
|
end
|
17
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
|