omniauth-parallelmarkets 0.4.2 → 0.5.0

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: bf94329fc1db02d346d0d7befbb29fac39e51d30ec66e9a4a8b538951d3c7ec7
4
- data.tar.gz: f71b522a1fcf3aee5585575e8446ad97b1d91c0b8bf4dc3f0967fd27a8023bc0
3
+ metadata.gz: 116a4e6f6b528976b72de3ea0fe9b1fbdb49789abf02fe1ec140596554cedbb9
4
+ data.tar.gz: a609f558e13b46498bbe870c94873846a13a33a012700d78c261c76826995aa7
5
5
  SHA512:
6
- metadata.gz: 3e2f2d1096227455fb66d03fa9d6896328113f0ba72b81c269bf771a4d4ad51066ab56cee1395584caa256046bce3b8cb5acd5116f94428f26d15c23dbb53d7b
7
- data.tar.gz: 3297663cf3ca60172a2aa44889a546116c6ac5a89cf6132366d1dab693b65cb698abdefcb868831e08eed8c8f90b8e659eca164c002f47fe7a3c55eebb7b25c8
6
+ metadata.gz: cd138b8aab041a68b18601f66602b5b5753f5f7b820c1def738a024da32471ab72d81711a18ce53d64e4bc421e52d8d1e2d5e4167d52071551f4463d08aa3bb1
7
+ data.tar.gz: 5487cb23b4ba7b1e4213634ac645b3525f894dfe4e693c7cb9414448d892a6cf400d5f9968db5c48c7b435723635b2691b49ee0347db7110c56694d38094ebba
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAuth
4
4
  module ParallelMarkets
5
- VERSION = '0.4.2'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
@@ -13,29 +13,22 @@ module OmniAuth
13
13
 
14
14
  uid { raw_info['id'] }
15
15
 
16
- info do
17
- {
18
- name: profile['name'] || "#{profile['first_name']} #{profile['last_name']}",
19
- first_name: profile['first_name'],
20
- last_name: profile['last_name'],
21
- email: profile['email']
22
- }
23
- end
16
+ info { to_contact_details(profile) }
24
17
 
25
18
  extra do
26
19
  {
27
- accreditations: accreditations,
28
- indicated_unaccredited: indicated_unaccredited,
20
+ authorize_scopes: authorize_scopes,
21
+ # from /api/v1/me
29
22
  business_type: profile['business_type'],
30
- primary_contact: profile['primary_contact'].nil? ? nil : {
31
- name: "#{profile['primary_contact']['first_name']} #{profile['primary_contact']['last_name']}",
32
- first_name: profile['primary_contact']['first_name'],
33
- last_name: profile['primary_contact']['last_name'],
34
- email: profile['primary_contact']['email']
35
- },
23
+ primary_contact: to_contact_details(profile['primary_contact']),
24
+ raw_info: raw_info,
36
25
  type: raw_info['type'],
37
26
  user_id: raw_info['user_id'],
38
- raw_info: raw_info
27
+ user_profile: to_contact_details(user_profile),
28
+ user_providing_for: raw_info['user_providing_for'],
29
+ # from /api/v1/accreditations
30
+ accreditations: accreditations,
31
+ indicated_unaccredited: raw_accreditations['indicated_unaccredited']
39
32
  }
40
33
  end
41
34
 
@@ -52,24 +45,42 @@ module OmniAuth
52
45
  options[:redirect_uri] || (full_host + script_name + callback_path)
53
46
  end
54
47
 
48
+ def scope?(single_scope)
49
+ authorize_scopes.include?(single_scope.to_s)
50
+ end
51
+
52
+ # if given ?scope query parameter, use that. otherwise, use server-side provider configuration
53
+ def authorize_scopes
54
+ @authorize_scopes ||= (env['omniauth.params']['scope'] || authorize_params['scope']).split(' ')
55
+ end
56
+
55
57
  def raw_info
56
- @raw_info ||= access_token.get('/v1/me').parsed
58
+ @raw_info ||= scope?(:profile) ? access_token.get('/v1/me').parsed : {}
57
59
  end
58
60
 
59
61
  def profile
60
62
  @profile ||= raw_info.fetch('profile', {})
61
63
  end
62
64
 
63
- def raw_accreditations
64
- @raw_accreditations ||= access_token.get('/v1/accreditations').parsed
65
+ def user_profile
66
+ @user_profile ||= raw_info.fetch('user_profile', {})
65
67
  end
66
68
 
67
- def indicated_unaccredited
68
- raw_accreditations['indicated_unaccredited']
69
+ def raw_accreditations
70
+ @raw_accreditations ||= scope?(:accreditation_status) ? access_token.get('/v1/accreditations').parsed : {}
69
71
  end
70
72
 
71
73
  def accreditations
72
- raw_accreditations['accreditations']
74
+ @accreditations ||= raw_accreditations.fetch('accreditations', [])
75
+ end
76
+
77
+ def to_contact_details(contact)
78
+ (contact.nil? || contact.empty?) ? {} : {
79
+ name: contact['name'] || "#{contact['first_name']} #{contact['last_name']}",
80
+ first_name: contact['first_name'],
81
+ last_name: contact['last_name'],
82
+ email: contact['email']
83
+ }
73
84
  end
74
85
  end
75
86
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-parallelmarkets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Muller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-10 00:00:00.000000000 Z
11
+ date: 2021-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-oauth2
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  requirements: []
92
- rubygems_version: 3.2.15
92
+ rubygems_version: 3.1.2
93
93
  signing_key:
94
94
  specification_version: 4
95
95
  summary: Parallel Markets OAuth strategy for OmniAuth