workos 0.10.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.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -1
  3. data/.ruby-version +1 -1
  4. data/.semaphore/semaphore.yml +10 -4
  5. data/Gemfile.lock +49 -36
  6. data/LICENSE +1 -1
  7. data/README.md +13 -230
  8. data/lib/workos/client.rb +24 -6
  9. data/lib/workos/connection.rb +12 -1
  10. data/lib/workos/directory.rb +53 -0
  11. data/lib/workos/directory_group.rb +44 -0
  12. data/lib/workos/directory_sync.rb +63 -7
  13. data/lib/workos/directory_user.rb +63 -0
  14. data/lib/workos/organizations.rb +150 -0
  15. data/lib/workos/passwordless.rb +4 -0
  16. data/lib/workos/portal.rb +1 -81
  17. data/lib/workos/profile.rb +9 -12
  18. data/lib/workos/profile_and_token.rb +28 -0
  19. data/lib/workos/sso.rb +56 -104
  20. data/lib/workos/types/connection_struct.rb +3 -0
  21. data/lib/workos/types/directory_group_struct.rb +13 -0
  22. data/lib/workos/types/directory_struct.rb +16 -0
  23. data/lib/workos/types/directory_user_struct.rb +19 -0
  24. data/lib/workos/types/intent_enum.rb +1 -0
  25. data/lib/workos/types.rb +3 -0
  26. data/lib/workos/version.rb +1 -1
  27. data/lib/workos.rb +5 -0
  28. data/sorbet/rbi/gems/addressable.rbi +199 -0
  29. data/sorbet/rbi/gems/ast.rbi +49 -0
  30. data/sorbet/rbi/gems/codecov.rbi +37 -0
  31. data/sorbet/rbi/gems/crack.rbi +62 -0
  32. data/sorbet/rbi/gems/docile.rbi +36 -0
  33. data/sorbet/rbi/gems/hashdiff.rbi +66 -0
  34. data/sorbet/rbi/gems/parallel.rbi +83 -0
  35. data/sorbet/rbi/gems/parser.rbi +1429 -0
  36. data/sorbet/rbi/gems/public_suffix.rbi +104 -0
  37. data/sorbet/rbi/gems/rainbow.rbi +118 -0
  38. data/sorbet/rbi/gems/rake.rbi +644 -0
  39. data/sorbet/rbi/gems/regexp_parser.rbi +926 -0
  40. data/sorbet/rbi/gems/rexml.rbi +628 -0
  41. data/sorbet/rbi/gems/rspec-core.rbi +1898 -0
  42. data/sorbet/rbi/gems/rspec-expectations.rbi +1127 -0
  43. data/sorbet/rbi/gems/rspec-mocks.rbi +1099 -0
  44. data/sorbet/rbi/gems/rspec-support.rbi +280 -0
  45. data/sorbet/rbi/gems/rspec.rbi +15 -0
  46. data/sorbet/rbi/gems/rubocop-ast.rbi +1355 -0
  47. data/sorbet/rbi/gems/rubocop.rbi +7253 -0
  48. data/sorbet/rbi/gems/ruby-progressbar.rbi +304 -0
  49. data/sorbet/rbi/gems/simplecov-html.rbi +35 -0
  50. data/sorbet/rbi/gems/simplecov.rbi +406 -0
  51. data/sorbet/rbi/gems/unicode-display_width.rbi +17 -0
  52. data/sorbet/rbi/gems/vcr.rbi +572 -0
  53. data/sorbet/rbi/gems/webmock.rbi +556 -0
  54. data/sorbet/rbi/gems/yard.rbi +1165 -0
  55. data/sorbet/rbi/sorbet-typed/lib/rake/all/rake.rbi +645 -0
  56. data/sorbet/rbi/sorbet-typed/lib/rspec-core/all/rspec-core.rbi +1891 -0
  57. data/sorbet/rbi/sorbet-typed/lib/rubocop/~>0.85/rubocop.rbi +2072 -0
  58. data/sorbet/rbi/sorbet-typed/lib/yard/all/yard.rbi +1214 -0
  59. data/sorbet/rbi/todo.rbi +1 -3
  60. data/spec/lib/workos/audit_trail_spec.rb +0 -8
  61. data/spec/lib/workos/directory_sync_spec.rb +347 -40
  62. data/spec/lib/workos/organizations_spec.rb +164 -0
  63. data/spec/lib/workos/passwordless_spec.rb +0 -8
  64. data/spec/lib/workos/portal_spec.rb +17 -123
  65. data/spec/lib/workos/sso_spec.rb +172 -173
  66. data/spec/spec_helper.rb +2 -1
  67. data/spec/support/fixtures/vcr_cassettes/directory_sync/delete_directory.yml +72 -0
  68. data/spec/support/fixtures/vcr_cassettes/{sso/list_connections.yml → directory_sync/list_directories/with_after.yml} +7 -7
  69. data/spec/support/fixtures/vcr_cassettes/{sso/list_connections_with_limit_param.yml → directory_sync/list_directories/with_before.yml} +8 -8
  70. data/spec/support/fixtures/vcr_cassettes/{sso/list_connections_with_connection_type_param.yml → directory_sync/list_directories/with_domain.yml} +11 -10
  71. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_limit.yml +74 -0
  72. data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_directories.yml → list_directories/with_no_options.yml} +1 -1
  73. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_search.yml +73 -0
  74. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_after.yml +76 -0
  75. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_before.yml +74 -0
  76. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_directory.yml +78 -0
  77. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_limit.yml +74 -0
  78. data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_groups.yml → list_groups/with_no_options.yml} +16 -6
  79. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_user.yml +72 -0
  80. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_after.yml +86 -0
  81. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_before.yml +75 -0
  82. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_directory.yml +93 -0
  83. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_group.yml +76 -0
  84. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_limit.yml +75 -0
  85. data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_users.yml → list_users/with_no_options.yml} +16 -6
  86. data/spec/support/fixtures/vcr_cassettes/organization/get.yml +73 -0
  87. data/spec/support/fixtures/vcr_cassettes/organization/get_invalid.yml +72 -0
  88. data/spec/support/fixtures/vcr_cassettes/organization/update.yml +73 -0
  89. data/spec/support/fixtures/vcr_cassettes/organization/update_invalid.yml +73 -0
  90. data/spec/support/fixtures/vcr_cassettes/portal/generate_link_dsync.yml +72 -0
  91. data/spec/support/fixtures/vcr_cassettes/portal/{generate_link.yml → generate_link_sso.yml} +1 -1
  92. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_after.yml +73 -0
  93. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_before.yml +73 -0
  94. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_connection_type.yml +73 -0
  95. data/spec/support/fixtures/vcr_cassettes/sso/{list_connections_with_domain_param.yml → list_connections/with_domain.yml} +6 -6
  96. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_limit.yml +74 -0
  97. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_no_options.yml +73 -0
  98. data/spec/support/fixtures/vcr_cassettes/sso/{list_connections_with_before_param.yml → list_connections/with_organization_id.yml} +7 -8
  99. data/spec/support/fixtures/vcr_cassettes/sso/profile.yml +74 -0
  100. data/workos.gemspec +2 -0
  101. metadata +114 -43
  102. data/sorbet/rbi/hidden-definitions/errors.txt +0 -24896
  103. data/sorbet/rbi/hidden-definitions/hidden.rbi +0 -38411
  104. data/sorbet/rbi/sorbet-typed/lib/bundler/all/bundler.rbi +0 -8684
  105. data/sorbet/rbi/sorbet-typed/lib/ruby/all/gem.rbi +0 -4222
  106. data/sorbet/rbi/sorbet-typed/lib/ruby/all/open3.rbi +0 -111
  107. data/sorbet/rbi/sorbet-typed/lib/ruby/all/resolv.rbi +0 -543
  108. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories_with_domain_param.yml +0 -63
  109. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups_with_directory_param.yml +0 -62
  110. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users_with_directory_param.yml +0 -62
  111. data/spec/support/fixtures/vcr_cassettes/sso/create_connection_with_invalid_source.yml +0 -58
  112. data/spec/support/fixtures/vcr_cassettes/sso/create_connection_with_valid_source.yml +0 -63
  113. data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_after_param.yml +0 -72
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72c11606b98be63db5dab6a2c68eb69cab12ce9f9afe20b73475ce6948b24794
4
- data.tar.gz: c7ea54043041810b71e2390b3efe20152870d8617da9a48a9922c775fb01f5d4
3
+ metadata.gz: 7d48c12ff6a0a470ca2a35fb76cabf17fe9d4f2444b11811891a9ea0c81f9cda
4
+ data.tar.gz: ec43b59ca57135efd145346ce14ebab1ed30341f210b3a47f8525afb907d3856
5
5
  SHA512:
6
- metadata.gz: 8721f09bdcabce0772ffd6218b11859bbbdddb096f7d85c1b56b1f1b28816b8e2d86ef45838311e37c5c7bb322ffb2836d4ff355d8268ee15bbfcded71f1f658
7
- data.tar.gz: 74b8126bedbd7c2f36da24376af99f2502d5ba3ac062c9067515d1fa6c5c402684ae0c6a3d2cfa42ee0ea61cbf75329b861a6362aa8fd7af361e58f8fff0604d
6
+ metadata.gz: 2068f4bd90b52d90b802eea6f1e8ebeb2a5e1b166d5256d952df40af30821bd858999813532f18e9ab44eff36f4cde40a27f423126028509fe9c12f15ef07d58
7
+ data.tar.gz: 526f33fd44a2371696dc19f400461af7e170e362d7057bf04529767eae8692d12b8e56635f6b61d5b0e8c585f2275e65e62422f064bbe056645c2c0cc1cfe14f
data/.rubocop.yml CHANGED
@@ -13,10 +13,12 @@ Metrics/BlockLength:
13
13
  Metrics/MethodLength:
14
14
  Max: 15
15
15
  Metrics/ModuleLength:
16
- Max: 150
16
+ Max: 200
17
17
  Metrics/ParameterLists:
18
18
  Max: 6
19
19
  Style/TrailingCommaInArguments:
20
20
  EnforcedStyleForMultiline: 'consistent_comma'
21
21
  Style/TrailingCommaInHashLiteral:
22
22
  EnforcedStyleForMultiline: 'consistent_comma'
23
+ AllCops:
24
+ TargetRubyVersion: 2.5
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.1
1
+ 3.0.1
@@ -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
@@ -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.1
63
+ - name: Ruby 2.7.3
64
64
  commands:
65
65
  - checkout
66
- - sem-version ruby 2.7.1
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.10.0)
4
+ workos (1.1.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.0)
13
- codecov (0.2.8)
12
+ ast (2.4.2)
13
+ codecov (0.2.12)
14
14
  json
15
15
  simplecov
16
- crack (0.4.3)
17
- safe_yaml (~> 1.0.0)
18
- diff-lcs (1.3)
19
- docile (1.3.2)
20
- hashdiff (1.0.0)
21
- jaro_winkler (1.5.4)
22
- json (2.3.1)
23
- parallel (1.19.1)
24
- parser (2.7.0.0)
25
- ast (~> 2.4.0)
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.1)
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.0)
34
- rspec-support (~> 3.9.0)
35
- rspec-expectations (3.9.0)
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.0)
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.0)
42
- rubocop (0.78.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.6)
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, < 1.7)
49
- ruby-progressbar (1.10.1)
50
- safe_yaml (1.0.5)
51
- simplecov (0.19.0)
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
- simplecov-html (0.12.2)
55
- sorbet (0.5.5560)
56
- sorbet-static (= 0.5.5560)
57
- sorbet-runtime (0.5.6189)
58
- sorbet-static (0.5.5560-universal-darwin-14)
59
- unicode-display_width (1.6.0)
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.6424)
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.7.6)
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.22)
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.1.4
96
+ 2.2.16
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019 WorkOS
3
+ Copyright (c) 2021 WorkOS
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,22 +1,22 @@
1
- # workos-ruby [![codecov](https://codecov.io/gh/workos-inc/workos-ruby/branch/master/graph/badge.svg)](https://codecov.io/gh/workos-inc/workos-ruby)
1
+ # WorkOS Ruby Library
2
2
 
3
- WorkOS official Ruby gem for interacting with WorkOS APIs
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
- Complete documentation for the latest version of WorkOS Ruby Gem can be found [here](https://workos-inc.github.io/workos-ruby/).
7
+ See the [API Reference](https://workos.com/docs/reference/client-libraries) for Ruby usage examples.
8
8
 
9
9
  ## Installation
10
10
 
11
- To get started, you can install the WorkOS gem via RubyGems with:
11
+ Install the package with:
12
12
 
13
- ```ruby
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
- ```ruby
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 SDK you must first provide your API key from the [WorkOS Developer Dashboard](https://dashboard.workos.com/api-keys).
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
- Alternatively, you may set the key yourself, such as in an initializer in your application load path:
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,222 +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
- ## The SSO Module
46
-
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.
48
-
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
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
51
- using the `WorkOS::SSO.get_profile` method.
52
-
53
- See our Ruby SSO example app for a [complete example](https://github.com/workos-inc/ruby-sso-example).
54
-
55
- ```ruby
56
- WorkOS::SSO.authorization_url(domain:, client_id:, redirect_uri:, state: {})
57
- ```
58
-
59
- > Generate an authorization URL to intitiate the WorkOS OAuth2 workflow.
60
-
61
- `WorkOS::SSO.authorization_url` accepts four arguments:
62
-
63
- - `domain` (string) — the authenticating user's company domain, without protocol (ex. `example.com`)
64
- - `client_id` (string) — your application's WorkOS [Client ID](https://dashboard.workos.com/sso/configuration) (ex. `project_01JG3BCPTRTSTTWQR4VSHXGWCQ`)
65
- - `state` (optional, hash) — an optional hash used to manage state across authorization transactions (ex. `{ next_page: '/docs'}`)
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.
67
-
68
- This method will return an OAuth2 query string of the form:
69
-
70
- `https://${domain}/sso/authorize?response_type=code&client_id=${clientID}&redirect_uri=${redirectURI}&state=${state}`
71
-
72
- For example, when used in a [Sinatra app](http://sinatrarb.com/):
73
-
74
- ```ruby
75
- DOMAIN = 'example.com'
76
- CLIENT_ID = '{clientId}'
77
- REDIRECT_URI = 'http://localhost:4567/callback'
78
-
79
- get '/auth' do
80
- authorization_url = WorkOS::SSO.authorization_url(
81
- domain: DOMAIN,
82
- client_id: CLIENT_ID,
83
- redirect_uri: REDIRECT_URI,
84
- )
85
-
86
- redirect authorization_url
87
- end
88
- ```
89
-
90
- The user would be redirected to:
91
-
92
- `https://api.workos.com/sso/authorize?response_type=code&client_id={clientID}&redirect_uri=http://localhost:4567/callback`
93
-
94
- WorkOS takes over from here, sending the user to authenticate with their IDP, and on successful login, returns
95
- the user to your callback URL with a `code` parameter. You'll use `WorkOS::SSO.profile` to exchange the
96
- code for a `WorkOS::Profile`.
97
-
98
- ```ruby
99
- WorkOS::SSO.profile(code:, client_id:)
100
- ```
101
-
102
- > Fetch a WorkOS::Profile for an authorized user.
103
-
104
- `WorkOS::SSO.profile` accepts two arguments:
105
-
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
107
- - `client_id` (string) — your application's WorkOS [Client ID](https://dashboard.workos.com/sso/configuration) (ex. `project_01JG3BCPTRTSTTWQR4VSHXGWCQ`)
108
-
109
- This method will return an instance of a `WorkOS::Profile` with the following attributes:
110
-
111
- ```ruby
112
- <WorkOS::Profile:0x00007fb6e4193d20
113
- @id="prof_01DRA1XNSJDZ19A31F183ECQW5",
114
- @email="demo@workos-okta.com",
115
- @first_name="WorkOS",
116
- @connection_id="conn_01EMH8WAK20T42N2NBMNBCYHAG",
117
- @connection_type="OktaSAML",
118
- @last_name="Demo",
119
- @idp_id="00u1klkowm8EGah2H357",
120
- @raw_attributes={
121
- :id=>"prof_01DRA1XNSJDZ19A31F183ECQW5",
122
- :email=>"demo@workos-okta.com",
123
- :first_name=>"WorkOS",
124
- :last_name=>"Demo",
125
- :idp_id=>"00u1klkowm8EGah2H357"
126
- },
127
- >
128
- ```
129
-
130
- Our Sinatra app can be extended to use this method:
131
-
132
- ```ruby
133
- DOMAIN = 'example.com'
134
- CLIENT_ID = '{clientId}'
135
- REDIRECT_URI = 'http://localhost:4567/callback'
136
-
137
- get '/auth' do
138
- authorization_url = WorkOS::SSO.authorization_url(
139
- domain: DOMAIN,
140
- client_id: CLIENT_ID,
141
- redirect_uri: REDIRECT_URI,
142
- )
143
-
144
- redirect authorization_url
145
- end
146
-
147
- get '/callback' do
148
- profile = WorkOS::SSO.profile(
149
- code: params['code'],
150
- client_id: CLIENT_ID,
151
- )
152
-
153
- session[:user] = profile.to_json
154
-
155
- redirect '/'
156
- end
157
- ```
158
-
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
- ```
41
+ ## More Information
260
42
 
261
- See our [API
262
- Reference](https://docs.workos.com/audit-trail/api-reference#idempotency)
263
- for more information on idempotency keys.
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)
data/lib/workos/client.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: false
3
3
 
4
4
  module WorkOS
5
5
  # A Net::HTTP based API client for interacting with the WorkOS API
@@ -19,7 +19,7 @@ module WorkOS
19
19
 
20
20
  sig do
21
21
  params(
22
- request: T.any(Net::HTTP::Get, Net::HTTP::Post, Net::HTTP::Delete),
22
+ request: T.any(Net::HTTP::Get, Net::HTTP::Post, Net::HTTP::Delete, Net::HTTP::Put),
23
23
  ).returns(::T.untyped)
24
24
  end
25
25
  def execute_request(request:)
@@ -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
@@ -90,6 +91,23 @@ module WorkOS
90
91
  request
91
92
  end
92
93
 
94
+ sig do
95
+ params(
96
+ path: String,
97
+ auth: T.nilable(T::Boolean),
98
+ idempotency_key: T.nilable(String),
99
+ body: T.nilable(Hash),
100
+ ).returns(Net::HTTP::Put)
101
+ end
102
+ def put_request(path:, auth: false, idempotency_key: nil, body: nil)
103
+ request = Net::HTTP::Put.new(path, 'Content-Type' => 'application/json')
104
+ request.body = body.to_json if body
105
+ request['Authorization'] = "Bearer #{WorkOS.key!}" if auth
106
+ request['Idempotency-Key'] = idempotency_key if idempotency_key
107
+ request['User-Agent'] = user_agent
108
+ request
109
+ end
110
+
93
111
  sig { returns(String) }
94
112
  def user_agent
95
113
  engine = defined?(::RUBY_ENGINE) ? ::RUBY_ENGINE : 'Ruby'
@@ -102,7 +120,7 @@ module WorkOS
102
120
  ].join('; ')
103
121
  end
104
122
 
105
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
123
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
106
124
  sig { params(response: ::T.untyped).void }
107
125
  def handle_error_response(response:)
108
126
  http_status = response.code.to_i
@@ -139,7 +157,7 @@ module WorkOS
139
157
  )
140
158
  end
141
159
  end
142
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
160
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
143
161
 
144
162
  private
145
163
 
@@ -5,10 +5,12 @@ module WorkOS
5
5
  # The Connection class provides a lightweight wrapper around
6
6
  # a WorkOS Connection resource. This class is not meant to be instantiated
7
7
  # in user space, and is instantiated internally but exposed.
8
+ # Note: status is deprecated - use state instead
8
9
  class Connection
9
10
  extend T::Sig
10
11
 
11
- attr_accessor :id, :name, :connection_type, :domains
12
+ attr_accessor :id, :name, :connection_type, :domains, :organization_id,
13
+ :state, :status
12
14
 
13
15
  sig { params(json: String).void }
14
16
  def initialize(json)
@@ -18,6 +20,9 @@ module WorkOS
18
20
  @name = T.let(raw.name, String)
19
21
  @connection_type = T.let(raw.connection_type, String)
20
22
  @domains = T.let(raw.domains, Array)
23
+ @organization_id = T.let(raw.organization_id, String)
24
+ @state = T.let(raw.state, String)
25
+ @status = T.let(raw.status, String)
21
26
  end
22
27
 
23
28
  def to_json(*)
@@ -26,6 +31,9 @@ module WorkOS
26
31
  name: name,
27
32
  connection_type: connection_type,
28
33
  domains: domains,
34
+ organization_id: organization_id,
35
+ state: state,
36
+ status: status,
29
37
  }
30
38
  end
31
39
 
@@ -40,6 +48,9 @@ module WorkOS
40
48
  name: hash[:name],
41
49
  connection_type: hash[:connection_type],
42
50
  domains: hash[:domains],
51
+ organization_id: hash[:organization_id],
52
+ state: hash[:state],
53
+ status: hash[:status],
43
54
  )
44
55
  end
45
56
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ module WorkOS
5
+ # The Directory class provides a lightweight wrapper around
6
+ # a WorkOS Directory resource. This class is not meant to be instantiated
7
+ # in user space, and is instantiated internally but exposed.
8
+ class Directory
9
+ extend T::Sig
10
+
11
+ attr_accessor :id, :domain, :name, :type, :state
12
+
13
+ sig { params(json: String).void }
14
+ def initialize(json)
15
+ raw = parse_json(json)
16
+
17
+ @id = T.let(raw.id, String)
18
+ @name = T.let(raw.name, String)
19
+ @domain = T.let(raw.domain, String)
20
+ @type = T.let(raw.type, String)
21
+ @state = T.let(raw.state, String)
22
+ end
23
+
24
+ def to_json(*)
25
+ {
26
+ id: id,
27
+ name: name,
28
+ domain: domain,
29
+ type: type,
30
+ state: state,
31
+ }
32
+ end
33
+
34
+ private
35
+
36
+ sig do
37
+ params(
38
+ json_string: String,
39
+ ).returns(WorkOS::Types::DirectoryStruct)
40
+ end
41
+ def parse_json(json_string)
42
+ hash = JSON.parse(json_string, symbolize_names: true)
43
+
44
+ WorkOS::Types::DirectoryStruct.new(
45
+ id: hash[:id],
46
+ name: hash[:name],
47
+ domain: hash[:domain],
48
+ type: hash[:type],
49
+ state: hash[:state],
50
+ )
51
+ end
52
+ end
53
+ end