workos 0.9.0 → 1.0.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 +5 -1
- data/.ruby-version +1 -1
- data/.semaphore/semaphore.yml +8 -2
- data/Gemfile.lock +49 -36
- data/LICENSE +1 -1
- data/README.md +13 -167
- 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 +42 -4
- data/lib/workos/connection.rb +12 -3
- data/lib/workos/directory.rb +53 -0
- data/lib/workos/directory_group.rb +44 -0
- data/lib/workos/directory_sync.rb +63 -7
- data/lib/workos/directory_user.rb +63 -0
- data/lib/workos/organization.rb +0 -2
- data/lib/workos/organizations.rb +150 -0
- data/lib/workos/passwordless.rb +7 -2
- data/lib/workos/portal.rb +1 -87
- data/lib/workos/profile.rb +3 -6
- data/lib/workos/profile_and_token.rb +28 -0
- data/lib/workos/sso.rb +106 -65
- data/lib/workos/types/connection_struct.rb +3 -0
- data/lib/workos/types/directory_group_struct.rb +13 -0
- data/lib/workos/types/directory_struct.rb +16 -0
- data/lib/workos/types/directory_user_struct.rb +19 -0
- data/lib/workos/types/intent_enum.rb +1 -0
- data/lib/workos/types.rb +3 -0
- data/lib/workos/version.rb +1 -1
- data/lib/workos.rb +6 -0
- data/sorbet/rbi/gems/addressable.rbi +199 -0
- data/sorbet/rbi/gems/ast.rbi +49 -0
- data/sorbet/rbi/gems/codecov.rbi +37 -0
- data/sorbet/rbi/gems/crack.rbi +62 -0
- data/sorbet/rbi/gems/docile.rbi +36 -0
- data/sorbet/rbi/gems/hashdiff.rbi +66 -0
- data/sorbet/rbi/gems/parallel.rbi +83 -0
- data/sorbet/rbi/gems/parser.rbi +1429 -0
- data/sorbet/rbi/gems/public_suffix.rbi +104 -0
- data/sorbet/rbi/gems/rainbow.rbi +118 -0
- data/sorbet/rbi/gems/rake.rbi +644 -0
- data/sorbet/rbi/gems/regexp_parser.rbi +926 -0
- data/sorbet/rbi/gems/rexml.rbi +628 -0
- data/sorbet/rbi/gems/rspec-core.rbi +1898 -0
- data/sorbet/rbi/gems/rspec-expectations.rbi +1127 -0
- data/sorbet/rbi/gems/rspec-mocks.rbi +1099 -0
- data/sorbet/rbi/gems/rspec-support.rbi +280 -0
- data/sorbet/rbi/gems/rspec.rbi +15 -0
- data/sorbet/rbi/gems/rubocop-ast.rbi +1355 -0
- data/sorbet/rbi/gems/rubocop.rbi +7253 -0
- data/sorbet/rbi/gems/ruby-progressbar.rbi +304 -0
- data/sorbet/rbi/gems/simplecov-html.rbi +35 -0
- data/sorbet/rbi/gems/simplecov.rbi +406 -0
- data/sorbet/rbi/gems/unicode-display_width.rbi +17 -0
- data/sorbet/rbi/gems/vcr.rbi +572 -0
- data/sorbet/rbi/gems/webmock.rbi +556 -0
- data/sorbet/rbi/gems/yard.rbi +1165 -0
- data/sorbet/rbi/sorbet-typed/lib/rake/all/rake.rbi +645 -0
- data/sorbet/rbi/sorbet-typed/lib/rspec-core/all/rspec-core.rbi +1891 -0
- data/sorbet/rbi/sorbet-typed/lib/rubocop/~>0.85/rubocop.rbi +2072 -0
- data/sorbet/rbi/sorbet-typed/lib/yard/all/yard.rbi +1214 -0
- data/sorbet/rbi/todo.rbi +1 -3
- data/spec/lib/workos/audit_trail_spec.rb +0 -8
- data/spec/lib/workos/directory_sync_spec.rb +347 -40
- data/spec/lib/workos/organizations_spec.rb +164 -0
- data/spec/lib/workos/passwordless_spec.rb +1 -8
- data/spec/lib/workos/portal_spec.rb +17 -123
- data/spec/lib/workos/sso_spec.rb +230 -71
- data/spec/spec_helper.rb +2 -1
- data/spec/support/fixtures/vcr_cassettes/audit_trail/get_events.yml +2 -2
- data/spec/support/fixtures/vcr_cassettes/directory_sync/delete_directory.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_after.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_before.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_directories_with_domain_param.yml → list_directories/with_domain.yml} +19 -9
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_limit.yml +74 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_directories.yml → list_directories/with_no_options.yml} +1 -1
- data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_users_with_directory_param.yml → list_directories/with_search.yml} +22 -11
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_after.yml +76 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_before.yml +74 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_directory.yml +78 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_limit.yml +74 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_groups.yml → list_groups/with_no_options.yml} +16 -6
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_user.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_after.yml +86 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_before.yml +75 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_directory.yml +93 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_group.yml +76 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_limit.yml +75 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_users.yml → list_users/with_no_options.yml} +16 -6
- data/spec/support/fixtures/vcr_cassettes/organization/get.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/{directory_sync/list_groups_with_directory_param.yml → organization/get_invalid.yml} +21 -11
- data/spec/support/fixtures/vcr_cassettes/organization/update.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/organization/update_invalid.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/portal/generate_link_dsync.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/portal/{generate_link.yml → generate_link_sso.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/{create_connection_with_invalid_source.yml → get_connection_with_invalid_id.yml} +26 -12
- data/spec/support/fixtures/vcr_cassettes/sso/get_connection_with_valid_id.yml +74 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_after.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_before.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_connection_type.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_domain.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_limit.yml +74 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_no_options.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_organization_id.yml +72 -0
- data/workos.gemspec +2 -0
- metadata +122 -33
- data/CODEOWNERS +0 -1
- data/sorbet/rbi/hidden-definitions/errors.txt +0 -24896
- data/sorbet/rbi/hidden-definitions/hidden.rbi +0 -38411
- data/sorbet/rbi/sorbet-typed/lib/bundler/all/bundler.rbi +0 -8684
- data/sorbet/rbi/sorbet-typed/lib/ruby/all/gem.rbi +0 -4222
- data/sorbet/rbi/sorbet-typed/lib/ruby/all/open3.rbi +0 -111
- data/sorbet/rbi/sorbet-typed/lib/ruby/all/resolv.rbi +0 -543
- data/spec/support/fixtures/vcr_cassettes/sso/create_connection_with_valid_source.yml +0 -63
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f8a9f985318b4480c50a4d0528cf5036018235833585746e3ed632020fca3d00
|
|
4
|
+
data.tar.gz: bc75b64c4a4ffa8b32ee2b841af1c6bdb39df729bda95cc59d9ad36206cab387
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 56d3896fd8bb4194cbb50464759c9babfe2421e56148827fe282af956fa4fb9f38eb308363e30427bed0ef3596e5c1ba99150f108208835ecdb40921e99bf67e
|
|
7
|
+
data.tar.gz: e5f09155ab5a7e92dc0ccd6a10af885d5802925a7db1fdaf21cbeb9902b231642284ed06aa1ce0806271fceab5f42209d1c3c1c5442c6ea42a780a6264670ce4
|
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
|
-
Max:
|
|
16
|
+
Max: 200
|
|
17
|
+
Metrics/ParameterLists:
|
|
18
|
+
Max: 6
|
|
15
19
|
Style/TrailingCommaInArguments:
|
|
16
20
|
EnforcedStyleForMultiline: 'consistent_comma'
|
|
17
21
|
Style/TrailingCommaInHashLiteral:
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
3.0.1
|
data/.semaphore/semaphore.yml
CHANGED
|
@@ -60,10 +60,16 @@ blocks:
|
|
|
60
60
|
- sem-version ruby 2.6.5
|
|
61
61
|
- bundle install
|
|
62
62
|
- bundle exec rspec
|
|
63
|
-
- name: Ruby 2.7.
|
|
63
|
+
- name: Ruby 2.7.3
|
|
64
64
|
commands:
|
|
65
65
|
- checkout
|
|
66
|
-
- sem-version ruby 2.7.
|
|
66
|
+
- sem-version ruby 2.7.3
|
|
67
|
+
- bundle install
|
|
68
|
+
- bundle exec rspec
|
|
69
|
+
- name: Ruby 3.0.1
|
|
70
|
+
commands:
|
|
71
|
+
- checkout
|
|
72
|
+
- sem-version ruby 3.0.1
|
|
67
73
|
- bundle install
|
|
68
74
|
- bundle exec rspec
|
|
69
75
|
promotions:
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
workos (0.
|
|
4
|
+
workos (1.0.0)
|
|
5
5
|
sorbet-runtime (~> 0.5)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
@@ -9,60 +9,73 @@ GEM
|
|
|
9
9
|
specs:
|
|
10
10
|
addressable (2.7.0)
|
|
11
11
|
public_suffix (>= 2.0.2, < 5.0)
|
|
12
|
-
ast (2.4.
|
|
13
|
-
codecov (0.2.
|
|
12
|
+
ast (2.4.2)
|
|
13
|
+
codecov (0.2.12)
|
|
14
14
|
json
|
|
15
15
|
simplecov
|
|
16
|
-
crack (0.4.
|
|
17
|
-
|
|
18
|
-
diff-lcs (1.
|
|
19
|
-
docile (1.3.
|
|
20
|
-
hashdiff (1.0.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
public_suffix (4.0.2)
|
|
16
|
+
crack (0.4.5)
|
|
17
|
+
rexml
|
|
18
|
+
diff-lcs (1.4.4)
|
|
19
|
+
docile (1.3.5)
|
|
20
|
+
hashdiff (1.0.1)
|
|
21
|
+
json (2.5.1)
|
|
22
|
+
parallel (1.20.1)
|
|
23
|
+
parser (3.0.1.0)
|
|
24
|
+
ast (~> 2.4.1)
|
|
25
|
+
public_suffix (4.0.6)
|
|
27
26
|
rainbow (3.0.0)
|
|
28
|
-
rake (13.0.
|
|
27
|
+
rake (13.0.3)
|
|
28
|
+
regexp_parser (2.1.1)
|
|
29
|
+
rexml (3.2.5)
|
|
29
30
|
rspec (3.9.0)
|
|
30
31
|
rspec-core (~> 3.9.0)
|
|
31
32
|
rspec-expectations (~> 3.9.0)
|
|
32
33
|
rspec-mocks (~> 3.9.0)
|
|
33
|
-
rspec-core (3.9.
|
|
34
|
-
rspec-support (~> 3.9.
|
|
35
|
-
rspec-expectations (3.9.
|
|
34
|
+
rspec-core (3.9.3)
|
|
35
|
+
rspec-support (~> 3.9.3)
|
|
36
|
+
rspec-expectations (3.9.4)
|
|
36
37
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
37
38
|
rspec-support (~> 3.9.0)
|
|
38
|
-
rspec-mocks (3.9.
|
|
39
|
+
rspec-mocks (3.9.1)
|
|
39
40
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
40
41
|
rspec-support (~> 3.9.0)
|
|
41
|
-
rspec-support (3.9.
|
|
42
|
-
rubocop (0.
|
|
43
|
-
jaro_winkler (~> 1.5.1)
|
|
42
|
+
rspec-support (3.9.4)
|
|
43
|
+
rubocop (0.93.1)
|
|
44
44
|
parallel (~> 1.10)
|
|
45
|
-
parser (>= 2.
|
|
45
|
+
parser (>= 2.7.1.5)
|
|
46
46
|
rainbow (>= 2.2.2, < 4.0)
|
|
47
|
+
regexp_parser (>= 1.8)
|
|
48
|
+
rexml
|
|
49
|
+
rubocop-ast (>= 0.6.0)
|
|
47
50
|
ruby-progressbar (~> 1.7)
|
|
48
|
-
unicode-display_width (>= 1.4.0, <
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
|
52
|
+
rubocop-ast (1.4.1)
|
|
53
|
+
parser (>= 2.7.1.5)
|
|
54
|
+
ruby-progressbar (1.11.0)
|
|
55
|
+
simplecov (0.21.2)
|
|
52
56
|
docile (~> 1.1)
|
|
53
57
|
simplecov-html (~> 0.11)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
sorbet
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
simplecov_json_formatter (~> 0.1)
|
|
59
|
+
simplecov-html (0.12.3)
|
|
60
|
+
simplecov_json_formatter (0.1.2)
|
|
61
|
+
sorbet (0.5.6388)
|
|
62
|
+
sorbet-static (= 0.5.6388)
|
|
63
|
+
sorbet-runtime (0.5.6403)
|
|
64
|
+
sorbet-static (0.5.6388-universal-darwin-14)
|
|
65
|
+
sorbet-static (0.5.6388-universal-darwin-15)
|
|
66
|
+
sorbet-static (0.5.6388-universal-darwin-16)
|
|
67
|
+
sorbet-static (0.5.6388-universal-darwin-17)
|
|
68
|
+
sorbet-static (0.5.6388-universal-darwin-18)
|
|
69
|
+
sorbet-static (0.5.6388-universal-darwin-19)
|
|
70
|
+
sorbet-static (0.5.6388-universal-darwin-20)
|
|
71
|
+
sorbet-static (0.5.6388-x86_64-linux)
|
|
72
|
+
unicode-display_width (1.7.0)
|
|
60
73
|
vcr (5.0.0)
|
|
61
|
-
webmock (3.
|
|
74
|
+
webmock (3.12.2)
|
|
62
75
|
addressable (>= 2.3.6)
|
|
63
76
|
crack (>= 0.3.2)
|
|
64
77
|
hashdiff (>= 0.4.0, < 2.0.0)
|
|
65
|
-
yard (0.9.
|
|
78
|
+
yard (0.9.26)
|
|
66
79
|
|
|
67
80
|
PLATFORMS
|
|
68
81
|
ruby
|
|
@@ -80,4 +93,4 @@ DEPENDENCIES
|
|
|
80
93
|
yard
|
|
81
94
|
|
|
82
95
|
BUNDLED WITH
|
|
83
|
-
2.
|
|
96
|
+
2.2.16
|
data/LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
#
|
|
1
|
+
# WorkOS Ruby Library
|
|
2
2
|
|
|
3
|
-
WorkOS
|
|
3
|
+
The WorkOS library for Ruby provides convenient access to the WorkOS API from applications written in Ruby.
|
|
4
4
|
|
|
5
5
|
## Documentation
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
See the [API Reference](https://workos.com/docs/reference/client-libraries) for Ruby usage examples.
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Install the package with:
|
|
12
12
|
|
|
13
|
-
```
|
|
13
|
+
```
|
|
14
14
|
gem install workos
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
If you're using Bundler to manage your application's gems, add the WorkOS gem to your Gemfile:
|
|
18
18
|
|
|
19
|
-
```
|
|
19
|
+
```
|
|
20
20
|
source 'https://rubygems.org'
|
|
21
21
|
|
|
22
22
|
gem 'workos'
|
|
@@ -24,17 +24,13 @@ gem 'workos'
|
|
|
24
24
|
|
|
25
25
|
## Configuration
|
|
26
26
|
|
|
27
|
-
To use the
|
|
28
|
-
|
|
29
|
-
You can do this through the `WORKOS_API_KEY` environment variable or by calling `WorkOS.key = [your API key]`.
|
|
30
|
-
|
|
31
|
-
The WorkOS Gem will read the environment variable `WORKOS_API_KEY`:
|
|
27
|
+
To use the library you must provide an API key, located in the WorkOS dashboard, as an environment variable `WORKOS_API_KEY`:
|
|
32
28
|
|
|
33
29
|
```sh
|
|
34
30
|
$ WORKOS_API_KEY=[your api key] ruby app.rb
|
|
35
31
|
```
|
|
36
32
|
|
|
37
|
-
|
|
33
|
+
Or, you may set the key yourself, such as in an initializer in your application load path:
|
|
38
34
|
|
|
39
35
|
```ruby
|
|
40
36
|
# /config/initializers/workos.rb
|
|
@@ -42,159 +38,9 @@ Alternatively, you may set the key yourself, such as in an initializer in your a
|
|
|
42
38
|
WorkOS.key = '[your api key]'
|
|
43
39
|
```
|
|
44
40
|
|
|
45
|
-
##
|
|
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
|
-
## The SSO Module
|
|
87
|
-
|
|
88
|
-
The SSO Module provides convenience methods for authenticating a Single Sign On (SSO) user via WorkOS. WorkOS SSO follows the Oauth 2.0 specification.
|
|
89
|
-
|
|
90
|
-
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
|
-
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
|
|
92
|
-
using the `WorkOS::SSO.get_profile` method.
|
|
93
|
-
|
|
94
|
-
See our Ruby SSO example app for a [complete example](https://github.com/workos-inc/ruby-sso-example).
|
|
95
|
-
|
|
96
|
-
```ruby
|
|
97
|
-
WorkOS::SSO.authorization_url(domain:, project_id:, redirect_uri:, state: {})
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
> Generate an authorization URL to intitiate the WorkOS OAuth2 workflow.
|
|
101
|
-
|
|
102
|
-
`WorkOS::SSO.authorization_url` accepts four arguments:
|
|
103
|
-
|
|
104
|
-
- `domain` (string) — the authenticating user's company domain, without protocol (ex. `example.com`)
|
|
105
|
-
- `project_id` (string) — your application's WorkOS [Project ID](https://dashboard.workos.com/sso/configuration) (ex. `project_01JG3BCPTRTSTTWQR4VSHXGWCQ`)
|
|
106
|
-
- `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 project on your WorkOS dashboard.
|
|
108
|
-
|
|
109
|
-
This method will return an OAuth2 query string of the form:
|
|
110
|
-
|
|
111
|
-
`https://${domain}/sso/authorize?response_type=code&client_id=${projectID}&redirect_uri=${redirectURI}&state=${state}`
|
|
112
|
-
|
|
113
|
-
For example, when used in a [Sinatra app](http://sinatrarb.com/):
|
|
114
|
-
|
|
115
|
-
```ruby
|
|
116
|
-
DOMAIN = 'example.com'
|
|
117
|
-
PROJECT_ID = '{projectId}'
|
|
118
|
-
REDIRECT_URI = 'http://localhost:4567/callback'
|
|
119
|
-
|
|
120
|
-
get '/auth' do
|
|
121
|
-
authorization_url = WorkOS::SSO.authorization_url(
|
|
122
|
-
domain: DOMAIN,
|
|
123
|
-
project_id: PROJECT_ID,
|
|
124
|
-
redirect_uri: REDIRECT_URI,
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
redirect authorization_url
|
|
128
|
-
end
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
The user would be redirected to:
|
|
132
|
-
|
|
133
|
-
`https://api.workos.com/sso/authorize?response_type=code&client_id={projectID}&redirect_uri=http://localhost:4567/callback`
|
|
134
|
-
|
|
135
|
-
WorkOS takes over from here, sending the user to authenticate with their IDP, and on successful login, returns
|
|
136
|
-
the user to your callback URL with a `code` parameter. You'll use `WorkOS::SSO.profile` to exchange the
|
|
137
|
-
code for a `WorkOS::Profile`.
|
|
138
|
-
|
|
139
|
-
```ruby
|
|
140
|
-
WorkOS::SSO.profile(code:, project_id:)</h4>
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
> Fetch a WorkOS::Profile for an authorized user.
|
|
144
|
-
|
|
145
|
-
`WorkOS::SSO.profile` accepts two arguments:
|
|
146
|
-
|
|
147
|
-
- `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
|
-
- `project_id` (string) — your application's WorkOS [Project ID](https://dashboard.workos.com/sso/configuration) (ex. `project_01JG3BCPTRTSTTWQR4VSHXGWCQ`)
|
|
149
|
-
|
|
150
|
-
This method will return an instance of a `WorkOS::Profile` with the following attributes:
|
|
151
|
-
|
|
152
|
-
```ruby
|
|
153
|
-
<WorkOS::Profile:0x00007fb6e4193d20
|
|
154
|
-
@id="prof_01DRA1XNSJDZ19A31F183ECQW5",
|
|
155
|
-
@email="demo@workos-okta.com",
|
|
156
|
-
@first_name="WorkOS",
|
|
157
|
-
@connection_id="conn_01EMH8WAK20T42N2NBMNBCYHAG",
|
|
158
|
-
@connection_type="OktaSAML",
|
|
159
|
-
@last_name="Demo",
|
|
160
|
-
@idp_id="00u1klkowm8EGah2H357",
|
|
161
|
-
@raw_attributes={
|
|
162
|
-
:id=>"prof_01DRA1XNSJDZ19A31F183ECQW5",
|
|
163
|
-
:email=>"demo@workos-okta.com",
|
|
164
|
-
:first_name=>"WorkOS",
|
|
165
|
-
:last_name=>"Demo",
|
|
166
|
-
:idp_id=>"00u1klkowm8EGah2H357"
|
|
167
|
-
},
|
|
168
|
-
>
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
Our Sintatra app can be extended to use this method:
|
|
172
|
-
|
|
173
|
-
```ruby
|
|
174
|
-
DOMAIN = 'example.com'
|
|
175
|
-
PROJECT_ID = '{projectId}'
|
|
176
|
-
REDIRECT_URI = 'http://localhost:4567/callback'
|
|
177
|
-
|
|
178
|
-
get '/auth' do
|
|
179
|
-
authorization_url = WorkOS::SSO.authorization_url(
|
|
180
|
-
domain: DOMAIN,
|
|
181
|
-
project_id: PROJECT_ID,
|
|
182
|
-
redirect_uri: REDIRECT_URI,
|
|
183
|
-
)
|
|
184
|
-
|
|
185
|
-
redirect authorization_url
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
get '/callback' do
|
|
189
|
-
profile = WorkOS::SSO.profile(
|
|
190
|
-
code: params['code'],
|
|
191
|
-
project_id: PROJECT_ID,
|
|
192
|
-
)
|
|
193
|
-
|
|
194
|
-
session[:user] = profile.to_json
|
|
195
|
-
|
|
196
|
-
redirect '/'
|
|
197
|
-
end
|
|
198
|
-
```
|
|
41
|
+
## More Information
|
|
199
42
|
|
|
200
|
-
|
|
43
|
+
* [Single Sign-On Guide](https://workos.com/docs/sso/guide)
|
|
44
|
+
* [Directory Sync Guide](https://workos.com/docs/directory-sync/guide)
|
|
45
|
+
* [Admin Portal Guide](https://workos.com/docs/admin-portal/guide)
|
|
46
|
+
* [Magic Link Guide](https://workos.com/docs/magic-link/guide)
|