workos 0.9.0 → 0.10.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 +4 -4
- data/.github/CODEOWNERS +5 -0
- data/.rubocop.yml +4 -0
- data/Gemfile.lock +2 -2
- data/README.md +118 -55
- data/docs/WorkOS/SSO.html +235 -235
- data/docs/file.README.html +20 -20
- data/lib/workos/audit_trail.rb +1 -0
- data/lib/workos/client.rb +22 -1
- data/lib/workos/connection.rb +0 -2
- data/lib/workos/organization.rb +0 -2
- data/lib/workos/passwordless.rb +3 -2
- data/lib/workos/portal.rb +0 -6
- data/lib/workos/profile.rb +2 -4
- data/lib/workos/sso.rb +119 -13
- data/lib/workos/version.rb +1 -1
- data/lib/workos.rb +1 -0
- data/spec/lib/workos/passwordless_spec.rb +1 -0
- data/spec/lib/workos/sso_spec.rb +198 -7
- data/spec/support/fixtures/vcr_cassettes/audit_trail/get_events.yml +2 -2
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories.yml +1 -1
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories_with_domain_param.yml +1 -1
- data/spec/support/fixtures/vcr_cassettes/sso/delete_connection_with_invalid_id.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/sso/delete_connection_with_valid_id.yml +70 -0
- data/spec/support/fixtures/vcr_cassettes/sso/get_connection_with_invalid_id.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/sso/get_connection_with_valid_id.yml +74 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_after_param.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_before_param.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_connection_type_param.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_domain_param.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_limit_param.yml +72 -0
- metadata +24 -4
- data/CODEOWNERS +0 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 72c11606b98be63db5dab6a2c68eb69cab12ce9f9afe20b73475ce6948b24794
|
|
4
|
+
data.tar.gz: c7ea54043041810b71e2390b3efe20152870d8617da9a48a9922c775fb01f5d4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8721f09bdcabce0772ffd6218b11859bbbdddb096f7d85c1b56b1f1b28816b8e2d86ef45838311e37c5c7bb322ffb2836d4ff355d8268ee15bbfcded71f1f658
|
|
7
|
+
data.tar.gz: 74b8126bedbd7c2f36da24376af99f2502d5ba3ac062c9067515d1fa6c5c402684ae0c6a3d2cfa42ee0ea61cbf75329b861a6362aa8fd7af361e58f8fff0604d
|
data/.github/CODEOWNERS
ADDED
data/.rubocop.yml
CHANGED
|
@@ -10,8 +10,12 @@ Layout/LineLength:
|
|
|
10
10
|
- '(\A|\s)/.*?/'
|
|
11
11
|
Metrics/BlockLength:
|
|
12
12
|
ExcludedMethods: ['describe', 'context']
|
|
13
|
+
Metrics/MethodLength:
|
|
14
|
+
Max: 15
|
|
13
15
|
Metrics/ModuleLength:
|
|
14
16
|
Max: 150
|
|
17
|
+
Metrics/ParameterLists:
|
|
18
|
+
Max: 6
|
|
15
19
|
Style/TrailingCommaInArguments:
|
|
16
20
|
EnforcedStyleForMultiline: 'consistent_comma'
|
|
17
21
|
Style/TrailingCommaInHashLiteral:
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
workos (0.
|
|
4
|
+
workos (0.10.0)
|
|
5
5
|
sorbet-runtime (~> 0.5)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
@@ -54,7 +54,7 @@ GEM
|
|
|
54
54
|
simplecov-html (0.12.2)
|
|
55
55
|
sorbet (0.5.5560)
|
|
56
56
|
sorbet-static (= 0.5.5560)
|
|
57
|
-
sorbet-runtime (0.5.
|
|
57
|
+
sorbet-runtime (0.5.6189)
|
|
58
58
|
sorbet-static (0.5.5560-universal-darwin-14)
|
|
59
59
|
unicode-display_width (1.6.0)
|
|
60
60
|
vcr (5.0.0)
|
data/README.md
CHANGED
|
@@ -42,50 +42,9 @@ Alternatively, you may set the key yourself, such as in an initializer in your a
|
|
|
42
42
|
WorkOS.key = '[your api key]'
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
## The Audit Trail Module
|
|
46
|
-
|
|
47
|
-
The Audit Trail Module provides methods for creating Audit Trail events on
|
|
48
|
-
WorkOS.
|
|
49
|
-
|
|
50
|
-
See our [Audit Trail
|
|
51
|
-
Overview](https://docs.workos.com/audit-trail/overview) for
|
|
52
|
-
more information.
|
|
53
|
-
|
|
54
|
-
```ruby
|
|
55
|
-
payload = {
|
|
56
|
-
group: 'Foo Corp',
|
|
57
|
-
location: '127.0.0.1',
|
|
58
|
-
action: 'user.created',
|
|
59
|
-
action_type: 'C',
|
|
60
|
-
actor_name: 'Foo',
|
|
61
|
-
actor_id: 'user_12345',
|
|
62
|
-
target_name: 'Bar',
|
|
63
|
-
target_id: 'user_67890',
|
|
64
|
-
occurred_at: '2020-01-10T15:30:00-05:00',
|
|
65
|
-
metadata: {
|
|
66
|
-
source: 'Email',
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
WorkOS::AuditTrail.create_event(event: payload)
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### Idempotency
|
|
74
|
-
|
|
75
|
-
To perform an idempotent request, provide an additional idempotency_key
|
|
76
|
-
parameter to the `create_event` options.
|
|
77
|
-
|
|
78
|
-
```ruby
|
|
79
|
-
WorkOS::AuditTrail.create_event(event: payload, idempotency_key: 'key123456')
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
See our [API
|
|
83
|
-
Reference](https://docs.workos.com/audit-trail/api-reference#idempotency)
|
|
84
|
-
for more information on idempotency keys.
|
|
85
|
-
|
|
86
45
|
## The SSO Module
|
|
87
46
|
|
|
88
|
-
The SSO Module provides
|
|
47
|
+
The SSO Module provides convenient methods for authenticating a Single Sign On (SSO) user via WorkOS. WorkOS SSO follows the OAuth 2.0 specification.
|
|
89
48
|
|
|
90
49
|
First, you'll direct your SSO users to an `authorization_url`. They will sign in to their SSO account with their Identity Provider, and be redirected to a
|
|
91
50
|
callback URL that you set in your WorkOS Dashboard. The user will be redirected with a `code` URL parameter, which you can then exchange for a WorkOS::Profile
|
|
@@ -94,7 +53,7 @@ using the `WorkOS::SSO.get_profile` method.
|
|
|
94
53
|
See our Ruby SSO example app for a [complete example](https://github.com/workos-inc/ruby-sso-example).
|
|
95
54
|
|
|
96
55
|
```ruby
|
|
97
|
-
WorkOS::SSO.authorization_url(domain:,
|
|
56
|
+
WorkOS::SSO.authorization_url(domain:, client_id:, redirect_uri:, state: {})
|
|
98
57
|
```
|
|
99
58
|
|
|
100
59
|
> Generate an authorization URL to intitiate the WorkOS OAuth2 workflow.
|
|
@@ -102,25 +61,25 @@ WorkOS::SSO.authorization_url(domain:, project_id:, redirect_uri:, state: {})
|
|
|
102
61
|
`WorkOS::SSO.authorization_url` accepts four arguments:
|
|
103
62
|
|
|
104
63
|
- `domain` (string) — the authenticating user's company domain, without protocol (ex. `example.com`)
|
|
105
|
-
- `
|
|
64
|
+
- `client_id` (string) — your application's WorkOS [Client ID](https://dashboard.workos.com/sso/configuration) (ex. `project_01JG3BCPTRTSTTWQR4VSHXGWCQ`)
|
|
106
65
|
- `state` (optional, hash) — an optional hash used to manage state across authorization transactions (ex. `{ next_page: '/docs'}`)
|
|
107
|
-
- `redirect_uri` (string) — a callback URL where your application redirects the user-agent after an authorization code is granted (ex. `workos.dev/callback`). This must match one of your configured callback URLs for the associated
|
|
66
|
+
- `redirect_uri` (string) — a callback URL where your application redirects the user-agent after an authorization code is granted (ex. `workos.dev/callback`). This must match one of your configured callback URLs for the associated environment on your WorkOS dashboard.
|
|
108
67
|
|
|
109
68
|
This method will return an OAuth2 query string of the form:
|
|
110
69
|
|
|
111
|
-
`https://${domain}/sso/authorize?response_type=code&client_id=${
|
|
70
|
+
`https://${domain}/sso/authorize?response_type=code&client_id=${clientID}&redirect_uri=${redirectURI}&state=${state}`
|
|
112
71
|
|
|
113
72
|
For example, when used in a [Sinatra app](http://sinatrarb.com/):
|
|
114
73
|
|
|
115
74
|
```ruby
|
|
116
75
|
DOMAIN = 'example.com'
|
|
117
|
-
|
|
76
|
+
CLIENT_ID = '{clientId}'
|
|
118
77
|
REDIRECT_URI = 'http://localhost:4567/callback'
|
|
119
78
|
|
|
120
79
|
get '/auth' do
|
|
121
80
|
authorization_url = WorkOS::SSO.authorization_url(
|
|
122
81
|
domain: DOMAIN,
|
|
123
|
-
|
|
82
|
+
client_id: CLIENT_ID,
|
|
124
83
|
redirect_uri: REDIRECT_URI,
|
|
125
84
|
)
|
|
126
85
|
|
|
@@ -130,14 +89,14 @@ end
|
|
|
130
89
|
|
|
131
90
|
The user would be redirected to:
|
|
132
91
|
|
|
133
|
-
`https://api.workos.com/sso/authorize?response_type=code&client_id={
|
|
92
|
+
`https://api.workos.com/sso/authorize?response_type=code&client_id={clientID}&redirect_uri=http://localhost:4567/callback`
|
|
134
93
|
|
|
135
94
|
WorkOS takes over from here, sending the user to authenticate with their IDP, and on successful login, returns
|
|
136
95
|
the user to your callback URL with a `code` parameter. You'll use `WorkOS::SSO.profile` to exchange the
|
|
137
96
|
code for a `WorkOS::Profile`.
|
|
138
97
|
|
|
139
98
|
```ruby
|
|
140
|
-
WorkOS::SSO.profile(code:,
|
|
99
|
+
WorkOS::SSO.profile(code:, client_id:)
|
|
141
100
|
```
|
|
142
101
|
|
|
143
102
|
> Fetch a WorkOS::Profile for an authorized user.
|
|
@@ -145,7 +104,7 @@ WorkOS::SSO.profile(code:, project_id:)</h4>
|
|
|
145
104
|
`WorkOS::SSO.profile` accepts two arguments:
|
|
146
105
|
|
|
147
106
|
- `code` (string) — an opaque string provided by the authorization server; will be exchanged for an Access Token when the user's profile is sent
|
|
148
|
-
- `
|
|
107
|
+
- `client_id` (string) — your application's WorkOS [Client ID](https://dashboard.workos.com/sso/configuration) (ex. `project_01JG3BCPTRTSTTWQR4VSHXGWCQ`)
|
|
149
108
|
|
|
150
109
|
This method will return an instance of a `WorkOS::Profile` with the following attributes:
|
|
151
110
|
|
|
@@ -168,17 +127,17 @@ This method will return an instance of a `WorkOS::Profile` with the following at
|
|
|
168
127
|
>
|
|
169
128
|
```
|
|
170
129
|
|
|
171
|
-
Our
|
|
130
|
+
Our Sinatra app can be extended to use this method:
|
|
172
131
|
|
|
173
132
|
```ruby
|
|
174
133
|
DOMAIN = 'example.com'
|
|
175
|
-
|
|
134
|
+
CLIENT_ID = '{clientId}'
|
|
176
135
|
REDIRECT_URI = 'http://localhost:4567/callback'
|
|
177
136
|
|
|
178
137
|
get '/auth' do
|
|
179
138
|
authorization_url = WorkOS::SSO.authorization_url(
|
|
180
139
|
domain: DOMAIN,
|
|
181
|
-
|
|
140
|
+
client_id: CLIENT_ID,
|
|
182
141
|
redirect_uri: REDIRECT_URI,
|
|
183
142
|
)
|
|
184
143
|
|
|
@@ -188,7 +147,7 @@ end
|
|
|
188
147
|
get '/callback' do
|
|
189
148
|
profile = WorkOS::SSO.profile(
|
|
190
149
|
code: params['code'],
|
|
191
|
-
|
|
150
|
+
client_id: CLIENT_ID,
|
|
192
151
|
)
|
|
193
152
|
|
|
194
153
|
session[:user] = profile.to_json
|
|
@@ -198,3 +157,107 @@ end
|
|
|
198
157
|
```
|
|
199
158
|
|
|
200
159
|
Given the `WorkOS::Profile`, you can now sign the user in according to your own authentication setup.
|
|
160
|
+
|
|
161
|
+
## The Magic Link Module
|
|
162
|
+
|
|
163
|
+
The Magic Link Module provides methods for authenticating a Passwordless user via WorkOS.
|
|
164
|
+
|
|
165
|
+
First, you'll create a Passwordless Session for a Magic Link connection.
|
|
166
|
+
Then, using the session ID, you'll email a user the Magic Link confirmation URL.
|
|
167
|
+
The user can then click on that link to be authenticated to your application.
|
|
168
|
+
|
|
169
|
+
> Create a Passwordless Session for a Magic Link Connection.
|
|
170
|
+
|
|
171
|
+
`WorkOS::Passwordless.create_session` accepts four arguments:
|
|
172
|
+
|
|
173
|
+
- `email` (string) - the email of the user to authenticate.
|
|
174
|
+
- `type` (string) - The type of Passwordless Session to create. Currently, the only supported value is `MagicLink`.
|
|
175
|
+
- `state` (optional, string) - Optional parameter that a Developer can choose to include in their authorization URL. If included, then the redirect URI received from WorkOS will contain the exact `state` that was passed in the authorization URL.
|
|
176
|
+
- `redirect_uri` (string) - a callback URL where your application redirects the user-agent after an authorization code is granted (ex. `workos.dev/callback`). This must match one of your configured callback URLs for the associated environment on your WorkOS dashboard.
|
|
177
|
+
|
|
178
|
+
This method will return a Passwordless Session object, containing the following attributes:
|
|
179
|
+
|
|
180
|
+
- `id` (string) - the unique ID of the session.
|
|
181
|
+
- `email` (string) - the email address of the user for the session.
|
|
182
|
+
- `expires_at` (date) - the ISO-8601 datetime at which the session expires.
|
|
183
|
+
- `link` (string) - the link for the user to authenticate with. You can use this link to send a custom email to the user, or send an email using the `WorkOS::Passwordless.send_session` method, described below.
|
|
184
|
+
|
|
185
|
+
> Email a user the Magic Link confirmation URL.
|
|
186
|
+
|
|
187
|
+
`WorkOS::Passwordless.send_session` accepts one argument:
|
|
188
|
+
|
|
189
|
+
- `id` (string) - the unique identifier of the Passwordless Session to send an email for.
|
|
190
|
+
|
|
191
|
+
This method will return a boolean confirming the Magic Link was sent.
|
|
192
|
+
|
|
193
|
+
> Example with Sinatra application
|
|
194
|
+
|
|
195
|
+
Our Sinatra app can be altered to use Magic Link:
|
|
196
|
+
|
|
197
|
+
```ruby
|
|
198
|
+
CLIENT_ID = '{clientId}'
|
|
199
|
+
REDIRECT_URI = 'http://localhost:4567/callback'
|
|
200
|
+
|
|
201
|
+
post '/passwordless-auth' do
|
|
202
|
+
session = WorkOS::Passwordless.create_session(
|
|
203
|
+
email: params[:email],
|
|
204
|
+
type: 'MagicLink',
|
|
205
|
+
redirect_uri: REDIRECT_URI
|
|
206
|
+
)
|
|
207
|
+
WorkOS::Passwordless.send_session(session.id)
|
|
208
|
+
|
|
209
|
+
redirect '/check-email'
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
get '/callback' do
|
|
213
|
+
profile = WorkOS::SSO.profile(
|
|
214
|
+
code: params['code'],
|
|
215
|
+
client_id: CLIENT_ID,
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
session[:user] = profile.to_json
|
|
219
|
+
|
|
220
|
+
redirect '/'
|
|
221
|
+
end
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## The Audit Trail Module
|
|
225
|
+
|
|
226
|
+
The Audit Trail Module provides methods for creating Audit Trail events on
|
|
227
|
+
WorkOS.
|
|
228
|
+
|
|
229
|
+
See our [Audit Trail
|
|
230
|
+
Overview](https://docs.workos.com/audit-trail/overview) for
|
|
231
|
+
more information.
|
|
232
|
+
|
|
233
|
+
```ruby
|
|
234
|
+
payload = {
|
|
235
|
+
group: 'Foo Corp',
|
|
236
|
+
location: '127.0.0.1',
|
|
237
|
+
action: 'user.created',
|
|
238
|
+
action_type: 'C',
|
|
239
|
+
actor_name: 'Foo',
|
|
240
|
+
actor_id: 'user_12345',
|
|
241
|
+
target_name: 'Bar',
|
|
242
|
+
target_id: 'user_67890',
|
|
243
|
+
occurred_at: '2020-01-10T15:30:00-05:00',
|
|
244
|
+
metadata: {
|
|
245
|
+
source: 'Email',
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
WorkOS::AuditTrail.create_event(event: payload)
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Idempotency
|
|
253
|
+
|
|
254
|
+
To perform an idempotent request, provide an additional idempotency_key
|
|
255
|
+
parameter to the `create_event` options.
|
|
256
|
+
|
|
257
|
+
```ruby
|
|
258
|
+
WorkOS::AuditTrail.create_event(event: payload, idempotency_key: 'key123456')
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
See our [API
|
|
262
|
+
Reference](https://docs.workos.com/audit-trail/api-reference#idempotency)
|
|
263
|
+
for more information on idempotency keys.
|