workos 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/.ruby-version +1 -1
- data/.semaphore/semaphore.yml +13 -6
- data/Gemfile.lock +6 -6
- data/lib/workos.rb +1 -0
- data/lib/workos/audit_trail.rb +0 -16
- data/lib/workos/client.rb +43 -4
- data/lib/workos/connection.rb +48 -0
- data/lib/workos/profile.rb +6 -7
- data/lib/workos/sso.rb +45 -32
- data/lib/workos/types.rb +2 -2
- data/lib/workos/types/connection_struct.rb +15 -0
- data/lib/workos/types/profile_struct.rb +0 -1
- data/lib/workos/types/provider_enum.rb +0 -1
- data/lib/workos/version.rb +1 -1
- data/sorbet/rbi/hidden-definitions/errors.txt +1416 -321
- data/sorbet/rbi/hidden-definitions/hidden.rbi +2490 -597
- data/sorbet/rbi/sorbet-typed/lib/rainbow/all/rainbow.rbi +36 -14
- data/sorbet/rbi/todo.rbi +1 -6
- data/spec/lib/workos/sso_spec.rb +46 -0
- data/spec/support/fixtures/vcr_cassettes/sso/create_connection_with_invalid_source.yml +58 -0
- data/spec/support/fixtures/vcr_cassettes/sso/create_connection_with_valid_source.yml +63 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06fb7835303dcd8aa08c89cdd04c24c59f0d649b7e21d7dfd6ae82cc57529304
|
4
|
+
data.tar.gz: 62bfacb18255d7c177c611c7dda0dd2a459610cdd1e0a0c48bbe3800a750ed64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd38c198e15b8c0f9f804593aba4eebe23ccad4c3be119c3d75861f0f38769fa13bccf204ad1085f74a32d448877e172eac4f45132fae8e4a793d699e0e78327
|
7
|
+
data.tar.gz: de1017c20f88ad1ba4d74cb51e98a6f234e692564ef073ceaeaae893cdc3b70c2af9bce74d74264fe0461d21ce0757fc8e6548143de33a54a1dc9f08f8a91eab
|
data/.rubocop.yml
CHANGED
@@ -10,6 +10,8 @@ Layout/LineLength:
|
|
10
10
|
- '(\A|\s)/.*?/'
|
11
11
|
Metrics/BlockLength:
|
12
12
|
ExcludedMethods: ['describe', 'context']
|
13
|
+
Metrics/ModuleLength:
|
14
|
+
Max: 150
|
13
15
|
Style/TrailingCommaInArguments:
|
14
16
|
EnforcedStyleForMultiline: 'consistent_comma'
|
15
17
|
Style/TrailingCommaInHashLiteral:
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.7.1
|
data/.semaphore/semaphore.yml
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
version: v1.0
|
2
2
|
name: Ruby
|
3
|
+
|
3
4
|
agent:
|
4
5
|
machine:
|
5
6
|
type: e1-standard-2
|
6
7
|
os_image: ubuntu1804
|
8
|
+
|
7
9
|
blocks:
|
8
10
|
- name: Run Sorbet 🍦
|
9
11
|
task:
|
@@ -11,19 +13,18 @@ blocks:
|
|
11
13
|
- name: srb tc
|
12
14
|
commands:
|
13
15
|
- checkout
|
14
|
-
- sem-version ruby 2.6.5
|
15
|
-
- gem install bundler
|
16
16
|
- bundle install
|
17
17
|
- bundle exec srb tc
|
18
|
+
|
18
19
|
- name: Run Rubocop 🚔
|
19
20
|
task:
|
20
21
|
jobs:
|
21
22
|
- name: rubocop
|
22
23
|
commands:
|
23
24
|
- checkout
|
24
|
-
- sem-version ruby 2.6.5
|
25
25
|
- bundle install
|
26
26
|
- bundle exec rubocop
|
27
|
+
|
27
28
|
- name: Run Tests 👩🏽🔬
|
28
29
|
task:
|
29
30
|
secrets:
|
@@ -40,7 +41,7 @@ blocks:
|
|
40
41
|
- checkout
|
41
42
|
- sem-version ruby 2.0.0
|
42
43
|
- bundle install
|
43
|
-
- bundle exec rspec
|
44
|
+
- bundle exec rspec
|
44
45
|
- name: Ruby 2.3.4
|
45
46
|
commands:
|
46
47
|
- checkout
|
@@ -58,7 +59,13 @@ blocks:
|
|
58
59
|
- checkout
|
59
60
|
- sem-version ruby 2.6.5
|
60
61
|
- bundle install
|
61
|
-
- bundle exec rspec
|
62
|
+
- bundle exec rspec
|
63
|
+
- name: Ruby 2.7.1
|
64
|
+
commands:
|
65
|
+
- checkout
|
66
|
+
- sem-version ruby 2.7.1
|
67
|
+
- bundle install
|
68
|
+
- bundle exec rspec
|
62
69
|
promotions:
|
63
70
|
- name: Deploy workos-rb to rubygems
|
64
|
-
pipeline_file: rubygems.yml
|
71
|
+
pipeline_file: rubygems.yml
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
workos (0.2.
|
4
|
+
workos (0.2.3)
|
5
5
|
sorbet-runtime (~> 0.5)
|
6
6
|
|
7
7
|
GEM
|
@@ -54,10 +54,10 @@ GEM
|
|
54
54
|
json (>= 1.8, < 3)
|
55
55
|
simplecov-html (~> 0.10.0)
|
56
56
|
simplecov-html (0.10.2)
|
57
|
-
sorbet (0.5.
|
58
|
-
sorbet-static (= 0.5.
|
59
|
-
sorbet-runtime (0.5.
|
60
|
-
sorbet-static (0.5.
|
57
|
+
sorbet (0.5.5560)
|
58
|
+
sorbet-static (= 0.5.5560)
|
59
|
+
sorbet-runtime (0.5.5560)
|
60
|
+
sorbet-static (0.5.5560-universal-darwin-14)
|
61
61
|
unicode-display_width (1.6.0)
|
62
62
|
url (0.3.2)
|
63
63
|
vcr (5.0.0)
|
@@ -83,4 +83,4 @@ DEPENDENCIES
|
|
83
83
|
yard
|
84
84
|
|
85
85
|
BUNDLED WITH
|
86
|
-
2.1.
|
86
|
+
2.1.4
|
data/lib/workos.rb
CHANGED
data/lib/workos/audit_trail.rb
CHANGED
@@ -57,22 +57,6 @@ module WorkOS
|
|
57
57
|
|
58
58
|
execute_request(request: request)
|
59
59
|
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
sig do
|
64
|
-
params(
|
65
|
-
path: String,
|
66
|
-
idempotency_key: T.nilable(String),
|
67
|
-
body: T.nilable(Hash),
|
68
|
-
).returns(Net::HTTP::Post)
|
69
|
-
end
|
70
|
-
def post_request(path:, idempotency_key: nil, body: nil)
|
71
|
-
request = super(path: path, body: body)
|
72
|
-
request['Authorization'] = "Bearer #{WorkOS.key}"
|
73
|
-
request['Idempotency-Key'] = idempotency_key if idempotency_key
|
74
|
-
request
|
75
|
-
end
|
76
60
|
end
|
77
61
|
end
|
78
62
|
end
|
data/lib/workos/client.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
# typed: true
|
3
3
|
|
4
|
-
|
5
4
|
module WorkOS
|
6
5
|
# A Net::HTTP based API client for interacting with the WorkOS API
|
7
6
|
module Client
|
@@ -18,7 +17,11 @@ module WorkOS
|
|
18
17
|
@client
|
19
18
|
end
|
20
19
|
|
21
|
-
sig
|
20
|
+
sig do
|
21
|
+
params(
|
22
|
+
request: T.any(Net::HTTP::Get, Net::HTTP::Post),
|
23
|
+
).returns(::T.untyped)
|
24
|
+
end
|
22
25
|
def execute_request(request:)
|
23
26
|
response = client.request(request)
|
24
27
|
|
@@ -28,10 +31,40 @@ module WorkOS
|
|
28
31
|
response
|
29
32
|
end
|
30
33
|
|
31
|
-
sig
|
32
|
-
|
34
|
+
sig do
|
35
|
+
params(
|
36
|
+
path: String,
|
37
|
+
auth: T.nilable(T::Boolean),
|
38
|
+
params: T.nilable(Hash),
|
39
|
+
).returns(Net::HTTP::Get)
|
40
|
+
end
|
41
|
+
def get_request(path:, auth: false, params: {})
|
42
|
+
uri = URI(path)
|
43
|
+
uri.query = URI.encode_www_form(params) if params
|
44
|
+
|
45
|
+
request = Net::HTTP::Get.new(
|
46
|
+
uri.to_s,
|
47
|
+
'Content-Type' => 'application/json',
|
48
|
+
)
|
49
|
+
|
50
|
+
request['Authorization'] = "Bearer #{WorkOS.key!}" if auth
|
51
|
+
request['User-Agent'] = user_agent
|
52
|
+
request
|
53
|
+
end
|
54
|
+
|
55
|
+
sig do
|
56
|
+
params(
|
57
|
+
path: String,
|
58
|
+
auth: T.nilable(T::Boolean),
|
59
|
+
idempotency_key: T.nilable(String),
|
60
|
+
body: T.nilable(Hash),
|
61
|
+
).returns(Net::HTTP::Post)
|
62
|
+
end
|
63
|
+
def post_request(path:, auth: false, idempotency_key: nil, body: nil)
|
33
64
|
request = Net::HTTP::Post.new(path, 'Content-Type' => 'application/json')
|
34
65
|
request.body = body.to_json if body
|
66
|
+
request['Authorization'] = "Bearer #{WorkOS.key!}" if auth
|
67
|
+
request['Idempotency-Key'] = idempotency_key if idempotency_key
|
35
68
|
request['User-Agent'] = user_agent
|
36
69
|
request
|
37
70
|
end
|
@@ -68,6 +101,12 @@ module WorkOS
|
|
68
101
|
http_status: http_status,
|
69
102
|
request_id: response['x-request-id'],
|
70
103
|
)
|
104
|
+
when 404
|
105
|
+
raise APIError.new(
|
106
|
+
message: json['message'],
|
107
|
+
http_status: http_status,
|
108
|
+
request_id: response['x-request-id'],
|
109
|
+
)
|
71
110
|
when 422
|
72
111
|
errors = json['errors'].map do |error|
|
73
112
|
"#{error['field']}: #{error['code']}"
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# typed: true
|
3
|
+
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module WorkOS
|
7
|
+
# The Connection class provides a lightweight wrapper around
|
8
|
+
# a WorkOS Connection resource. This class is not meant to be instantiated
|
9
|
+
# in user space, and is instantiated internally but exposed.
|
10
|
+
class Connection
|
11
|
+
extend T::Sig
|
12
|
+
|
13
|
+
attr_accessor :id, :name, :connection_type, :domains
|
14
|
+
|
15
|
+
sig { params(json: String).void }
|
16
|
+
def initialize(json)
|
17
|
+
raw = parse_json(json)
|
18
|
+
|
19
|
+
@id = T.let(raw.id, String)
|
20
|
+
@name = T.let(raw.name, String)
|
21
|
+
@connection_type = T.let(raw.connection_type, String)
|
22
|
+
@domains = T.let(raw.domains, Array)
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_json(*)
|
26
|
+
{
|
27
|
+
id: id,
|
28
|
+
name: name,
|
29
|
+
connection_type: connection_type,
|
30
|
+
domains: domains,
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
sig { params(json_string: String).returns(WorkOS::Types::ConnectionStruct) }
|
37
|
+
def parse_json(json_string)
|
38
|
+
hash = JSON.parse(json_string, symbolize_names: true)
|
39
|
+
|
40
|
+
WorkOS::Types::ConnectionStruct.new(
|
41
|
+
id: hash[:id],
|
42
|
+
name: hash[:name],
|
43
|
+
connection_type: hash[:connection_type],
|
44
|
+
domains: hash[:domains],
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/workos/profile.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
# typed: true
|
3
3
|
|
4
|
-
|
5
4
|
require 'json'
|
6
5
|
|
7
6
|
module WorkOS
|
8
7
|
# The Profile class provides a lighweight wrapper around
|
9
8
|
# a normalized response from the various IDPs WorkOS
|
10
9
|
# supports as part of the SSO integration. This class
|
11
|
-
# is not meant
|
10
|
+
# is not meant to be instantiated in user space, and
|
12
11
|
# is instantiated internally but exposed.
|
13
12
|
class Profile
|
14
13
|
extend T::Sig
|
@@ -21,12 +20,12 @@ module WorkOS
|
|
21
20
|
def initialize(profile_json)
|
22
21
|
raw = parse_json(profile_json)
|
23
22
|
|
24
|
-
@id
|
25
|
-
@email
|
26
|
-
@first_name
|
27
|
-
@last_name
|
23
|
+
@id = T.let(raw.id, String)
|
24
|
+
@email = T.let(raw.email, String)
|
25
|
+
@first_name = T.let(raw.first_name, String)
|
26
|
+
@last_name = T.let(raw.last_name, String)
|
28
27
|
@connection_type = T.let(raw.connection_type, String)
|
29
|
-
@idp_id
|
28
|
+
@idp_id = T.let(raw.idp_id, String)
|
30
29
|
end
|
31
30
|
|
32
31
|
sig { returns(String) }
|
data/lib/workos/sso.rb
CHANGED
@@ -18,16 +18,6 @@ module WorkOS
|
|
18
18
|
|
19
19
|
PROVIDERS = WorkOS::Types::Provider.values.map(&:serialize).freeze
|
20
20
|
|
21
|
-
sig do
|
22
|
-
params(
|
23
|
-
project_id: String,
|
24
|
-
redirect_uri: String,
|
25
|
-
domain: T.nilable(String),
|
26
|
-
provider: T.nilable(String),
|
27
|
-
state: Hash,
|
28
|
-
).returns(String)
|
29
|
-
end
|
30
|
-
|
31
21
|
# Generate an Oauth2 authorization URL where your users will
|
32
22
|
# authenticate using the configured SSO Identity Provider.
|
33
23
|
#
|
@@ -59,6 +49,15 @@ module WorkOS
|
|
59
49
|
# "response_type=code&state=%7B%3Anext_page%3D%3E%22%2Fdocs%22%7D"
|
60
50
|
#
|
61
51
|
# @return [String]
|
52
|
+
sig do
|
53
|
+
params(
|
54
|
+
project_id: String,
|
55
|
+
redirect_uri: String,
|
56
|
+
domain: T.nilable(String),
|
57
|
+
provider: T.nilable(String),
|
58
|
+
state: Hash,
|
59
|
+
).returns(String)
|
60
|
+
end
|
62
61
|
def authorization_url(
|
63
62
|
project_id:, redirect_uri:, domain: nil, provider: nil, state: {}
|
64
63
|
)
|
@@ -76,13 +75,6 @@ module WorkOS
|
|
76
75
|
"https://#{WorkOS::API_HOSTNAME}/sso/authorize?#{query}"
|
77
76
|
end
|
78
77
|
|
79
|
-
sig do
|
80
|
-
params(
|
81
|
-
code: String,
|
82
|
-
project_id: String,
|
83
|
-
).returns(WorkOS::Profile)
|
84
|
-
end
|
85
|
-
|
86
78
|
# Fetch the profile details for the authenticated SSO user.
|
87
79
|
#
|
88
80
|
# @param [String] code The authorization code provided in the callback URL
|
@@ -105,6 +97,7 @@ module WorkOS
|
|
105
97
|
# >
|
106
98
|
#
|
107
99
|
# @return [WorkOS::Profile]
|
100
|
+
sig { params(code: String, project_id: String).returns(WorkOS::Profile) }
|
108
101
|
def profile(code:, project_id:)
|
109
102
|
body = {
|
110
103
|
client_id: project_id,
|
@@ -119,17 +112,11 @@ module WorkOS
|
|
119
112
|
WorkOS::Profile.new(response.body)
|
120
113
|
end
|
121
114
|
|
122
|
-
sig do
|
123
|
-
params(
|
124
|
-
token: String,
|
125
|
-
).returns(T::Boolean)
|
126
|
-
end
|
127
|
-
|
128
115
|
# Promote a DraftConnection created via the WorkOS.js embed such that the
|
129
116
|
# Enterprise users can begin signing into your application.
|
130
117
|
#
|
131
|
-
# @param [String] token The
|
132
|
-
# you by the WorkOS.js
|
118
|
+
# @param [String] token The Draft Connection token that's been provided to
|
119
|
+
# you by the WorkOS.js
|
133
120
|
#
|
134
121
|
# @example
|
135
122
|
# WorkOS::SSO.promote_draft_connection(
|
@@ -139,8 +126,10 @@ module WorkOS
|
|
139
126
|
#
|
140
127
|
# @return [Bool] - returns `true` if successful, `false` otherwise.
|
141
128
|
# @see https://github.com/workos-inc/ruby-idp-link-example
|
129
|
+
sig { params(token: String).returns(T::Boolean) }
|
142
130
|
def promote_draft_connection(token:)
|
143
|
-
request =
|
131
|
+
request = post_request(
|
132
|
+
auth: true,
|
144
133
|
path: "/draft_connections/#{token}/activate",
|
145
134
|
)
|
146
135
|
|
@@ -149,6 +138,36 @@ module WorkOS
|
|
149
138
|
response.is_a? Net::HTTPSuccess
|
150
139
|
end
|
151
140
|
|
141
|
+
# Create a Connection
|
142
|
+
#
|
143
|
+
# @param [String] source The Draft Connection token that's been provided
|
144
|
+
# to you by WorkOS.js
|
145
|
+
#
|
146
|
+
# @example
|
147
|
+
# WorkOS::SSO.create_connection(source: 'draft_conn_429u59js')
|
148
|
+
# => #<WorkOS::Connection:0x00007fb6e4193d20
|
149
|
+
# @id="conn_02DRA1XNSJDZ19A31F183ECQW9",
|
150
|
+
# @name="Foo Corp",
|
151
|
+
# @connection_type="OktaSAML",
|
152
|
+
# @domains=
|
153
|
+
# [{:object=>"connection_domain",
|
154
|
+
# :id=>"domain_01E6PK9N3XMD8RHWF7S66380AR",
|
155
|
+
# :domain=>"example.com"}]>
|
156
|
+
#
|
157
|
+
# @return [WorkOS::Connection]
|
158
|
+
sig { params(source: String).returns(WorkOS::Connection) }
|
159
|
+
def create_connection(source:)
|
160
|
+
request = post_request(
|
161
|
+
auth: true,
|
162
|
+
path: '/connections',
|
163
|
+
body: { source: source },
|
164
|
+
)
|
165
|
+
|
166
|
+
response = execute_request(request: request)
|
167
|
+
|
168
|
+
WorkOS::Connection.new(response.body)
|
169
|
+
end
|
170
|
+
|
152
171
|
private
|
153
172
|
|
154
173
|
sig do
|
@@ -188,12 +207,6 @@ module WorkOS
|
|
188
207
|
)
|
189
208
|
end
|
190
209
|
# rubocop:enable Metrics/MethodLength
|
191
|
-
|
192
|
-
def bearer_post_request(path:, body: nil)
|
193
|
-
request = post_request(path: path, body: body)
|
194
|
-
request['Authorization'] = "Bearer #{WorkOS.key!}"
|
195
|
-
request
|
196
|
-
end
|
197
210
|
end
|
198
211
|
end
|
199
212
|
end
|
data/lib/workos/types.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
# typed:
|
3
|
-
|
2
|
+
# typed: strong
|
4
3
|
|
5
4
|
module WorkOS
|
6
5
|
# WorkOS believes strongly in typed languages,
|
7
6
|
# so we're using Sorbet throughout this Ruby gem.
|
8
7
|
module Types
|
8
|
+
require_relative 'types/connection_struct'
|
9
9
|
require_relative 'types/profile_struct'
|
10
10
|
require_relative 'types/provider_enum'
|
11
11
|
end
|