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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5173b53bdb3dee4b0ba2d5e7f4e44d437bcd3e4aa574573d8989b54a0dee945d
4
- data.tar.gz: c349e50c8b0319979fdd23279a051b7af238d09d44f4ce7a31f327f84146a915
3
+ metadata.gz: cede940ab1a8cb4dcf23bfef0f27135f108b06cd91c04a9f65a08b525581b369
4
+ data.tar.gz: bb24a581ed8195dea78d4497024665b93ae7e9e92654c6b199a157c9eb2967e0
5
5
  SHA512:
6
- metadata.gz: 16bcd457e52d08d65a6332c85bcb7106484ea33d3dfbd4b9964349f0ecfefe6781ea4840b21359845cbb8064b4670a80fc1e9f445743e77969abf13f539907ee
7
- data.tar.gz: e0cd0e369b2a39ee5661c31b4f7db8baf1c999c7ea7f168eefaa141bdcc5fce72cb3a1c9763df93bbb06ec2054ddd530779cae0bf9d306d1a4d5b510cb0dafc2
6
+ metadata.gz: acae84052ab448f7d874c14fc23adfc8116ceaed35c7f2f572ace7597ca675fd7e960128f7b2d51cc975690acec3c5b551e58b34aa57bf30bb8f7ba25a03c988
7
+ data.tar.gz: d5aa7e5f8ceea119e0721f909a73c1c13cd5d436e45ae357f70fba561b6eeb85f5907615eb21bf78fd39538da8f1cdb8f5d9580d80eb19787abb20947fb54a32
@@ -16,7 +16,7 @@ module Ibrain::Mutations
16
16
  private
17
17
 
18
18
  def normalize_parameters
19
- attribute_params.permit(:uid)
19
+ attribute_params.permit(:code, :redirect_uri)
20
20
  rescue StandardError
21
21
  ActionController::Parameters.new({})
22
22
  end
@@ -4,7 +4,8 @@ module Ibrain
4
4
  module Types
5
5
  module Input
6
6
  class GenerateFirebaseTokenInput < Ibrain::Types::BaseInputObject
7
- argument :uid, String, required: true
7
+ argument :code, String, required: true
8
+ argument :redirect_uri, String, required: true
8
9
  end
9
10
  end
10
11
  end
@@ -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: params[: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 < Ibrain::BaseRepository
4
- def initialize(record, params)
5
- super(nil, record)
3
+ class LineRepository
4
+ LINE_BASE_HEADERS = {
5
+ 'Content-Type': "application/x-www-form-urlencoded"
6
+ }.freeze
6
7
 
7
- @params = params
8
- @collection = Ibrain.user_class
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 find_or_initialize!
12
- user = @collection.find_by_line(uid: params['code'])
13
- return user if user.present?
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
- @collection.create_with_line!
44
+ response.try(:fetch, 'userId', nil)
16
45
  end
17
46
  end
@@ -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
@@ -11,4 +11,6 @@ ja:
11
11
  account:
12
12
  not_found: アカウントが見つかりません
13
13
  incorrect: ユーザー名またはパスワードが正しくありません!
14
- not_verified: ログインする前にアカウントを確認してください
14
+ not_verified: ログインする前にアカウントを確認してください
15
+ custom_token:
16
+ not_retrieve_uid: uid を取得できません
@@ -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
@@ -4,7 +4,7 @@ module Ibrain
4
4
  # frozen_string_literal: true
5
5
 
6
6
  module Auth
7
- VERSION = '0.3.14'
7
+ VERSION = '0.3.15'
8
8
 
9
9
  def self.ibrain_auth_version
10
10
  VERSION
@@ -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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibrain-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.14
4
+ version: 0.3.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tai Nguyen Van