stytch 6.4.0 → 9.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,7 +23,11 @@ module Stytch
23
23
  #
24
24
  # == Parameters:
25
25
  # token::
26
- # The token to authenticate.
26
+ # The Magic Link `token` from the `?token=` query parameter in the URL.
27
+ #
28
+ # The redirect URL will look like `https://example.com/authenticate?stytch_token_type=magic_links&token=rM_kw42CWBhsHLF62V75jELMbvJ87njMe3tFVj7Qupu7`
29
+ #
30
+ # In the redirect URL, the `stytch_token_type` will be `magic_link`. See [here](https://stytch.com/docs/guides/dashboard/redirect-urls) for more detail.
27
31
  # The type of this field is +String+.
28
32
  # attributes::
29
33
  # Provided attributes help with fraud detection.
@@ -99,6 +103,7 @@ module Stytch
99
103
  session_custom_claims: nil,
100
104
  code_verifier: nil
101
105
  )
106
+ headers = {}
102
107
  request = {
103
108
  token: token
104
109
  }
@@ -110,7 +115,7 @@ module Stytch
110
115
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
111
116
  request[:code_verifier] = code_verifier unless code_verifier.nil?
112
117
 
113
- post_request('/v1/magic_links/authenticate', request)
118
+ post_request('/v1/magic_links/authenticate', request, headers)
114
119
  end
115
120
 
116
121
  # Create an embeddable Magic Link token for a User. Access to this endpoint is restricted. To enable it, please send us a note at support@stytch.com.
@@ -148,13 +153,14 @@ module Stytch
148
153
  expiration_minutes: nil,
149
154
  attributes: nil
150
155
  )
156
+ headers = {}
151
157
  request = {
152
158
  user_id: user_id
153
159
  }
154
160
  request[:expiration_minutes] = expiration_minutes unless expiration_minutes.nil?
155
161
  request[:attributes] = attributes unless attributes.nil?
156
162
 
157
- post_request('/v1/magic_links', request)
163
+ post_request('/v1/magic_links', request, headers)
158
164
  end
159
165
 
160
166
  class Email
@@ -167,9 +173,7 @@ module Stytch
167
173
  # Send a magic link to an existing Stytch user using their email address. If you'd like to create a user and send them a magic link by email with one request, use our [log in or create endpoint](https://stytch.com/docs/api/log-in-or-create-user-by-email).
168
174
  #
169
175
  # ### Add an email to an existing user
170
- # This endpoint also allows you to add a new email to an existing Stytch User. Including a `user_id`, `session_token`, or `session_jwt` in the request will add the email to the pre-existing Stytch User upon successful authentication.
171
- #
172
- # Adding a new email to an existing Stytch User requires the user to be present and validate the email via magic link. This requirement is in place to prevent account takeover attacks.
176
+ # This endpoint also allows you to add a new email address to an existing Stytch User. Including a `user_id`, `session_token`, or `session_jwt` in your Send Magic Link by email request will add the new, unverified email address to the existing Stytch User. If the user successfully authenticates within 5 minutes, the new email address will be marked as verified and remain permanently on the existing Stytch User. Otherwise, it will be removed from the User object, and any subsequent login requests using that email address will create a new User.
173
177
  #
174
178
  # ### Next steps
175
179
  # The user is emailed a magic link which redirects them to the provided [redirect URL](https://stytch.com/docs/guides/magic-links/email-magic-links/redirect-routing). Collect the `token` from the URL query parameters, and call [Authenticate magic link](https://stytch.com/docs/api/authenticate-magic-link) to complete authentication.
@@ -249,6 +253,7 @@ module Stytch
249
253
  locale: nil,
250
254
  signup_template_id: nil
251
255
  )
256
+ headers = {}
252
257
  request = {
253
258
  email: email
254
259
  }
@@ -265,13 +270,13 @@ module Stytch
265
270
  request[:locale] = locale unless locale.nil?
266
271
  request[:signup_template_id] = signup_template_id unless signup_template_id.nil?
267
272
 
268
- post_request('/v1/magic_links/email/send', request)
273
+ post_request('/v1/magic_links/email/send', request, headers)
269
274
  end
270
275
 
271
276
  # Send either a login or signup Magic Link to the User based on if the email is associated with a User already. A new or pending User will receive a signup Magic Link. An active User will receive a login Magic Link. For more information on how to control the status your Users are created in see the `create_user_as_pending` flag.
272
277
  #
273
278
  # ### Next steps
274
- # The User is emailed a Magic Link which redirects them to the provided [redirect URL](https://stytch.com/docs/magic-links#email-magic-links_redirect-routing). Collect the `token` from the URL query parameters and call [Authenticate Magic Link](https://stytch.com/docs/api/authenticate-magic-link) to complete authentication.
279
+ # The User is emailed a Magic Link which redirects them to the provided [redirect URL](https://stytch.com/docs/guides/magic-links/email-magic-links/redirect-routing). Collect the `token` from the URL query parameters and call [Authenticate Magic Link](https://stytch.com/docs/api/authenticate-magic-link) to complete authentication.
275
280
  #
276
281
  # == Parameters:
277
282
  # email::
@@ -347,6 +352,7 @@ module Stytch
347
352
  code_challenge: nil,
348
353
  locale: nil
349
354
  )
355
+ headers = {}
350
356
  request = {
351
357
  email: email
352
358
  }
@@ -361,13 +367,13 @@ module Stytch
361
367
  request[:code_challenge] = code_challenge unless code_challenge.nil?
362
368
  request[:locale] = locale unless locale.nil?
363
369
 
364
- post_request('/v1/magic_links/email/login_or_create', request)
370
+ post_request('/v1/magic_links/email/login_or_create', request, headers)
365
371
  end
366
372
 
367
373
  # Create a User and send an invite Magic Link to the provided `email`. The User will be created with a `pending` status until they click the Magic Link in the invite email.
368
374
  #
369
375
  # ### Next steps
370
- # The User is emailed a Magic Link which redirects them to the provided [redirect URL](https://stytch.com/docs/magic-links#email-magic-links_redirect-routing). Collect the `token` from the URL query parameters and call [Authenticate Magic Link](https://stytch.com/docs/api/authenticate-magic-link) to complete authentication.
376
+ # The User is emailed a Magic Link which redirects them to the provided [redirect URL](https://stytch.com/docs/guides/magic-links/email-magic-links/redirect-routing). Collect the `token` from the URL query parameters and call [Authenticate Magic Link](https://stytch.com/docs/api/authenticate-magic-link) to complete authentication.
371
377
  #
372
378
  # == Parameters:
373
379
  # email::
@@ -420,6 +426,7 @@ module Stytch
420
426
  invite_expiration_minutes: nil,
421
427
  locale: nil
422
428
  )
429
+ headers = {}
423
430
  request = {
424
431
  email: email
425
432
  }
@@ -430,7 +437,7 @@ module Stytch
430
437
  request[:invite_expiration_minutes] = invite_expiration_minutes unless invite_expiration_minutes.nil?
431
438
  request[:locale] = locale unless locale.nil?
432
439
 
433
- post_request('/v1/magic_links/email/invite', request)
440
+ post_request('/v1/magic_links/email/invite', request, headers)
434
441
  end
435
442
 
436
443
  # Revoke a pending invite based on the `email` provided.
@@ -451,11 +458,12 @@ module Stytch
451
458
  def revoke_invite(
452
459
  email:
453
460
  )
461
+ headers = {}
454
462
  request = {
455
463
  email: email
456
464
  }
457
465
 
458
- post_request('/v1/magic_links/email/revoke_invite', request)
466
+ post_request('/v1/magic_links/email/revoke_invite', request, headers)
459
467
  end
460
468
  end
461
469
  end
@@ -0,0 +1,22 @@
1
+ module Stytch
2
+ module MethodOptions
3
+ class Authorization
4
+ # A secret token for a given Stytch Session.
5
+ attr_accessor :session_token
6
+ # The JSON Web Token (JWT) for a given Stytch Session.
7
+ attr_accessor :session_jwt
8
+
9
+ def initialize(session_token: nil, session_jwt: nil)
10
+ @session_token = session_token
11
+ @session_jwt = session_jwt
12
+ end
13
+
14
+ def to_headers
15
+ headers = {}
16
+ headers['X-Stytch-Member-Session'] = session_token if session_token
17
+ headers['X-Stytch-Member-SessionJWT'] = session_jwt if session_jwt
18
+ headers
19
+ end
20
+ end
21
+ end
22
+ end
data/lib/stytch/oauth.rb CHANGED
@@ -53,6 +53,7 @@ module Stytch
53
53
  session_token: nil,
54
54
  session_jwt: nil
55
55
  )
56
+ headers = {}
56
57
  request = {
57
58
  provider: provider
58
59
  }
@@ -60,14 +61,18 @@ module Stytch
60
61
  request[:session_token] = session_token unless session_token.nil?
61
62
  request[:session_jwt] = session_jwt unless session_jwt.nil?
62
63
 
63
- post_request('/v1/oauth/attach', request)
64
+ post_request('/v1/oauth/attach', request, headers)
64
65
  end
65
66
 
66
67
  # Authenticate a User given a `token`. This endpoint verifies that the user completed the OAuth flow by verifying that the token is valid and hasn't expired. To initiate a Stytch session for the user while authenticating their OAuth token, include `session_duration_minutes`; a session with the identity provider, e.g. Google or Facebook, will always be initiated upon successful authentication.
67
68
  #
68
69
  # == Parameters:
69
70
  # token::
70
- # The token to authenticate.
71
+ # The OAuth `token` from the `?token=` query parameter in the URL.
72
+ #
73
+ # The redirect URL will look like `https://example.com/authenticate?stytch_token_type=oauth&token=rM_kw42CWBhsHLF62V75jELMbvJ87njMe3tFVj7Qupu7`
74
+ #
75
+ # In the redirect URL, the `stytch_token_type` will be `oauth`. See [here](https://stytch.com/docs/guides/dashboard/redirect-urls) for more detail.
71
76
  # The type of this field is +String+.
72
77
  # session_token::
73
78
  # Reuse an existing session instead of creating a new one. If you provide us with a `session_token`, then we'll update the session represented by this session token with this OAuth factor. If this `session_token` belongs to a different user than the OAuth token, the session_jwt will be ignored. This endpoint will error if both `session_token` and `session_jwt` are provided.
@@ -118,7 +123,7 @@ module Stytch
118
123
  # provider_values::
119
124
  # The `provider_values` object lists relevant identifiers, values, and scopes for a given OAuth provider. For example this object will include a provider's `access_token` that you can use to access the provider's API for a given user.
120
125
  #
121
- # Note that these values will vary based on the OAuth provider in question, e.g. `id_token` is only returned by OIDC complaint identity providers.
126
+ # Note that these values will vary based on the OAuth provider in question, e.g. `id_token` is only returned by OIDC compliant identity providers.
122
127
  # The type of this field is +ProviderValues+ (+object+).
123
128
  # user::
124
129
  # The `user` object affected by this API call. See the [Get user endpoint](https://stytch.com/docs/api/get-user) for complete response field details.
@@ -146,6 +151,7 @@ module Stytch
146
151
  session_custom_claims: nil,
147
152
  code_verifier: nil
148
153
  )
154
+ headers = {}
149
155
  request = {
150
156
  token: token
151
157
  }
@@ -155,7 +161,7 @@ module Stytch
155
161
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
156
162
  request[:code_verifier] = code_verifier unless code_verifier.nil?
157
163
 
158
- post_request('/v1/oauth/authenticate', request)
164
+ post_request('/v1/oauth/authenticate', request, headers)
159
165
  end
160
166
  end
161
167
  end
data/lib/stytch/otps.rb CHANGED
@@ -101,6 +101,7 @@ module Stytch
101
101
  session_jwt: nil,
102
102
  session_custom_claims: nil
103
103
  )
104
+ headers = {}
104
105
  request = {
105
106
  method_id: method_id,
106
107
  code: code
@@ -112,7 +113,7 @@ module Stytch
112
113
  request[:session_jwt] = session_jwt unless session_jwt.nil?
113
114
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
114
115
 
115
- post_request('/v1/otps/authenticate', request)
116
+ post_request('/v1/otps/authenticate', request, headers)
116
117
  end
117
118
 
118
119
  class Sms
@@ -129,11 +130,13 @@ module Stytch
129
130
  # ### Cost to send SMS OTP
130
131
  # Before configuring SMS or WhatsApp OTPs, please review how Stytch [bills the costs of international OTPs](https://stytch.com/pricing) and understand how to protect your app against [toll fraud](https://stytch.com/docs/guides/passcodes/toll-fraud/overview).
131
132
  #
132
- # ### Add a phone number to an existing user
133
+ # __Note:__ SMS to phone numbers outside of the US and Canada is disabled by default for customers who did not use SMS prior to October 2023. If you're interested in sending international SMS, please reach out to [support@stytch.com](mailto:support@stytch.com?subject=Enable%20international%20SMS).
134
+ #
135
+ # Even when international SMS is enabled, we do not support sending SMS to countries on our [Unsupported countries list](https://stytch.com/docs/guides/passcodes/unsupported-countries).
133
136
  #
134
- # This endpoint also allows you to add a new phone number to an existing Stytch User. Including a `user_id`, `session_token`, or `session_jwt` in the request will add the phone number to the pre-existing Stytch User upon successful authentication.
137
+ # ### Add a phone number to an existing user
135
138
  #
136
- # Adding a new phone number to an existing Stytch User requires the user to be present and validate the phone number via OTP. This requirement is in place to prevent account takeover attacks.
139
+ # This endpoint also allows you to add a new phone number to an existing Stytch User. Including a `user_id`, `session_token`, or `session_jwt` in your Send one-time passcode by SMS request will add the new, unverified phone number to the existing Stytch User. If the user successfully authenticates within 5 minutes, the new phone number will be marked as verified and remain permanently on the existing Stytch User. Otherwise, it will be removed from the User object, and any subsequent login requests using that phone number will create a new User.
137
140
  #
138
141
  # ### Next steps
139
142
  #
@@ -190,6 +193,7 @@ module Stytch
190
193
  session_token: nil,
191
194
  session_jwt: nil
192
195
  )
196
+ headers = {}
193
197
  request = {
194
198
  phone_number: phone_number
195
199
  }
@@ -200,13 +204,18 @@ module Stytch
200
204
  request[:session_token] = session_token unless session_token.nil?
201
205
  request[:session_jwt] = session_jwt unless session_jwt.nil?
202
206
 
203
- post_request('/v1/otps/sms/send', request)
207
+ post_request('/v1/otps/sms/send', request, headers)
204
208
  end
205
209
 
206
210
  # Send a One-Time Passcode (OTP) to a User using their phone number. If the phone number is not associated with a user already, a user will be created.
207
211
  #
208
212
  # ### Cost to send SMS OTP
209
213
  # Before configuring SMS or WhatsApp OTPs, please review how Stytch [bills the costs of international OTPs](https://stytch.com/pricing) and understand how to protect your app against [toll fraud](https://stytch.com/docs/guides/passcodes/toll-fraud/overview).
214
+ #
215
+ # __Note:__ SMS to phone numbers outside of the US and Canada is disabled by default for customers who did not use SMS prior to October 2023. If you're interested in sending international SMS, please reach out to [support@stytch.com](mailto:support@stytch.com?subject=Enable%20international%20SMS).
216
+ #
217
+ # Even when international SMS is enabled, we do not support sending SMS to countries on our [Unsupported countries list](https://stytch.com/docs/guides/passcodes/unsupported-countries).
218
+ #
210
219
  # ### Next steps
211
220
  #
212
221
  # Collect the OTP which was delivered to the User. Call [Authenticate OTP](https://stytch.com/docs/api/authenticate-otp) using the OTP `code` along with the `phone_id` found in the response as the `method_id`.
@@ -261,6 +270,7 @@ module Stytch
261
270
  create_user_as_pending: nil,
262
271
  locale: nil
263
272
  )
273
+ headers = {}
264
274
  request = {
265
275
  phone_number: phone_number
266
276
  }
@@ -269,7 +279,7 @@ module Stytch
269
279
  request[:create_user_as_pending] = create_user_as_pending unless create_user_as_pending.nil?
270
280
  request[:locale] = locale unless locale.nil?
271
281
 
272
- post_request('/v1/otps/sms/login_or_create', request)
282
+ post_request('/v1/otps/sms/login_or_create', request, headers)
273
283
  end
274
284
  end
275
285
 
@@ -289,9 +299,7 @@ module Stytch
289
299
  #
290
300
  # ### Add a phone number to an existing user
291
301
  #
292
- # This endpoint also allows you to add a new phone number to an existing Stytch User. Including a `user_id`, `session_token`, or `session_jwt` in the request will add the phone number to the pre-existing Stytch User upon successful authentication.
293
- #
294
- # Adding a new phone number to an existing Stytch User requires the user to be present and validate the phone number via OTP. This requirement is in place to prevent account takeover attacks.
302
+ # This endpoint also allows you to add a new phone number to an existing Stytch User. Including a `user_id`, `session_token`, or `session_jwt` in your Send one-time passcode by WhatsApp request will add the new, unverified phone number to the existing Stytch User. If the user successfully authenticates within 5 minutes, the new phone number will be marked as verified and remain permanently on the existing Stytch User. Otherwise, it will be removed from the User object, and any subsequent login requests using that phone number will create a new User.
295
303
  #
296
304
  # ### Next steps
297
305
  #
@@ -348,6 +356,7 @@ module Stytch
348
356
  session_token: nil,
349
357
  session_jwt: nil
350
358
  )
359
+ headers = {}
351
360
  request = {
352
361
  phone_number: phone_number
353
362
  }
@@ -358,7 +367,7 @@ module Stytch
358
367
  request[:session_token] = session_token unless session_token.nil?
359
368
  request[:session_jwt] = session_jwt unless session_jwt.nil?
360
369
 
361
- post_request('/v1/otps/whatsapp/send', request)
370
+ post_request('/v1/otps/whatsapp/send', request, headers)
362
371
  end
363
372
 
364
373
  # Send a one-time passcode (OTP) to a User's WhatsApp using their phone number. If the phone number is not associated with a User already, a User will be created.
@@ -420,6 +429,7 @@ module Stytch
420
429
  create_user_as_pending: nil,
421
430
  locale: nil
422
431
  )
432
+ headers = {}
423
433
  request = {
424
434
  phone_number: phone_number
425
435
  }
@@ -428,7 +438,7 @@ module Stytch
428
438
  request[:create_user_as_pending] = create_user_as_pending unless create_user_as_pending.nil?
429
439
  request[:locale] = locale unless locale.nil?
430
440
 
431
- post_request('/v1/otps/whatsapp/login_or_create', request)
441
+ post_request('/v1/otps/whatsapp/login_or_create', request, headers)
432
442
  end
433
443
  end
434
444
 
@@ -442,12 +452,10 @@ module Stytch
442
452
  # Send a One-Time Passcode (OTP) to a User using their email. If you'd like to create a user and send them a passcode with one request, use our [log in or create endpoint](https://stytch.com/docs/api/log-in-or-create-user-by-email-otp).
443
453
  #
444
454
  # ### Add an email to an existing user
445
- # This endpoint also allows you to add a new email to an existing Stytch User. Including a `user_id`, `session_token`, or `session_jwt` in the request will add the email to the pre-existing Stytch User upon successful authentication.
446
- #
447
- # Adding a new email to an existing Stytch User requires the User to be present and validate the email via OTP. This requirement is in place to prevent account takeover attacks.
455
+ # This endpoint also allows you to add a new email address to an existing Stytch User. Including a `user_id`, `session_token`, or `session_jwt` in your Send one-time passcode by email request will add the new, unverified email address to the existing Stytch User. If the user successfully authenticates within 5 minutes, the new email address will be marked as verified and remain permanently on the existing Stytch User. Otherwise, it will be removed from the User object, and any subsequent login requests using that email address will create a new User.
448
456
  #
449
457
  # ### Next steps
450
- # Collect the OTP which was delivered to the user. Call [Authenticate OTP](https://stytch.com/docs/api/authenticate-otp) using the OTP `code` along with the `phone_id` found in the response as the `method_id`.
458
+ # Collect the OTP which was delivered to the user. Call [Authenticate OTP](https://stytch.com/docs/api/authenticate-otp) using the OTP `code` along with the `email_id` found in the response as the `method_id`.
451
459
  #
452
460
  # == Parameters:
453
461
  # email::
@@ -508,6 +516,7 @@ module Stytch
508
516
  login_template_id: nil,
509
517
  signup_template_id: nil
510
518
  )
519
+ headers = {}
511
520
  request = {
512
521
  email: email
513
522
  }
@@ -520,7 +529,7 @@ module Stytch
520
529
  request[:login_template_id] = login_template_id unless login_template_id.nil?
521
530
  request[:signup_template_id] = signup_template_id unless signup_template_id.nil?
522
531
 
523
- post_request('/v1/otps/email/send', request)
532
+ post_request('/v1/otps/email/send', request, headers)
524
533
  end
525
534
 
526
535
  # Send a one-time passcode (OTP) to a User using their email. If the email is not associated with a User already, a User will be created.
@@ -587,6 +596,7 @@ module Stytch
587
596
  login_template_id: nil,
588
597
  signup_template_id: nil
589
598
  )
599
+ headers = {}
590
600
  request = {
591
601
  email: email
592
602
  }
@@ -597,7 +607,7 @@ module Stytch
597
607
  request[:login_template_id] = login_template_id unless login_template_id.nil?
598
608
  request[:signup_template_id] = signup_template_id unless signup_template_id.nil?
599
609
 
600
- post_request('/v1/otps/email/login_or_create', request)
610
+ post_request('/v1/otps/email/login_or_create', request, headers)
601
611
  end
602
612
  end
603
613
  end
@@ -34,7 +34,7 @@ module Stytch
34
34
  # The email address of the end user.
35
35
  # The type of this field is +String+.
36
36
  # password::
37
- # The password of the user
37
+ # The password for the user. Any UTF8 character is allowed, e.g. spaces, emojis, non-English characers, etc.
38
38
  # The type of this field is +String+.
39
39
  # session_duration_minutes::
40
40
  # Set the session lifetime to be this many minutes from now. This will start a new session if one doesn't already exist,
@@ -100,6 +100,7 @@ module Stytch
100
100
  untrusted_metadata: nil,
101
101
  name: nil
102
102
  )
103
+ headers = {}
103
104
  request = {
104
105
  email: email,
105
106
  password: password
@@ -110,7 +111,7 @@ module Stytch
110
111
  request[:untrusted_metadata] = untrusted_metadata unless untrusted_metadata.nil?
111
112
  request[:name] = name unless name.nil?
112
113
 
113
- post_request('/v1/passwords', request)
114
+ post_request('/v1/passwords', request, headers)
114
115
  end
115
116
 
116
117
  # Authenticate a user with their email address and password. This endpoint verifies that the user has a password currently set, and that the entered password is correct. There are two instances where the endpoint will return a `reset_password` error even if they enter their previous password:
@@ -126,7 +127,7 @@ module Stytch
126
127
  # The email address of the end user.
127
128
  # The type of this field is +String+.
128
129
  # password::
129
- # The password of the user
130
+ # The password for the user. Any UTF8 character is allowed, e.g. spaces, emojis, non-English characers, etc.
130
131
  # The type of this field is +String+.
131
132
  # session_token::
132
133
  # The `session_token` associated with a User's existing Session.
@@ -185,6 +186,7 @@ module Stytch
185
186
  session_jwt: nil,
186
187
  session_custom_claims: nil
187
188
  )
189
+ headers = {}
188
190
  request = {
189
191
  email: email,
190
192
  password: password
@@ -194,7 +196,7 @@ module Stytch
194
196
  request[:session_jwt] = session_jwt unless session_jwt.nil?
195
197
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
196
198
 
197
- post_request('/v1/passwords/authenticate', request)
199
+ post_request('/v1/passwords/authenticate', request, headers)
198
200
  end
199
201
 
200
202
  # This API allows you to check whether or not the user’s provided password is valid, and to provide feedback to the user on how to increase the strength of their password.
@@ -212,7 +214,7 @@ module Stytch
212
214
  #
213
215
  # == Parameters:
214
216
  # password::
215
- # The password of the user
217
+ # The password for the user. Any UTF8 character is allowed, e.g. spaces, emojis, non-English characers, etc.
216
218
  # The type of this field is +String+.
217
219
  # email::
218
220
  # The email address of the end user.
@@ -248,12 +250,13 @@ module Stytch
248
250
  password:,
249
251
  email: nil
250
252
  )
253
+ headers = {}
251
254
  request = {
252
255
  password: password
253
256
  }
254
257
  request[:email] = email unless email.nil?
255
258
 
256
- post_request('/v1/passwords/strength_check', request)
259
+ post_request('/v1/passwords/strength_check', request, headers)
257
260
  end
258
261
 
259
262
  # Adds an existing password to a User's email that doesn't have a password yet. We support migrating users from passwords stored with `bcrypt`, `scrypt`, `argon2`, `MD-5`, `SHA-1`, or `PBKDF2`. This endpoint has a rate limit of 100 requests per second.
@@ -289,6 +292,11 @@ module Stytch
289
292
  # untrusted_metadata::
290
293
  # The `untrusted_metadata` field contains an arbitrary JSON object of application-specific data. Untrusted metadata can be edited by end users directly via the SDK, and **cannot be used to store critical information.** See the [Metadata](https://stytch.com/docs/api/metadata) reference for complete field behavior details.
291
294
  # The type of this field is nilable +object+.
295
+ # set_email_verified::
296
+ # Whether to set the user's email as verified. This is a dangerous field. Incorrect use may lead to users getting erroneously
297
+ # deduplicated into one user object. This flag should only be set if you can attest that the user owns the email address in question.
298
+ # Access to this field is restricted. To enable it, please send us a note at support@stytch.com.
299
+ # The type of this field is nilable +Boolean+.
292
300
  # name::
293
301
  # The name of the user. Each field in the name object is optional.
294
302
  # The type of this field is nilable +Name+ (+object+).
@@ -324,8 +332,10 @@ module Stytch
324
332
  pbkdf_2_config: nil,
325
333
  trusted_metadata: nil,
326
334
  untrusted_metadata: nil,
335
+ set_email_verified: nil,
327
336
  name: nil
328
337
  )
338
+ headers = {}
329
339
  request = {
330
340
  email: email,
331
341
  hash: hash,
@@ -338,9 +348,10 @@ module Stytch
338
348
  request[:pbkdf_2_config] = pbkdf_2_config unless pbkdf_2_config.nil?
339
349
  request[:trusted_metadata] = trusted_metadata unless trusted_metadata.nil?
340
350
  request[:untrusted_metadata] = untrusted_metadata unless untrusted_metadata.nil?
351
+ request[:set_email_verified] = set_email_verified unless set_email_verified.nil?
341
352
  request[:name] = name unless name.nil?
342
353
 
343
- post_request('/v1/passwords/migrate', request)
354
+ post_request('/v1/passwords/migrate', request, headers)
344
355
  end
345
356
 
346
357
  class Email
@@ -415,33 +426,37 @@ module Stytch
415
426
  locale: nil,
416
427
  reset_password_template_id: nil
417
428
  )
429
+ headers = {}
418
430
  request = {
419
431
  email: email
420
432
  }
421
433
  request[:reset_password_redirect_url] = reset_password_redirect_url unless reset_password_redirect_url.nil?
422
- unless reset_password_expiration_minutes.nil?
423
- request[:reset_password_expiration_minutes] =
424
- reset_password_expiration_minutes
425
- end
434
+ request[:reset_password_expiration_minutes] = reset_password_expiration_minutes unless reset_password_expiration_minutes.nil?
426
435
  request[:code_challenge] = code_challenge unless code_challenge.nil?
427
436
  request[:attributes] = attributes unless attributes.nil?
428
437
  request[:login_redirect_url] = login_redirect_url unless login_redirect_url.nil?
429
438
  request[:locale] = locale unless locale.nil?
430
439
  request[:reset_password_template_id] = reset_password_template_id unless reset_password_template_id.nil?
431
440
 
432
- post_request('/v1/passwords/email/reset/start', request)
441
+ post_request('/v1/passwords/email/reset/start', request, headers)
433
442
  end
434
443
 
435
444
  # Reset the user’s password and authenticate them. This endpoint checks that the magic link `token` is valid, hasn’t expired, or already been used – and can optionally require additional security settings, such as the IP address and user agent matching the initial reset request.
436
445
  #
437
446
  # The provided password needs to meet our password strength requirements, which can be checked in advance with the password strength endpoint. If the token and password are accepted, the password is securely stored for future authentication and the user is authenticated.
438
447
  #
448
+ # Note that a successful password reset by email will revoke all active sessions for the `user_id`.
449
+ #
439
450
  # == Parameters:
440
451
  # token::
441
- # The token to authenticate.
452
+ # The Passwords `token` from the `?token=` query parameter in the URL.
453
+ #
454
+ # In the redirect URL, the `stytch_token_type` will be `login` or `reset_password`.
455
+ #
456
+ # See examples and read more about redirect URLs [here](https://stytch.com/docs/guides/dashboard/redirect-urls).
442
457
  # The type of this field is +String+.
443
458
  # password::
444
- # The password of the user
459
+ # The password for the user. Any UTF8 character is allowed, e.g. spaces, emojis, non-English characers, etc.
445
460
  # The type of this field is +String+.
446
461
  # session_token::
447
462
  # The `session_token` associated with a User's existing Session.
@@ -512,6 +527,7 @@ module Stytch
512
527
  attributes: nil,
513
528
  options: nil
514
529
  )
530
+ headers = {}
515
531
  request = {
516
532
  token: token,
517
533
  password: password
@@ -524,7 +540,7 @@ module Stytch
524
540
  request[:attributes] = attributes unless attributes.nil?
525
541
  request[:options] = options unless options.nil?
526
542
 
527
- post_request('/v1/passwords/email/reset', request)
543
+ post_request('/v1/passwords/email/reset', request, headers)
528
544
  end
529
545
  end
530
546
 
@@ -537,6 +553,8 @@ module Stytch
537
553
 
538
554
  # Reset the User’s password using their existing password.
539
555
  #
556
+ # Note that a successful password reset via an existing password will revoke all active sessions for the `user_id`.
557
+ #
540
558
  # == Parameters:
541
559
  # email::
542
560
  # The email address of the end user.
@@ -605,6 +623,7 @@ module Stytch
605
623
  session_jwt: nil,
606
624
  session_custom_claims: nil
607
625
  )
626
+ headers = {}
608
627
  request = {
609
628
  email: email,
610
629
  existing_password: existing_password,
@@ -615,7 +634,7 @@ module Stytch
615
634
  request[:session_jwt] = session_jwt unless session_jwt.nil?
616
635
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
617
636
 
618
- post_request('/v1/passwords/existing_password/reset', request)
637
+ post_request('/v1/passwords/existing_password/reset', request, headers)
619
638
  end
620
639
  end
621
640
 
@@ -628,9 +647,11 @@ module Stytch
628
647
 
629
648
  # Reset the user’s password using their existing session. The endpoint will error if the session does not have a password, email magic link, or email OTP authentication factor that has been issued within the last 5 minutes. This endpoint requires either a `session_jwt` or `session_token` be included in the request.
630
649
  #
650
+ # Note that a successful password reset via an existing session will revoke all active sessions for the `user_id`, except for the one used during the reset flow.
651
+ #
631
652
  # == Parameters:
632
653
  # password::
633
- # The password of the user
654
+ # The password for the user. Any UTF8 character is allowed, e.g. spaces, emojis, non-English characers, etc.
634
655
  # The type of this field is +String+.
635
656
  # session_token::
636
657
  # The `session_token` associated with a User's existing Session.
@@ -638,6 +659,22 @@ module Stytch
638
659
  # session_jwt::
639
660
  # The `session_jwt` associated with a User's existing Session.
640
661
  # The type of this field is nilable +String+.
662
+ # session_duration_minutes::
663
+ # Set the session lifetime to be this many minutes from now. This will start a new session if one doesn't already exist,
664
+ # returning both an opaque `session_token` and `session_jwt` for this session. Remember that the `session_jwt` will have a fixed lifetime of
665
+ # five minutes regardless of the underlying session duration, and will need to be refreshed over time.
666
+ #
667
+ # This value must be a minimum of 5 and a maximum of 527040 minutes (366 days).
668
+ #
669
+ # If a `session_token` or `session_jwt` is provided then a successful authentication will continue to extend the session this many minutes.
670
+ #
671
+ # If the `session_duration_minutes` parameter is not specified, a Stytch session will not be created.
672
+ # The type of this field is nilable +Integer+.
673
+ # session_custom_claims::
674
+ # Add a custom claims map to the Session being authenticated. Claims are only created if a Session is initialized by providing a value in `session_duration_minutes`. Claims will be included on the Session object and in the JWT. To update a key in an existing Session, supply a new value. To delete a key, supply a null value.
675
+ #
676
+ # Custom claims made with reserved claims ("iss", "sub", "aud", "exp", "nbf", "iat", "jti") will be ignored. Total custom claims size cannot exceed four kilobytes.
677
+ # The type of this field is nilable +object+.
641
678
  #
642
679
  # == Returns:
643
680
  # An object with the following fields:
@@ -650,6 +687,12 @@ module Stytch
650
687
  # user::
651
688
  # The `user` object affected by this API call. See the [Get user endpoint](https://stytch.com/docs/api/get-user) for complete response field details.
652
689
  # The type of this field is +User+ (+object+).
690
+ # session_token::
691
+ # A secret token for a given Stytch Session.
692
+ # The type of this field is +String+.
693
+ # session_jwt::
694
+ # The JSON Web Token (JWT) for a given Stytch Session.
695
+ # The type of this field is +String+.
653
696
  # status_code::
654
697
  # 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.
655
698
  # The type of this field is +Integer+.
@@ -662,15 +705,20 @@ module Stytch
662
705
  def reset(
663
706
  password:,
664
707
  session_token: nil,
665
- session_jwt: nil
708
+ session_jwt: nil,
709
+ session_duration_minutes: nil,
710
+ session_custom_claims: nil
666
711
  )
712
+ headers = {}
667
713
  request = {
668
714
  password: password
669
715
  }
670
716
  request[:session_token] = session_token unless session_token.nil?
671
717
  request[:session_jwt] = session_jwt unless session_jwt.nil?
718
+ request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
719
+ request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
672
720
 
673
- post_request('/v1/passwords/session/reset', request)
721
+ post_request('/v1/passwords/session/reset', request, headers)
674
722
  end
675
723
  end
676
724
  end