workos 5.3.0 → 6.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 (90) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +1 -1
  3. data/.github/workflows/ci.yml +2 -4
  4. data/.github/workflows/lint-pr-title.yml +20 -0
  5. data/.github/workflows/release-please.yml +25 -0
  6. data/.github/workflows/release.yml +22 -25
  7. data/.gitignore +1 -0
  8. data/.release-please-manifest.json +3 -0
  9. data/.rubocop.yml +11 -8
  10. data/.rubocop_todo.yml +94 -0
  11. data/.ruby-version +1 -1
  12. data/CHANGELOG.md +15 -0
  13. data/Gemfile.lock +32 -18
  14. data/Rakefile +8 -0
  15. data/context7.json +4 -0
  16. data/lib/workos/authentication_response.rb +32 -4
  17. data/lib/workos/cache.rb +94 -0
  18. data/lib/workos/client.rb +9 -1
  19. data/lib/workos/directory_sync.rb +1 -1
  20. data/lib/workos/directory_user.rb +31 -3
  21. data/lib/workos/encryptors/aes_gcm.rb +49 -0
  22. data/lib/workos/encryptors.rb +9 -0
  23. data/lib/workos/errors.rb +4 -0
  24. data/lib/workos/feature_flag.rb +34 -0
  25. data/lib/workos/mfa.rb +0 -1
  26. data/lib/workos/oauth_tokens.rb +29 -0
  27. data/lib/workos/organization.rb +14 -1
  28. data/lib/workos/organization_membership.rb +5 -1
  29. data/lib/workos/organizations.rb +87 -3
  30. data/lib/workos/profile.rb +10 -2
  31. data/lib/workos/refresh_authentication_response.rb +29 -2
  32. data/lib/workos/role.rb +38 -0
  33. data/lib/workos/session.rb +187 -0
  34. data/lib/workos/sso.rb +3 -24
  35. data/lib/workos/types/intent.rb +3 -1
  36. data/lib/workos/types/provider.rb +1 -1
  37. data/lib/workos/types/widget_scope.rb +15 -0
  38. data/lib/workos/types.rb +1 -0
  39. data/lib/workos/user.rb +7 -1
  40. data/lib/workos/user_management/session.rb +57 -0
  41. data/lib/workos/user_management.rb +213 -45
  42. data/lib/workos/version.rb +1 -1
  43. data/lib/workos/widgets.rb +46 -0
  44. data/lib/workos.rb +8 -0
  45. data/release-please-config.json +12 -0
  46. data/spec/lib/workos/cache_spec.rb +94 -0
  47. data/spec/lib/workos/directory_user_spec.rb +13 -3
  48. data/spec/lib/workos/encryptors/aes_gcm_spec.rb +41 -0
  49. data/spec/lib/workos/organizations_spec.rb +258 -1
  50. data/spec/lib/workos/portal_spec.rb +30 -0
  51. data/spec/lib/workos/role_spec.rb +142 -0
  52. data/spec/lib/workos/session_spec.rb +475 -0
  53. data/spec/lib/workos/sso_spec.rb +106 -5
  54. data/spec/lib/workos/user_management_spec.rb +496 -1
  55. data/spec/lib/workos/widgets_spec.rb +73 -0
  56. data/spec/support/fixtures/vcr_cassettes/directory_sync/get_user.yml +1 -1
  57. data/spec/support/fixtures/vcr_cassettes/organization/create_with_external_id.yml +83 -0
  58. data/spec/support/fixtures/vcr_cassettes/organization/list_organization_feature_flags.yml +78 -0
  59. data/spec/support/fixtures/vcr_cassettes/organization/list_organization_roles.yml +82 -0
  60. data/spec/support/fixtures/vcr_cassettes/organization/update_with_external_id.yml +78 -0
  61. data/spec/support/fixtures/vcr_cassettes/organization/update_with_external_id_null.yml +78 -0
  62. data/spec/support/fixtures/vcr_cassettes/organization/update_with_stripe_customer_id.yml +78 -0
  63. data/spec/support/fixtures/vcr_cassettes/organization/update_without_name.yml +85 -0
  64. data/spec/support/fixtures/vcr_cassettes/portal/generate_link_certificate_renewal.yml +72 -0
  65. data/spec/support/fixtures/vcr_cassettes/portal/generate_link_domain_verification.yml +72 -0
  66. data/spec/support/fixtures/vcr_cassettes/sso/profile.yml +1 -1
  67. data/spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_code/valid_with_oauth_tokens.yml +82 -0
  68. data/spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_password/unverified.yml +82 -0
  69. data/spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_refresh_token/valid.yml +79 -78
  70. data/spec/support/fixtures/vcr_cassettes/user_management/create_organization_membership/valid_multiple_roles.yml +76 -0
  71. data/spec/support/fixtures/vcr_cassettes/user_management/create_user_with_external_id.yml +77 -0
  72. data/spec/support/fixtures/vcr_cassettes/user_management/get_user.yml +1 -1
  73. data/spec/support/fixtures/vcr_cassettes/user_management/list_sessions/valid.yml +38 -0
  74. data/spec/support/fixtures/vcr_cassettes/user_management/resend_invitation/accepted.yml +83 -0
  75. data/spec/support/fixtures/vcr_cassettes/user_management/resend_invitation/expired.yml +83 -0
  76. data/spec/support/fixtures/vcr_cassettes/user_management/resend_invitation/invalid.yml +83 -0
  77. data/spec/support/fixtures/vcr_cassettes/user_management/resend_invitation/revoked.yml +83 -0
  78. data/spec/support/fixtures/vcr_cassettes/user_management/resend_invitation/valid.yml +83 -0
  79. data/spec/support/fixtures/vcr_cassettes/user_management/reset_password/valid.yml +1 -1
  80. data/spec/support/fixtures/vcr_cassettes/user_management/update_organization_membership/valid_multiple_roles.yml +76 -0
  81. data/spec/support/fixtures/vcr_cassettes/user_management/update_user/email.yml +82 -0
  82. data/spec/support/fixtures/vcr_cassettes/user_management/update_user/locale.yml +76 -0
  83. data/spec/support/fixtures/vcr_cassettes/user_management/update_user/valid.yml +2 -2
  84. data/spec/support/fixtures/vcr_cassettes/user_management/update_user_external_id_null.yml +77 -0
  85. data/spec/support/fixtures/vcr_cassettes/widgets/get_token.yml +82 -0
  86. data/spec/support/fixtures/vcr_cassettes/widgets/get_token_invalid_organization_id.yml +74 -0
  87. data/spec/support/fixtures/vcr_cassettes/widgets/get_token_invalid_user_id.yml +74 -0
  88. data/spec/support/profile.txt +1 -1
  89. data/workos.gemspec +7 -3
  90. metadata +132 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e386ae2dd110ea57c1a5c8d15c09c68263dedbee77c6ffa015b84a952d88920
4
- data.tar.gz: e5001300c2da182fd3a230e66c7ced29ef937c8f0774cbd51d1f4e8bc9b8ee45
3
+ metadata.gz: 2c2b3e2f56e5f5ffc2d59d27eb6613c018b24ec57ff270ed9e95730a46aafdc6
4
+ data.tar.gz: 6e001f5af6046daf9b640f570cd7318767fc106e90cdf3c9e7f8a3b0c11d1b3b
5
5
  SHA512:
6
- metadata.gz: d7882eb8eaef394157785a2592bcb616fa2bd4a7b9015b0b8b37c203ea70ccf43b72c5eb10bbde9155938154d9fc3a2ab5f1e630330efd2eeb53f2672bea65fe
7
- data.tar.gz: 0fb86220b0b5fe4dbbcdaa24b35586348d961a40c1628b5eebf44926e7c0a0350ea538b3dcc9610e073c654c65ab5f7d9ada0edb4196bc93b8d9994a3739c7f2
6
+ metadata.gz: aa0bdfff2eb4de65c9bd5679be9f44b36df9eafd5eb8d3826f490d435825f61f3df32768e77b8954df538a3e3af2963aaba3fe23c89148b7f7619d83ea349c46
7
+ data.tar.gz: 6ae668143797a324cea0db2d9d779fe803c13f9defc62d707bb7b4419ba931a71d12ff5dd4bdc17da5c6c284623b1484a111817a1294e1f02f0e1e741dd15781
data/.github/CODEOWNERS CHANGED
@@ -2,4 +2,4 @@
2
2
  # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners
3
3
 
4
4
  # Rubyist Team
5
- * @workos-inc/ruby
5
+ * @workos/ruby
@@ -17,13 +17,11 @@ jobs:
17
17
  strategy:
18
18
  matrix:
19
19
  ruby:
20
- - '2.7'
21
- - '3.0'
22
20
  - '3.1'
23
21
  - '3.2'
24
22
  steps:
25
- - uses: actions/checkout@v4
26
- - uses: ruby/setup-ruby@v1
23
+ - uses: actions/checkout@v6
24
+ - uses: ruby/setup-ruby@675dd7ba1b06c8786a1480d89c384f5620a42647 # v1.281.0
27
25
  with:
28
26
  ruby-version: ${{ matrix.ruby }}
29
27
  bundler-cache: true
@@ -0,0 +1,20 @@
1
+ name: Lint PR Title
2
+
3
+ on:
4
+ pull_request_target:
5
+ types:
6
+ - opened
7
+ - edited
8
+ - synchronize
9
+
10
+ permissions:
11
+ pull-requests: read
12
+
13
+ jobs:
14
+ main:
15
+ name: Validate PR title
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - uses: amannn/action-semantic-pull-request@v6
19
+ env:
20
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,25 @@
1
+ name: Release Please
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ permissions:
9
+ contents: write
10
+ pull-requests: write
11
+
12
+ jobs:
13
+ release-please:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - name: Generate token
17
+ id: generate-token
18
+ uses: actions/create-github-app-token@v2
19
+ with:
20
+ app-id: ${{ vars.SDK_BOT_APP_ID }}
21
+ private-key: ${{ secrets.SDK_BOT_PRIVATE_KEY }}
22
+
23
+ - uses: googleapis/release-please-action@v4
24
+ with:
25
+ token: ${{ steps.generate-token.outputs.token }}
@@ -1,43 +1,40 @@
1
1
  name: Release
2
2
 
3
3
  on:
4
- # Support manually pushing a new release
5
- workflow_dispatch: {}
6
- # Trigger when a release is published
7
4
  release:
8
- types: [released]
5
+ types: [published]
9
6
 
10
7
  defaults:
11
8
  run:
12
9
  shell: bash
13
10
 
14
11
  jobs:
15
- test:
12
+ publish:
16
13
  name: Publish to RubyGems
17
14
  runs-on: ubuntu-latest
15
+ permissions:
16
+ id-token: write
17
+ contents: read
18
18
  steps:
19
- - uses: actions/checkout@v4
20
- - uses: ruby/setup-ruby@v1
19
+ - name: Configure RubyGems credentials
20
+ uses: rubygems/configure-rubygems-credentials@main
21
21
  with:
22
- ruby-version: '3.2'
23
- bundler-cache: true
24
-
25
- - name: Spec
26
- run: |
27
- bundle exec rspec
22
+ role-to-assume: rg_oidc_akr_fn8dx45asckvmsnd2kka
28
23
 
29
- - name: Publish
30
- env:
31
- RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
32
- run: |
33
- mkdir -p ~/.gem
24
+ - name: Checkout
25
+ uses: actions/checkout@v6
34
26
 
35
- cat << EOF > ~/.gem/credentials
36
- ---
37
- :rubygems_api_key: ${RUBYGEMS_API_KEY}
38
- EOF
27
+ - name: Setup Ruby
28
+ uses: ruby/setup-ruby@v1
29
+ with:
30
+ ruby-version: "3.2"
31
+ bundler-cache: true
39
32
 
40
- chmod 0600 ~/.gem/credentials
33
+ - name: Run tests
34
+ run: bundle exec rspec
41
35
 
42
- bundle exec gem build workos --output=release.gem
43
- bundle exec gem push release.gem
36
+ - name: Publish to RubyGems
37
+ run: |
38
+ VERSION="${GITHUB_REF_NAME#v}"
39
+ bundle exec rake build
40
+ gem push pkg/workos-${VERSION}.gem --host https://rubygems.org
data/.gitignore CHANGED
@@ -49,3 +49,4 @@
49
49
  # .rubocop-https?--*
50
50
 
51
51
  .vscode
52
+ .idea/
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "6.1.0"
3
+ }
data/.rubocop.yml CHANGED
@@ -1,6 +1,5 @@
1
- # Disabling due to conflict with Ruby 2.7/3.1
2
- Layout/BlockAlignment:
3
- Enabled: false
1
+ inherit_from: .rubocop_todo.yml
2
+
4
3
  Layout/DotPosition:
5
4
  EnforcedStyle: trailing
6
5
  Layout/EmptyLineAfterMagicComment:
@@ -8,15 +7,19 @@ Layout/EmptyLineAfterMagicComment:
8
7
  Layout/EmptyLines:
9
8
  Enabled: false
10
9
  Layout/LineLength:
11
- IgnoredPatterns:
10
+ AllowedPatterns:
12
11
  - 'VCR\.use_cassette'
13
12
  - '(\A|\s)/.*?/'
14
13
  Metrics/BlockLength:
15
- ExcludedMethods: ['describe', 'context', 'before']
14
+ AllowedMethods: ['describe', 'context', 'before', 'it']
15
+ Metrics/ClassLength:
16
+ Enabled: false
17
+ Metrics/CyclomaticComplexity:
18
+ Enabled: false
16
19
  Metrics/MethodLength:
17
- Max: 30
20
+ Enabled: false
18
21
  Metrics/ModuleLength:
19
- Max: 200
22
+ Enabled: false
20
23
  Metrics/ParameterLists:
21
24
  Max: 6
22
25
  Naming/ConstantName:
@@ -28,4 +31,4 @@ Style/TrailingCommaInArguments:
28
31
  Style/TrailingCommaInHashLiteral:
29
32
  EnforcedStyleForMultiline: 'consistent_comma'
30
33
  AllCops:
31
- TargetRubyVersion: 2.7
34
+ TargetRubyVersion: 3.1
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,94 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2025-01-22 21:38:20 UTC using RuboCop version 1.71.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # This cop supports safe autocorrection (--autocorrect).
11
+ # Configuration parameters: EnforcedStyleAlignWith.
12
+ # SupportedStylesAlignWith: either, start_of_block, start_of_line
13
+ Layout/BlockAlignment:
14
+ Exclude:
15
+ - 'spec/lib/workos/session_spec.rb'
16
+
17
+ # Offense count: 2
18
+ # This cop supports safe autocorrection (--autocorrect).
19
+ Layout/EmptyLinesAroundMethodBody:
20
+ Exclude:
21
+ - 'lib/workos/mfa.rb'
22
+ - 'lib/workos/user_management.rb'
23
+
24
+ # Offense count: 1
25
+ # This cop supports safe autocorrection (--autocorrect).
26
+ Layout/SpaceAroundMethodCallOperator:
27
+ Exclude:
28
+ - 'spec/lib/workos/directory_sync_spec.rb'
29
+
30
+ # Offense count: 1
31
+ # This cop supports unsafe autocorrection (--autocorrect-all).
32
+ Lint/DuplicateRequire:
33
+ Exclude:
34
+ - 'lib/workos/session.rb'
35
+
36
+ # Offense count: 3
37
+ # Configuration parameters: AllowedParentClasses.
38
+ Lint/MissingSuper:
39
+ Exclude:
40
+ - 'lib/workos/directory_group.rb'
41
+ - 'lib/workos/directory_user.rb'
42
+ - 'lib/workos/errors.rb'
43
+
44
+ # Offense count: 5
45
+ # Configuration parameters: CountComments, CountAsOne.
46
+ Metrics/ClassLength:
47
+ Max: 624
48
+
49
+ # Offense count: 8
50
+ # This cop supports safe autocorrection (--autocorrect).
51
+ # Configuration parameters: EnforcedStyle.
52
+ # SupportedStyles: separated, grouped
53
+ Style/AccessorGrouping:
54
+ Exclude:
55
+ - 'lib/workos/errors.rb'
56
+
57
+ # Offense count: 34
58
+ # This cop supports safe autocorrection (--autocorrect).
59
+ # Configuration parameters: EnforcedStyle.
60
+ # SupportedStyles: braces, no_braces
61
+ Style/HashAsLastArrayItem:
62
+ Exclude:
63
+ - 'spec/lib/workos/directory_sync_spec.rb'
64
+ - 'spec/lib/workos/event_spec.rb'
65
+ - 'spec/lib/workos/organizations_spec.rb'
66
+ - 'spec/lib/workos/sso_spec.rb'
67
+ - 'spec/lib/workos/user_management_spec.rb'
68
+
69
+ # Offense count: 2
70
+ # This cop supports safe autocorrection (--autocorrect).
71
+ Style/KeywordParametersOrder:
72
+ Exclude:
73
+ - 'lib/workos/organizations.rb'
74
+
75
+ # Offense count: 3
76
+ # This cop supports unsafe autocorrection (--autocorrect-all).
77
+ # Configuration parameters: SafeForConstants.
78
+ Style/RedundantFetchBlock:
79
+ Exclude:
80
+ - 'spec/lib/workos/cache_spec.rb'
81
+
82
+ # Offense count: 1
83
+ # This cop supports safe autocorrection (--autocorrect).
84
+ # Configuration parameters: AllowMultipleReturnValues.
85
+ Style/RedundantReturn:
86
+ Exclude:
87
+ - 'lib/workos/directory_user.rb'
88
+
89
+ # Offense count: 2
90
+ # This cop supports unsafe autocorrection (--autocorrect-all).
91
+ Style/SlicingWithRange:
92
+ Exclude:
93
+ - 'lib/workos/deprecated_hash_wrapper.rb'
94
+ - 'lib/workos/session.rb'
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.0.2
1
+ 3.1.4
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ ## [6.1.0](https://github.com/workos/workos-ruby/compare/workos-v6.0.0...workos/v6.1.0) (2026-02-10)
4
+
5
+
6
+ ### Features
7
+
8
+ * add support for totp_secret ([#300](https://github.com/workos/workos-ruby/issues/300)) ([c0a26bf](https://github.com/workos/workos-ruby/commit/c0a26bf745fb49ebaac7c5241e99d51188b886bb))
9
+ * Include Feature Flags decoded from the JWT in the payload of a Session ([#386](https://github.com/workos/workos-ruby/issues/386)) ([31a0e79](https://github.com/workos/workos-ruby/commit/31a0e7901247652182dcaad95e131357b93d0d71))
10
+ * **workos-ruby:** Add `connection` to `authorization_url` ([#78](https://github.com/workos/workos-ruby/issues/78)) ([c3a0e8e](https://github.com/workos/workos-ruby/commit/c3a0e8e4031a3ee888d925c11f1fd2fb152f0a16))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * add `invitation_token` parameter to authentication methods ([#438](https://github.com/workos/workos-ruby/issues/438)) ([d24e3dc](https://github.com/workos/workos-ruby/commit/d24e3dc2995de26970415e4570a7ed810d432715))
data/Gemfile.lock CHANGED
@@ -1,7 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- workos (5.3.0)
4
+ workos (6.1.0)
5
+ encryptor (~> 3.0)
6
+ jwt (~> 3.1)
5
7
 
6
8
  GEM
7
9
  remote: https://rubygems.org/
@@ -9,21 +11,28 @@ GEM
9
11
  addressable (2.8.6)
10
12
  public_suffix (>= 2.0.2, < 6.0)
11
13
  ast (2.4.2)
14
+ base64 (0.3.0)
12
15
  bigdecimal (3.1.7)
13
16
  crack (1.0.0)
14
17
  bigdecimal
15
18
  rexml
16
19
  diff-lcs (1.5.1)
20
+ encryptor (3.0.0)
17
21
  hashdiff (1.1.0)
18
- parallel (1.24.0)
19
- parser (3.3.0.5)
22
+ json (2.9.1)
23
+ jwt (3.1.2)
24
+ base64
25
+ language_server-protocol (3.17.0.3)
26
+ parallel (1.26.3)
27
+ parser (3.3.7.0)
20
28
  ast (~> 2.4.1)
21
29
  racc
22
30
  public_suffix (5.0.4)
23
- racc (1.7.3)
31
+ racc (1.8.1)
24
32
  rainbow (3.1.1)
25
- regexp_parser (2.9.0)
26
- rexml (3.2.6)
33
+ rake (13.3.1)
34
+ regexp_parser (2.10.0)
35
+ rexml (3.4.2)
27
36
  rspec (3.9.0)
28
37
  rspec-core (~> 3.9.0)
29
38
  rspec-expectations (~> 3.9.0)
@@ -37,20 +46,24 @@ GEM
37
46
  diff-lcs (>= 1.2.0, < 2.0)
38
47
  rspec-support (~> 3.9.0)
39
48
  rspec-support (3.9.4)
40
- rubocop (0.93.1)
49
+ rubocop (1.71.0)
50
+ json (~> 2.3)
51
+ language_server-protocol (>= 3.17.0)
41
52
  parallel (~> 1.10)
42
- parser (>= 2.7.1.5)
53
+ parser (>= 3.3.0.2)
43
54
  rainbow (>= 2.2.2, < 4.0)
44
- regexp_parser (>= 1.8)
45
- rexml
46
- rubocop-ast (>= 0.6.0)
55
+ regexp_parser (>= 2.9.3, < 3.0)
56
+ rubocop-ast (>= 1.36.2, < 2.0)
47
57
  ruby-progressbar (~> 1.7)
48
- unicode-display_width (>= 1.4.0, < 2.0)
49
- rubocop-ast (1.31.2)
50
- parser (>= 3.3.0.4)
58
+ unicode-display_width (>= 2.4.0, < 4.0)
59
+ rubocop-ast (1.37.0)
60
+ parser (>= 3.3.1.0)
51
61
  ruby-progressbar (1.13.0)
52
- unicode-display_width (1.8.0)
53
- vcr (5.0.0)
62
+ unicode-display_width (3.1.4)
63
+ unicode-emoji (~> 4.0, >= 4.0.4)
64
+ unicode-emoji (4.0.4)
65
+ vcr (6.3.1)
66
+ base64
54
67
  webmock (3.23.0)
55
68
  addressable (>= 2.8.0)
56
69
  crack (>= 0.3.2)
@@ -61,9 +74,10 @@ PLATFORMS
61
74
 
62
75
  DEPENDENCIES
63
76
  bundler (>= 2.0.1)
77
+ rake
64
78
  rspec (~> 3.9.0)
65
- rubocop (~> 0.77)
66
- vcr (~> 5.0.0)
79
+ rubocop (~> 1.71)
80
+ vcr (~> 6.0)
67
81
  webmock
68
82
  workos!
69
83
 
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/context7.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "url": "https://context7.com/workos/workos-ruby",
3
+ "public_key": "pk_q7NnKuFFXMWA7WnmjMHQU"
4
+ }
@@ -6,10 +6,20 @@ module WorkOS
6
6
  class AuthenticationResponse
7
7
  include HashProvider
8
8
 
9
- attr_accessor :user, :organization_id, :impersonator, :access_token, :refresh_token
9
+ attr_accessor :user,
10
+ :organization_id,
11
+ :impersonator,
12
+ :access_token,
13
+ :refresh_token,
14
+ :authentication_method,
15
+ :sealed_session,
16
+ :oauth_tokens
10
17
 
11
- def initialize(authentication_response_json)
18
+ # rubocop:disable Metrics/AbcSize
19
+ def initialize(authentication_response_json, session = nil)
12
20
  json = JSON.parse(authentication_response_json, symbolize_names: true)
21
+ @access_token = json[:access_token]
22
+ @refresh_token = json[:refresh_token]
13
23
  @user = WorkOS::User.new(json[:user].to_json)
14
24
  @organization_id = json[:organization_id]
15
25
  @impersonator =
@@ -17,9 +27,24 @@ module WorkOS
17
27
  Impersonator.new(email: impersonator_json[:email],
18
28
  reason: impersonator_json[:reason],)
19
29
  end
20
- @access_token = json[:access_token]
21
- @refresh_token = json[:refresh_token]
30
+ @authentication_method = json[:authentication_method]
31
+ @oauth_tokens = json[:oauth_tokens] ? WorkOS::OAuthTokens.new(json[:oauth_tokens].to_json) : nil
32
+ @sealed_session =
33
+ if session && session[:seal_session]
34
+ WorkOS::Session.seal_data(
35
+ {
36
+ access_token: access_token,
37
+ refresh_token: refresh_token,
38
+ user: user.to_json,
39
+ organization_id: organization_id,
40
+ impersonator: impersonator.to_json,
41
+ },
42
+ session[:cookie_password],
43
+ encryptor: session[:encryptor],
44
+ )
45
+ end
22
46
  end
47
+ # rubocop:enable Metrics/AbcSize
23
48
 
24
49
  def to_json(*)
25
50
  {
@@ -28,6 +53,9 @@ module WorkOS
28
53
  impersonator: impersonator.to_json,
29
54
  access_token: access_token,
30
55
  refresh_token: refresh_token,
56
+ authentication_method: authentication_method,
57
+ sealed_session: sealed_session,
58
+ oauth_tokens: oauth_tokens&.to_json,
31
59
  }
32
60
  end
33
61
  end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorkOS
4
+ # The Cache module provides a simple in-memory cache for storing values
5
+ # This module is not meant to be instantiated in a user space, and is used internally by the SDK
6
+ module Cache
7
+ # The Entry class represents a cache entry with a value and an expiration time
8
+ class Entry
9
+ attr_reader :value, :expires_at
10
+
11
+ # Initializes a new cache entry
12
+ # @param value [Object] The value to store in the cache
13
+ # @param expires_in_seconds [Integer, nil] The expiration time for the value in seconds, or nil for no expiration
14
+ def initialize(value, expires_in_seconds)
15
+ @value = value
16
+ @expires_at = expires_in_seconds ? Time.now + expires_in_seconds : nil
17
+ end
18
+
19
+ # Checks if the entry has expired
20
+ # @return [Boolean] True if the entry has expired, false otherwise
21
+ def expired?
22
+ return false if expires_at.nil?
23
+
24
+ Time.now > @expires_at
25
+ end
26
+ end
27
+
28
+ class << self
29
+ # Fetches a value from the cache, or calls the block to fetch the value if it is not present
30
+ # @param key [String] The key to fetch the value for
31
+ # @param expires_in [Integer] The expiration time for the value in seconds
32
+ # @param force [Boolean] If true, the value will be fetched from the block even if it is present in the cache
33
+ # @param block [Proc] The block to call to fetch the value if it is not present in the cache
34
+ # @return [Object] The value fetched from the cache or the block
35
+ def fetch(key, expires_in: nil, force: false, &block)
36
+ entry = store[key]
37
+
38
+ if force || entry.nil? || entry.expired?
39
+ value = block.call
40
+ store[key] = Entry.new(value, expires_in)
41
+ return value
42
+ end
43
+
44
+ entry.value
45
+ end
46
+
47
+ # Reads a value from the cache
48
+ # @param key [String] The key to read the value for
49
+ # @return [Object] The value read from the cache, or nil if the value is not present or has expired
50
+ def read(key)
51
+ entry = store[key]
52
+ return nil if entry.nil? || entry.expired?
53
+
54
+ entry.value
55
+ end
56
+
57
+ # Writes a value to the cache
58
+ # @param key [String] The key to write the value for
59
+ # @param value [Object] The value to write to the cache
60
+ # @param expires_in [Integer] The expiration time for the value in seconds
61
+ # @return [Object] The value written to the cache
62
+ def write(key, value, expires_in: nil)
63
+ store[key] = Entry.new(value, expires_in)
64
+ value
65
+ end
66
+
67
+ # Deletes a value from the cache
68
+ # @param key [String] The key to delete the value for
69
+ def delete(key)
70
+ store.delete(key)
71
+ end
72
+
73
+ # Clears all values from the cache
74
+ def clear
75
+ store.clear
76
+ end
77
+
78
+ # Checks if a value exists in the cache
79
+ # @param key [String] The key to check for
80
+ # @return [Boolean] True if the value exists and has not expired, false otherwise
81
+ def exist?(key)
82
+ entry = store[key]
83
+ !(entry.nil? || entry.expired?)
84
+ end
85
+
86
+ private
87
+
88
+ # The in-memory store for the cache
89
+ def store
90
+ @store ||= {}
91
+ end
92
+ end
93
+ end
94
+ end
data/lib/workos/client.rb CHANGED
@@ -86,7 +86,7 @@ module WorkOS
86
86
  ].join('; ')
87
87
  end
88
88
 
89
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity:
89
+ # rubocop:disable Metrics/AbcSize:
90
90
  def handle_error_response(response:)
91
91
  http_status = response.code.to_i
92
92
  json = JSON.parse(response.body)
@@ -109,6 +109,14 @@ module WorkOS
109
109
  http_status: http_status,
110
110
  request_id: response['x-request-id'],
111
111
  )
112
+ when 403
113
+ raise ForbiddenRequestError.new(
114
+ message: json['message'],
115
+ http_status: http_status,
116
+ request_id: response['x-request-id'],
117
+ code: json['code'],
118
+ data: json,
119
+ )
112
120
  when 404
113
121
  raise NotFoundError.new(
114
122
  message: json['message'],
@@ -115,7 +115,7 @@ module WorkOS
115
115
  # @param [Hash] options An options hash
116
116
  # @option options [String] directory The ID of the directory whose
117
117
  # directory users will be retrieved.
118
- # @option options [String] user The ID of the directory group whose
118
+ # @option options [String] group The ID of the directory group whose
119
119
  # directory users will be retrieved.
120
120
  # @option options [String] limit Maximum number of records to return.
121
121
  # @option options [String] order The order in which to paginate records