workos 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8a9f985318b4480c50a4d0528cf5036018235833585746e3ed632020fca3d00
4
- data.tar.gz: bc75b64c4a4ffa8b32ee2b841af1c6bdb39df729bda95cc59d9ad36206cab387
3
+ metadata.gz: 7d48c12ff6a0a470ca2a35fb76cabf17fe9d4f2444b11811891a9ea0c81f9cda
4
+ data.tar.gz: ec43b59ca57135efd145346ce14ebab1ed30341f210b3a47f8525afb907d3856
5
5
  SHA512:
6
- metadata.gz: 56d3896fd8bb4194cbb50464759c9babfe2421e56148827fe282af956fa4fb9f38eb308363e30427bed0ef3596e5c1ba99150f108208835ecdb40921e99bf67e
7
- data.tar.gz: e5f09155ab5a7e92dc0ccd6a10af885d5802925a7db1fdaf21cbeb9902b231642284ed06aa1ce0806271fceab5f42209d1c3c1c5442c6ea42a780a6264670ce4
6
+ metadata.gz: 2068f4bd90b52d90b802eea6f1e8ebeb2a5e1b166d5256d952df40af30821bd858999813532f18e9ab44eff36f4cde40a27f423126028509fe9c12f15ef07d58
7
+ data.tar.gz: 526f33fd44a2371696dc19f400461af7e170e362d7057bf04529767eae8692d12b8e56635f6b61d5b0e8c585f2275e65e62422f064bbe056645c2c0cc1cfe14f
data/.rubocop.yml CHANGED
@@ -20,3 +20,5 @@ Style/TrailingCommaInArguments:
20
20
  EnforcedStyleForMultiline: 'consistent_comma'
21
21
  Style/TrailingCommaInHashLiteral:
22
22
  EnforcedStyleForMultiline: 'consistent_comma'
23
+ AllCops:
24
+ TargetRubyVersion: 2.5
@@ -33,13 +33,13 @@ blocks:
33
33
  - name: Ruby 1.9.3
34
34
  commands:
35
35
  - checkout
36
- - sem-version ruby 1.9.3
36
+ - sem-version ruby 1.9.3-p551
37
37
  - bundle install
38
38
  - bundle exec rspec
39
39
  - name: Ruby 2.0.0
40
40
  commands:
41
41
  - checkout
42
- - sem-version ruby 2.0.0
42
+ - sem-version ruby 2.0.0-p648
43
43
  - bundle install
44
44
  - bundle exec rspec
45
45
  - name: Ruby 2.3.4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- workos (1.0.0)
4
+ workos (1.1.0)
5
5
  sorbet-runtime (~> 0.5)
6
6
 
7
7
  GEM
@@ -60,7 +60,7 @@ GEM
60
60
  simplecov_json_formatter (0.1.2)
61
61
  sorbet (0.5.6388)
62
62
  sorbet-static (= 0.5.6388)
63
- sorbet-runtime (0.5.6403)
63
+ sorbet-runtime (0.5.6424)
64
64
  sorbet-static (0.5.6388-universal-darwin-14)
65
65
  sorbet-static (0.5.6388-universal-darwin-15)
66
66
  sorbet-static (0.5.6388-universal-darwin-16)
data/lib/workos/client.rb CHANGED
@@ -36,9 +36,10 @@ module WorkOS
36
36
  path: String,
37
37
  auth: T.nilable(T::Boolean),
38
38
  params: T.nilable(Hash),
39
+ access_token: T.nilable(String),
39
40
  ).returns(Net::HTTP::Get)
40
41
  end
41
- def get_request(path:, auth: false, params: {})
42
+ def get_request(path:, auth: false, params: {}, access_token: nil)
42
43
  uri = URI(path)
43
44
  uri.query = URI.encode_www_form(params) if params
44
45
 
@@ -47,7 +48,7 @@ module WorkOS
47
48
  'Content-Type' => 'application/json',
48
49
  )
49
50
 
50
- request['Authorization'] = "Bearer #{WorkOS.key!}" if auth
51
+ request['Authorization'] = "Bearer #{access_token || WorkOS.key!}}" if auth
51
52
  request['User-Agent'] = user_agent
52
53
  request
53
54
  end
@@ -48,22 +48,20 @@ module WorkOS
48
48
 
49
49
  private
50
50
 
51
- # rubocop:disable Metrics/AbcSize
52
51
  sig { params(json_string: String).returns(WorkOS::Types::ProfileStruct) }
53
52
  def parse_json(json_string)
54
53
  hash = JSON.parse(json_string, symbolize_names: true)
55
54
 
56
55
  WorkOS::Types::ProfileStruct.new(
57
- id: hash[:profile][:id],
58
- email: hash[:profile][:email],
59
- first_name: hash[:profile][:first_name],
60
- last_name: hash[:profile][:last_name],
61
- connection_id: hash[:profile][:connection_id],
62
- connection_type: hash[:profile][:connection_type],
63
- idp_id: hash[:profile][:idp_id],
64
- raw_attributes: hash[:profile][:raw_attributes],
56
+ id: hash[:id],
57
+ email: hash[:email],
58
+ first_name: hash[:first_name],
59
+ last_name: hash[:last_name],
60
+ connection_id: hash[:connection_id],
61
+ connection_type: hash[:connection_type],
62
+ idp_id: hash[:idp_id],
63
+ raw_attributes: hash[:raw_attributes],
65
64
  )
66
65
  end
67
- # rubocop:enable Metrics/AbcSize
68
66
  end
69
67
  end
@@ -15,7 +15,7 @@ module WorkOS
15
15
  json = JSON.parse(profile_and_token_json, symbolize_names: true)
16
16
 
17
17
  @access_token = T.let(json[:access_token], String)
18
- @profile = WorkOS::Profile.new(profile_and_token_json)
18
+ @profile = WorkOS::Profile.new(json[:profile].to_json)
19
19
  end
20
20
 
21
21
  def to_json(*)
data/lib/workos/sso.rb CHANGED
@@ -88,6 +88,23 @@ module WorkOS
88
88
  "https://#{WorkOS::API_HOSTNAME}/sso/authorize?#{query}"
89
89
  end
90
90
 
91
+ sig do
92
+ params(
93
+ access_token: String,
94
+ ).returns(WorkOS::Profile)
95
+ end
96
+ def get_profile(access_token:)
97
+ response = execute_request(
98
+ request: get_request(
99
+ path: '/sso/profile',
100
+ auth: true,
101
+ access_token: access_token,
102
+ ),
103
+ )
104
+
105
+ WorkOS::Profile.new(response.body)
106
+ end
107
+
91
108
  # Fetch the profile details for the authenticated SSO user.
92
109
  #
93
110
  # @param [String] code The authorization code provided in the callback URL
@@ -2,5 +2,5 @@
2
2
  # typed: strong
3
3
 
4
4
  module WorkOS
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.0'
6
6
  end
@@ -149,6 +149,37 @@ describe WorkOS::SSO do
149
149
  end
150
150
  end
151
151
 
152
+ describe '.get_profile' do
153
+ it 'returns a profile' do
154
+ VCR.use_cassette 'sso/profile' do
155
+ profile = described_class.get_profile(access_token: 'access_token')
156
+
157
+ expectation = {
158
+ connection_id: 'conn_01E83FVYZHY7DM4S9503JHV0R5',
159
+ connection_type: 'GoogleOAuth',
160
+ email: 'bob.loblaw@workos.com',
161
+ first_name: 'Bob',
162
+ id: 'prof_01EEJTY9SZ1R350RB7B73SNBKF',
163
+ idp_id: '116485463307139932699',
164
+ last_name: 'Loblaw',
165
+ raw_attributes: {
166
+ email: 'bob.loblaw@workos.com',
167
+ family_name: 'Loblaw',
168
+ given_name: 'Bob',
169
+ hd: 'workos.com',
170
+ id: '116485463307139932699',
171
+ locale: 'en',
172
+ name: 'Bob Loblaw',
173
+ picture: 'https://lh3.googleusercontent.com/a-/AOh14GyO2hLlgZvteDQ3Ldi3_-RteZLya0hWH7247Cam=s96-c',
174
+ verified_email: true,
175
+ },
176
+ }
177
+
178
+ expect(profile.to_json).to eq(expectation)
179
+ end
180
+ end
181
+ end
182
+
152
183
  describe '.profile_and_token' do
153
184
  let(:args) do
154
185
  {
@@ -0,0 +1,74 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.workos.com/sso/profile
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ""
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ User-Agent:
17
+ - WorkOS; ruby/3.0.1; arm64-darwin20; v1.0.0
18
+ Authorization:
19
+ - Bearer access_token
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - Cowboy
27
+ Connection:
28
+ - keep-alive
29
+ Vary:
30
+ - Origin, Accept-Encoding
31
+ Access-Control-Allow-Credentials:
32
+ - "true"
33
+ Content-Security-Policy:
34
+ - "default-src 'self';base-uri 'self';block-all-mixed-content;font-src 'self'
35
+ https: data:;frame-ancestors 'self';img-src 'self' data:;object-src 'none';script-src
36
+ 'self';script-src-attr 'none';style-src 'self' https: 'unsafe-inline';upgrade-insecure-requests"
37
+ X-Dns-Prefetch-Control:
38
+ - "off"
39
+ Expect-Ct:
40
+ - max-age=0
41
+ X-Frame-Options:
42
+ - SAMEORIGIN
43
+ Strict-Transport-Security:
44
+ - max-age=15552000; includeSubDomains
45
+ X-Download-Options:
46
+ - noopen
47
+ X-Content-Type-Options:
48
+ - nosniff
49
+ X-Permitted-Cross-Domain-Policies:
50
+ - none
51
+ Referrer-Policy:
52
+ - no-referrer
53
+ X-Xss-Protection:
54
+ - "0"
55
+ X-Request-Id:
56
+ - 45f253d6-51bb-4171-879a-d532f0275044
57
+ Content-Type:
58
+ - application/json; charset=utf-8
59
+ Content-Length:
60
+ - "545"
61
+ Etag:
62
+ - W/"221-LoXMZbv3vrn7lnJvNn6G/pqr7+c"
63
+ Date:
64
+ - Tue, 18 May 2021 22:55:21 GMT
65
+ Via:
66
+ - 1.1 vegur
67
+ body:
68
+ encoding: UTF-8
69
+ string:
70
+ '{"object":"profile","id":"prof_01EEJTY9SZ1R350RB7B73SNBKF","connection_id":"conn_01E83FVYZHY7DM4S9503JHV0R5","connection_type":"GoogleOAuth","idp_id":"116485463307139932699","email":"bob.loblaw@workos.com","first_name":"Bob","last_name":"Loblaw","raw_attributes":{"hd":"workos.com","id":"116485463307139932699","name":"Bob
71
+ Loblaw","email":"bob.loblaw@workos.com","locale":"en","picture":"https://lh3.googleusercontent.com/a-/AOh14GyO2hLlgZvteDQ3Ldi3_-RteZLya0hWH7247Cam=s96-c","given_name":"Bob","family_name":"Loblaw","verified_email":true}}'
72
+ http_version:
73
+ recorded_at: Tue, 18 May 2021 22:55:21 GMT
74
+ recorded_with: VCR 5.0.0
data/workos.gemspec CHANGED
@@ -34,5 +34,5 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency 'webmock'
35
35
  spec.add_development_dependency 'yard'
36
36
 
37
- spec.required_ruby_version = '~> 3.0'
37
+ spec.required_ruby_version = '>= 2.5'
38
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workos
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - WorkOS
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-12 00:00:00.000000000 Z
11
+ date: 2021-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sorbet-runtime
@@ -332,6 +332,7 @@ files:
332
332
  - spec/support/fixtures/vcr_cassettes/sso/list_connections/with_limit.yml
333
333
  - spec/support/fixtures/vcr_cassettes/sso/list_connections/with_no_options.yml
334
334
  - spec/support/fixtures/vcr_cassettes/sso/list_connections/with_organization_id.yml
335
+ - spec/support/fixtures/vcr_cassettes/sso/profile.yml
335
336
  - spec/support/profile.txt
336
337
  - workos.gemspec
337
338
  homepage: https://github.com/workos-inc/workos-ruby
@@ -345,9 +346,9 @@ require_paths:
345
346
  - lib
346
347
  required_ruby_version: !ruby/object:Gem::Requirement
347
348
  requirements:
348
- - - "~>"
349
+ - - ">="
349
350
  - !ruby/object:Gem::Version
350
- version: '3.0'
351
+ version: '2.5'
351
352
  required_rubygems_version: !ruby/object:Gem::Requirement
352
353
  requirements:
353
354
  - - ">="
@@ -422,4 +423,5 @@ test_files:
422
423
  - spec/support/fixtures/vcr_cassettes/sso/list_connections/with_limit.yml
423
424
  - spec/support/fixtures/vcr_cassettes/sso/list_connections/with_no_options.yml
424
425
  - spec/support/fixtures/vcr_cassettes/sso/list_connections/with_organization_id.yml
426
+ - spec/support/fixtures/vcr_cassettes/sso/profile.yml
425
427
  - spec/support/profile.txt