stytch 6.4.0 → 7.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94327b3a992f3e596ec4c0a5a6bad97d2c78041e15f12a470949819aa5c0994d
4
- data.tar.gz: a02935d82c7129002058f425f15d73886b5f373b9f942e35cfb410fd62c7148d
3
+ metadata.gz: 7146e140429bd2244d6cb3fc47a94e545487c92f8a4e7b18216d23c59f47ad25
4
+ data.tar.gz: 548974370b5bcd86c1c54959f5447829742c2547491ab646cf108d769030f745
5
5
  SHA512:
6
- metadata.gz: c366e0741c92ecf5ce5413beb57917a01f733ecc231540aebfab19c8a51ee75e7ee9deded5d23453b0580fc3556c90f7e2d1b707dfd79fa6aa6fa6b43cf5e152
7
- data.tar.gz: 9e2540999fa38c50436ea9409859cff663378d7b4a4d21a9ec15bdc8e36b326ed3ae2d681751739adbcecb57b3bd3a1c578394ba6d9dd2b92a1e9b5863f1a84b
6
+ metadata.gz: 8de8b7d887ea706d38a81e15288fe87532c0f37df8021f2e36f547438547625a39aeedaea5d6757d7217da68732a71ad70f654f3e906a11b034d74411e3e5f9c
7
+ data.tar.gz: ff1ee0fee78c564b78cadddce1b4fddb3f8e06356e649db35e411db81ac6f7fad00b3177017950a8f0ef1dceff330ae1c91bb0b91838c5e477fc075bbf4183d0
@@ -26,3 +26,16 @@ jobs:
26
26
  bundler-cache: true
27
27
 
28
28
  - run: bundle exec rspec
29
+
30
+ lint:
31
+ runs-on: ubuntu-latest
32
+ steps:
33
+ - uses: actions/checkout@v3
34
+
35
+ - uses: ruby/setup-ruby@v1
36
+ with:
37
+ # Match the minimum supported Ruby version in the gemspec.
38
+ ruby-version: '2.7'
39
+ bundler-cache: true
40
+
41
+ - run: bundle exec rubocop
data/.gitignore CHANGED
@@ -8,6 +8,8 @@
8
8
  /tmp/
9
9
  *.gem
10
10
  Gemfile.lock
11
+ .idea/
12
+ .envrc
11
13
 
12
14
  # rspec failure tracking
13
15
  .rspec_status
data/.rubocop.yml ADDED
@@ -0,0 +1,21 @@
1
+ require:
2
+ - rubocop-rspec
3
+
4
+ AllCops:
5
+ NewCops: disable
6
+ # The target Ruby version must match the one in stytch.gemspec.
7
+ TargetRubyVersion: 2.7
8
+
9
+ Layout/LineLength: { Enabled: false }
10
+
11
+ Metrics: { Enabled: false }
12
+
13
+ Style/Documentation: { Enabled: false }
14
+ Style/For: { Enabled: false }
15
+ Style/FrozenStringLiteralComment: { Enabled: false }
16
+ Style/NumericPredicate: { Enabled: false }
17
+ Style/StringConcatenation: { Enabled: false }
18
+
19
+ RSpec/DescribedClass: { Enabled: false }
20
+ RSpec/ExampleLength: { Enabled: false }
21
+ RSpec/MultipleExpectations: { Enabled: false }
data/DEVELOPMENT.md CHANGED
@@ -5,7 +5,9 @@ Thanks for contributing to Stytch's Ruby library! If you run into trouble, find
5
5
  ## Setup
6
6
 
7
7
  1. Clone this repo.
8
- 2. To test your changes locally, update your GEMFILE with `gem 'stytch', path: '../stytch'` where `../stytch` is the path to your cloned copy of stytch-ruby.
8
+ 2. Install development dependencies using [Bundler]: `bundle install`
9
+
10
+ To test your changes locally in another project, update your `GEMFILE` with `gem 'stytch', path: '../stytch'` where `../stytch` is the path to your cloned copy of stytch-ruby.
9
11
 
10
12
  ## Issues and Pull Requests
11
13
 
@@ -15,4 +17,5 @@ If you have non-trivial changes you'd like us to incorporate, please open an iss
15
17
 
16
18
  When you're ready for someone to look at your issue or PR, assign `@stytchauth/client-libraries` (GitHub should do this automatically). If we don't acknowledge it within one business day, please escalate it by tagging `@stytchauth/engineering` in a comment or letting us know in [Slack].
17
19
 
18
- [Slack]: https://join.slack.com/t/stytch/shared_invite/zt-nil4wo92-jApJ9Cl32cJbEd9esKkvyg
20
+ [Bundler]: https://bundler.io/
21
+ [Slack]: https://join.slack.com/t/stytch/shared_invite/zt-nil4wo92-jApJ9Cl32cJbEd9esKkvyg
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The Stytch Ruby gem makes it easy to use the Stytch user infrastructure API in Ruby applications.
4
4
 
5
- It pairs well with the Stytch [Web SDK](https://www.npmjs.com/package/@stytch/stytch-js) or your own custom authentication flow.
5
+ It pairs well with the Stytch [Web SDK](https://www.npmjs.com/package/@stytch/vanilla-js) or your own custom authentication flow.
6
6
 
7
7
  ## Install
8
8
 
@@ -6,15 +6,19 @@ require_relative 'b2b_oauth'
6
6
  require_relative 'b2b_organizations'
7
7
  require_relative 'b2b_otp'
8
8
  require_relative 'b2b_passwords'
9
+ require_relative 'b2b_rbac'
10
+ require_relative 'b2b_recovery_codes'
9
11
  require_relative 'b2b_sessions'
10
12
  require_relative 'b2b_sso'
13
+ require_relative 'b2b_totps'
11
14
  require_relative 'm2m'
15
+ require_relative 'rbac_local'
12
16
 
13
17
  module StytchB2B
14
18
  class Client
15
19
  ENVIRONMENTS = %i[live test].freeze
16
20
 
17
- attr_reader :discovery, :m2m, :magic_links, :oauth, :otps, :organizations, :passwords, :sso, :sessions
21
+ attr_reader :discovery, :m2m, :magic_links, :oauth, :otps, :organizations, :passwords, :rbac, :recovery_codes, :sso, :sessions, :totps
18
22
 
19
23
  def initialize(project_id:, secret:, env: nil, &block)
20
24
  @api_host = api_host(env, project_id)
@@ -23,15 +27,21 @@ module StytchB2B
23
27
 
24
28
  create_connection(&block)
25
29
 
30
+ rbac = StytchB2B::RBAC.new(@connection)
31
+ @policy_cache = StytchB2B::PolicyCache.new(rbac_client: rbac)
32
+
26
33
  @discovery = StytchB2B::Discovery.new(@connection)
27
- @m2m = Stytch::M2M.new(@connection, project_id)
34
+ @m2m = Stytch::M2M.new(@connection, @project_id)
28
35
  @magic_links = StytchB2B::MagicLinks.new(@connection)
29
36
  @oauth = StytchB2B::OAuth.new(@connection)
30
37
  @otps = StytchB2B::OTPs.new(@connection)
31
38
  @organizations = StytchB2B::Organizations.new(@connection)
32
39
  @passwords = StytchB2B::Passwords.new(@connection)
40
+ @rbac = StytchB2B::RBAC.new(@connection)
41
+ @recovery_codes = StytchB2B::RecoveryCodes.new(@connection)
33
42
  @sso = StytchB2B::SSO.new(@connection)
34
- @sessions = StytchB2B::Sessions.new(@connection)
43
+ @sessions = StytchB2B::Sessions.new(@connection, @project_id, @policy_cache)
44
+ @totps = StytchB2B::TOTPs.new(@connection)
35
45
  end
36
46
 
37
47
  private
@@ -122,6 +122,7 @@ module StytchB2B
122
122
  session_custom_claims: nil,
123
123
  locale: nil
124
124
  )
125
+ headers = {}
125
126
  request = {
126
127
  intermediate_session_token: intermediate_session_token,
127
128
  organization_id: organization_id
@@ -130,7 +131,7 @@ module StytchB2B
130
131
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
131
132
  request[:locale] = locale unless locale.nil?
132
133
 
133
- post_request('/v1/b2b/discovery/intermediate_sessions/exchange', request)
134
+ post_request('/v1/b2b/discovery/intermediate_sessions/exchange', request, headers)
134
135
  end
135
136
  end
136
137
 
@@ -141,12 +142,15 @@ module StytchB2B
141
142
  @connection = connection
142
143
  end
143
144
 
144
- # If an end user does not want to join any already-existing organization, or has no possible organizations to join, this endpoint can be used to create a new
145
+ # If an end user does not want to join any already-existing Organization, or has no possible Organizations to join, this endpoint can be used to create a new
145
146
  # [Organization](https://stytch.com/docs/b2b/api/organization-object) and [Member](https://stytch.com/docs/b2b/api/member-object).
146
147
  #
147
148
  # This operation consumes the Intermediate Session.
148
149
  #
149
- # This endpoint can also be used to start an initial session for the newly created member and organization.
150
+ # This endpoint will also create an initial Member Session for the newly created Member.
151
+ #
152
+ # The Member created by this endpoint will automatically be granted the `stytch_admin` Role. See the
153
+ # [RBAC guide](https://stytch.com/docs/b2b/guides/rbac/stytch-defaults) for more details on this Role.
150
154
  #
151
155
  # If the new Organization is created with a `mfa_policy` of `REQUIRED_FOR_ALL`, the newly created Member will need to complete an MFA step to log in to the Organization.
152
156
  # The `intermediate_session_token` will not be consumed and instead will be returned in the response.
@@ -208,11 +212,11 @@ module StytchB2B
208
212
  # Common domains such as `gmail.com` are not allowed. See the [common email domains resource](https://stytch.com/docs/b2b/api/common-email-domains) for the full list.
209
213
  # The type of this field is nilable list of +String+.
210
214
  # email_jit_provisioning::
211
- # The authentication setting that controls how a new Member can be provisioned by authenticating via Email Magic Link. The accepted values are:
215
+ # The authentication setting that controls how a new Member can be provisioned by authenticating via Email Magic Link or OAuth. The accepted values are:
212
216
  #
213
- # `RESTRICTED` – only new Members with verified emails that comply with `email_allowed_domains` can be provisioned upon authentication via Email Magic Link.
217
+ # `RESTRICTED` – only new Members with verified emails that comply with `email_allowed_domains` can be provisioned upon authentication via Email Magic Link or OAuth.
214
218
  #
215
- # `NOT_ALLOWED` – disable JIT provisioning via Email Magic Link.
219
+ # `NOT_ALLOWED` – disable JIT provisioning via Email Magic Link and OAuth.
216
220
  #
217
221
  # The type of this field is nilable +String+.
218
222
  # email_invites::
@@ -234,7 +238,6 @@ module StytchB2B
234
238
  #
235
239
  # The type of this field is nilable +String+.
236
240
  # allowed_auth_methods::
237
- #
238
241
  # An array of allowed authentication methods. This list is enforced when `auth_methods` is set to `RESTRICTED`.
239
242
  # The list's accepted values are: `sso`, `magic_link`, `password`, `google_oauth`, and `microsoft_oauth`.
240
243
  #
@@ -242,11 +245,30 @@ module StytchB2B
242
245
  # mfa_policy::
243
246
  # The setting that controls the MFA policy for all Members in the Organization. The accepted values are:
244
247
  #
245
- # `REQUIRED_FOR_ALL` – All Members within the Organization will be required to complete MFA every time they wish to log in.
248
+ # `REQUIRED_FOR_ALL` – All Members within the Organization will be required to complete MFA every time they wish to log in. However, any active Session that existed prior to this setting change will remain valid.
246
249
  #
247
250
  # `OPTIONAL` – The default value. The Organization does not require MFA by default for all Members. Members will be required to complete MFA only if their `mfa_enrolled` status is set to true.
248
251
  #
249
252
  # The type of this field is nilable +String+.
253
+ # rbac_email_implicit_role_assignments::
254
+ # Implicit role assignments based off of email domains.
255
+ # For each domain-Role pair, all Members whose email addresses have the specified email domain will be granted the
256
+ # associated Role, regardless of their login method. See the [RBAC guide](https://stytch.com/docs/b2b/guides/rbac/role-assignment)
257
+ # for more information about role assignment.
258
+ # The type of this field is nilable list of +EmailImplicitRoleAssignment+ (+object+).
259
+ # mfa_methods::
260
+ # The setting that controls which MFA methods can be used by Members of an Organization. The accepted values are:
261
+ #
262
+ # `ALL_ALLOWED` – the default setting which allows all authentication methods to be used.
263
+ #
264
+ # `RESTRICTED` – only methods that comply with `allowed_mfa_methods` can be used for authentication. This setting does not apply to Members with `is_breakglass` set to `true`.
265
+ #
266
+ # The type of this field is nilable +String+.
267
+ # allowed_mfa_methods::
268
+ # An array of allowed MFA authentication methods. This list is enforced when `mfa_methods` is set to `RESTRICTED`.
269
+ # The list's accepted values are: `sms_otp` and `totp`.
270
+ #
271
+ # The type of this field is nilable list of +String+.
250
272
  #
251
273
  # == Returns:
252
274
  # An object with the following fields:
@@ -300,8 +322,12 @@ module StytchB2B
300
322
  email_invites: nil,
301
323
  auth_methods: nil,
302
324
  allowed_auth_methods: nil,
303
- mfa_policy: nil
325
+ mfa_policy: nil,
326
+ rbac_email_implicit_role_assignments: nil,
327
+ mfa_methods: nil,
328
+ allowed_mfa_methods: nil
304
329
  )
330
+ headers = {}
305
331
  request = {
306
332
  intermediate_session_token: intermediate_session_token,
307
333
  organization_name: organization_name,
@@ -318,8 +344,11 @@ module StytchB2B
318
344
  request[:auth_methods] = auth_methods unless auth_methods.nil?
319
345
  request[:allowed_auth_methods] = allowed_auth_methods unless allowed_auth_methods.nil?
320
346
  request[:mfa_policy] = mfa_policy unless mfa_policy.nil?
347
+ request[:rbac_email_implicit_role_assignments] = rbac_email_implicit_role_assignments unless rbac_email_implicit_role_assignments.nil?
348
+ request[:mfa_methods] = mfa_methods unless mfa_methods.nil?
349
+ request[:allowed_mfa_methods] = allowed_mfa_methods unless allowed_mfa_methods.nil?
321
350
 
322
- post_request('/v1/b2b/discovery/organizations/create', request)
351
+ post_request('/v1/b2b/discovery/organizations/create', request, headers)
323
352
  end
324
353
 
325
354
  # List all possible organization relationships connected to a [Member Session](https://stytch.com/docs/b2b/api/session-object) or Intermediate Session.
@@ -383,12 +412,13 @@ module StytchB2B
383
412
  session_token: nil,
384
413
  session_jwt: nil
385
414
  )
415
+ headers = {}
386
416
  request = {}
387
417
  request[:intermediate_session_token] = intermediate_session_token unless intermediate_session_token.nil?
388
418
  request[:session_token] = session_token unless session_token.nil?
389
419
  request[:session_jwt] = session_jwt unless session_jwt.nil?
390
420
 
391
- post_request('/v1/b2b/discovery/organizations', request)
421
+ post_request('/v1/b2b/discovery/organizations', request, headers)
392
422
  end
393
423
  end
394
424
  end
@@ -133,6 +133,7 @@ module StytchB2B
133
133
  session_custom_claims: nil,
134
134
  locale: nil
135
135
  )
136
+ headers = {}
136
137
  request = {
137
138
  magic_links_token: magic_links_token
138
139
  }
@@ -143,7 +144,7 @@ module StytchB2B
143
144
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
144
145
  request[:locale] = locale unless locale.nil?
145
146
 
146
- post_request('/v1/b2b/magic_links/authenticate', request)
147
+ post_request('/v1/b2b/magic_links/authenticate', request, headers)
147
148
  end
148
149
 
149
150
  class Email
@@ -225,6 +226,7 @@ module StytchB2B
225
226
  signup_template_id: nil,
226
227
  locale: nil
227
228
  )
229
+ headers = {}
228
230
  request = {
229
231
  organization_id: organization_id,
230
232
  email_address: email_address
@@ -236,10 +238,10 @@ module StytchB2B
236
238
  request[:signup_template_id] = signup_template_id unless signup_template_id.nil?
237
239
  request[:locale] = locale unless locale.nil?
238
240
 
239
- post_request('/v1/b2b/magic_links/email/login_or_signup', request)
241
+ post_request('/v1/b2b/magic_links/email/login_or_signup', request, headers)
240
242
  end
241
243
 
242
- # Send an invite email to a new Member to join an Organization. The Member will be created with an `invited` status until they successfully authenticate. Sending invites to `pending` Members will update their status to `invited`. Sending invites to already `active` Members will return an error.
244
+ # Send an invite email to a new Member to join an Organization. The Member will be created with an `invited` status until they successfully authenticate. Sending invites to `pending` Members will update their status to `invited`. Sending invites to already `active` Members will return an error. /%}
243
245
  #
244
246
  # == Parameters:
245
247
  # organization_id::
@@ -279,6 +281,10 @@ module StytchB2B
279
281
  # Request support for additional languages [here](https://docs.google.com/forms/d/e/1FAIpQLScZSpAu_m2AmLXRT3F3kap-s_mcV6UTBitYn6CdyWP0-o7YjQ/viewform?usp=sf_link")!
280
282
  #
281
283
  # The type of this field is nilable +InviteRequestLocale+ (string enum).
284
+ # roles::
285
+ # Roles to explicitly assign to this Member. See the [RBAC guide](https://stytch.com/docs/b2b/guides/rbac/role-assignment)
286
+ # for more information about role assignment.
287
+ # The type of this field is nilable list of +String+.
282
288
  #
283
289
  # == Returns:
284
290
  # An object with the following fields:
@@ -297,6 +303,9 @@ module StytchB2B
297
303
  # status_code::
298
304
  # The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
299
305
  # The type of this field is +Integer+.
306
+ #
307
+ # == Method Options:
308
+ # This method supports an optional +InviteRequestOptions+ object which will modify the headers sent in the HTTP request.
300
309
  def invite(
301
310
  organization_id:,
302
311
  email_address:,
@@ -306,8 +315,12 @@ module StytchB2B
306
315
  trusted_metadata: nil,
307
316
  untrusted_metadata: nil,
308
317
  invite_template_id: nil,
309
- locale: nil
318
+ locale: nil,
319
+ roles: nil,
320
+ method_options: nil
310
321
  )
322
+ headers = {}
323
+ headers = headers.merge(method_options.to_headers) unless method_options.nil?
311
324
  request = {
312
325
  organization_id: organization_id,
313
326
  email_address: email_address
@@ -319,8 +332,9 @@ module StytchB2B
319
332
  request[:untrusted_metadata] = untrusted_metadata unless untrusted_metadata.nil?
320
333
  request[:invite_template_id] = invite_template_id unless invite_template_id.nil?
321
334
  request[:locale] = locale unless locale.nil?
335
+ request[:roles] = roles unless roles.nil?
322
336
 
323
- post_request('/v1/b2b/magic_links/email/invite', request)
337
+ post_request('/v1/b2b/magic_links/email/invite', request, headers)
324
338
  end
325
339
 
326
340
  class Discovery
@@ -372,6 +386,7 @@ module StytchB2B
372
386
  login_template_id: nil,
373
387
  locale: nil
374
388
  )
389
+ headers = {}
375
390
  request = {
376
391
  email_address: email_address
377
392
  }
@@ -380,7 +395,7 @@ module StytchB2B
380
395
  request[:login_template_id] = login_template_id unless login_template_id.nil?
381
396
  request[:locale] = locale unless locale.nil?
382
397
 
383
- post_request('/v1/b2b/magic_links/email/discovery/send', request)
398
+ post_request('/v1/b2b/magic_links/email/discovery/send', request, headers)
384
399
  end
385
400
  end
386
401
  end
@@ -437,12 +452,13 @@ module StytchB2B
437
452
  discovery_magic_links_token:,
438
453
  pkce_code_verifier: nil
439
454
  )
455
+ headers = {}
440
456
  request = {
441
457
  discovery_magic_links_token: discovery_magic_links_token
442
458
  }
443
459
  request[:pkce_code_verifier] = pkce_code_verifier unless pkce_code_verifier.nil?
444
460
 
445
- post_request('/v1/b2b/magic_links/discovery/authenticate', request)
461
+ post_request('/v1/b2b/magic_links/discovery/authenticate', request, headers)
446
462
  end
447
463
  end
448
464
  end
@@ -28,6 +28,8 @@ module StytchB2B
28
28
  #
29
29
  # If a valid `session_token` or `session_jwt` is passed in, the Member will not be required to complete an MFA step.
30
30
  #
31
+ # We’re actively accepting requests for new OAuth providers! Please [email us](mailto:support@stytch.com) or [post in our community](https://stytch.com/docs/b2b/resources) if you are looking for an OAuth provider that is not currently supported.
32
+ #
31
33
  # == Parameters:
32
34
  # oauth_token::
33
35
  # The token to authenticate.
@@ -134,6 +136,7 @@ module StytchB2B
134
136
  pkce_code_verifier: nil,
135
137
  locale: nil
136
138
  )
139
+ headers = {}
137
140
  request = {
138
141
  oauth_token: oauth_token
139
142
  }
@@ -144,7 +147,7 @@ module StytchB2B
144
147
  request[:pkce_code_verifier] = pkce_code_verifier unless pkce_code_verifier.nil?
145
148
  request[:locale] = locale unless locale.nil?
146
149
 
147
- post_request('/v1/b2b/oauth/authenticate', request)
150
+ post_request('/v1/b2b/oauth/authenticate', request, headers)
148
151
  end
149
152
 
150
153
  class Discovery
@@ -204,6 +207,12 @@ module StytchB2B
204
207
  #
205
208
  # c) The Organization has at least one other Member with a verified email address with the same domain as the end user (to prevent phishing attacks).
206
209
  # The type of this field is list of +DiscoveredOrganization+ (+object+).
210
+ # provider_type::
211
+ # (no documentation yet)
212
+ # The type of this field is +String+.
213
+ # provider_tenant_id::
214
+ # (no documentation yet)
215
+ # The type of this field is +String+.
207
216
  # status_code::
208
217
  # The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
209
218
  # The type of this field is +Integer+.
@@ -215,6 +224,7 @@ module StytchB2B
215
224
  session_custom_claims: nil,
216
225
  pkce_code_verifier: nil
217
226
  )
227
+ headers = {}
218
228
  request = {
219
229
  discovery_oauth_token: discovery_oauth_token
220
230
  }
@@ -224,7 +234,7 @@ module StytchB2B
224
234
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
225
235
  request[:pkce_code_verifier] = pkce_code_verifier unless pkce_code_verifier.nil?
226
236
 
227
- post_request('/v1/b2b/oauth/discovery/authenticate', request)
237
+ post_request('/v1/b2b/oauth/discovery/authenticate', request, headers)
228
238
  end
229
239
  end
230
240
  end