stytch 5.0.2 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,67 +1,247 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # !!!
4
+ # WARNING: This file is autogenerated
5
+ # Only modify code within MANUAL() sections
6
+ # or your changes may be overwritten later!
7
+ # !!!
8
+
3
9
  require_relative 'request_helper'
4
10
 
5
11
  module Stytch
6
12
  class Passwords
7
13
  include Stytch::RequestHelper
8
-
9
- attr_reader :email, :existing_password, :session
10
-
11
- PATH = '/v1/passwords'
14
+ attr_reader :email, :existing_password, :sessions
12
15
 
13
16
  def initialize(connection)
14
17
  @connection = connection
15
18
 
16
19
  @email = Stytch::Passwords::Email.new(@connection)
17
20
  @existing_password = Stytch::Passwords::ExistingPassword.new(@connection)
18
- @session = Stytch::Passwords::Session.new(@connection)
21
+ @sessions = Stytch::Passwords::Sessions.new(@connection)
19
22
  end
20
23
 
24
+ # Create a new user with a password and an authenticated session for the user if requested. If a user with this email already exists in the project, this API will return an error.
25
+ #
26
+ # Existing passwordless users who wish to create a password need to go through the reset password flow.
27
+ #
28
+ # This endpoint will return an error if the password provided does not meet our strength requirements, which you can check beforehand with the password strength endpoint.
29
+ #
30
+ # == Parameters:
31
+ # email::
32
+ # The email address of the end user.
33
+ # The type of this field is +String+.
34
+ # password::
35
+ # The password of the user
36
+ # The type of this field is +String+.
37
+ # session_duration_minutes::
38
+ # Set the session lifetime to be this many minutes from now. This will start a new session if one doesn't already exist,
39
+ # returning both an opaque `session_token` and `session_jwt` for this session. Remember that the `session_jwt` will have a fixed lifetime of
40
+ # five minutes regardless of the underlying session duration, and will need to be refreshed over time.
41
+ #
42
+ # This value must be a minimum of 5 and a maximum of 527040 minutes (366 days).
43
+ #
44
+ # If a `session_token` or `session_jwt` is provided then a successful authentication will continue to extend the session this many minutes.
45
+ #
46
+ # If the `session_duration_minutes` parameter is not specified, a Stytch session will not be created.
47
+ # The type of this field is nilable +Integer+.
48
+ # session_custom_claims::
49
+ # 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.
50
+ #
51
+ # Custom claims made with reserved claims ("iss", "sub", "aud", "exp", "nbf", "iat", "jti") will be ignored. Total custom claims size cannot exceed four kilobytes.
52
+ # The type of this field is nilable +object+.
53
+ # trusted_metadata::
54
+ # The `trusted_metadata` field contains an arbitrary JSON object of application-specific data. See the [Metadata](https://stytch.com/docs/api/metadata) reference for complete field behavior details.
55
+ # The type of this field is nilable +object+.
56
+ # untrusted_metadata::
57
+ # 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.
58
+ # The type of this field is nilable +object+.
59
+ # name::
60
+ # The name of the user. Each field in the name object is optional.
61
+ # The type of this field is nilable +Name+ (+object+).
62
+ #
63
+ # == Returns:
64
+ # An object with the following fields:
65
+ # request_id::
66
+ # Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
67
+ # The type of this field is +String+.
68
+ # user_id::
69
+ # The unique ID of the affected User.
70
+ # The type of this field is +String+.
71
+ # email_id::
72
+ # The unique ID of a specific email address.
73
+ # The type of this field is +String+.
74
+ # session_token::
75
+ # A secret token for a given Stytch Session.
76
+ # The type of this field is +String+.
77
+ # session_jwt::
78
+ # The JSON Web Token (JWT) for a given Stytch Session.
79
+ # The type of this field is +String+.
80
+ # user::
81
+ # 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.
82
+ # The type of this field is +User+ (+object+).
83
+ # status_code::
84
+ # 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.
85
+ # The type of this field is +Integer+.
86
+ # session::
87
+ # If you initiate a Session, by including `session_duration_minutes` in your authenticate call, you'll receive a full Session object in the response.
88
+ #
89
+ # See [GET sessions](https://stytch.com/docs/api/session-get) for complete response fields.
90
+ #
91
+ # The type of this field is nilable +Session+ (+object+).
21
92
  def create(
22
93
  email:,
23
94
  password:,
24
- name: {},
25
95
  session_duration_minutes: nil,
26
96
  session_custom_claims: nil,
27
- trusted_metadata: {},
28
- untrusted_metadata: {}
97
+ trusted_metadata: nil,
98
+ untrusted_metadata: nil,
99
+ name: nil
29
100
  )
30
101
  request = {
31
102
  email: email,
32
103
  password: password
33
104
  }
34
-
35
- request[:name] = name if name != {}
36
105
  request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
37
106
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
38
- request[:trusted_metadata] = trusted_metadata if trusted_metadata != {}
39
- request[:untrusted_metadata] = untrusted_metadata if untrusted_metadata != {}
107
+ request[:trusted_metadata] = trusted_metadata unless trusted_metadata.nil?
108
+ request[:untrusted_metadata] = untrusted_metadata unless untrusted_metadata.nil?
109
+ request[:name] = name unless name.nil?
40
110
 
41
- post_request(PATH.to_s, request)
111
+ post_request('/v1/passwords', request)
42
112
  end
43
113
 
114
+ # 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:
115
+ #
116
+ # **One:** The user’s credentials appeared in the HaveIBeenPwned dataset. We force a password reset to ensure that the user is the legitimate owner of the email address, and not a malicious actor abusing the compromised credentials.
117
+ #
118
+ # **Two:** A user that has previously authenticated with email/password uses a passwordless authentication method tied to the same email address (e.g. Magic Links, Google OAuth) for the first time. Any subsequent email/password authentication attempt will result in this error. We force a password reset in this instance in order to safely deduplicate the account by email address, without introducing the risk of a pre-hijack account takeover attack.
119
+ #
120
+ # Imagine a bad actor creates many accounts using passwords and the known email addresses of their victims. If a victim comes to the site and logs in for the first time with an email-based passwordless authentication method then both the victim and the bad actor have credentials to access to the same account. To prevent this, any further email/password login attempts first require a password reset which can only be accomplished by someone with access to the underlying email address.
121
+ #
122
+ # == Parameters:
123
+ # email::
124
+ # The email address of the end user.
125
+ # The type of this field is +String+.
126
+ # password::
127
+ # The password of the user
128
+ # The type of this field is +String+.
129
+ # session_token::
130
+ # The `session_token` associated with a User's existing Session.
131
+ # The type of this field is nilable +String+.
132
+ # session_duration_minutes::
133
+ # Set the session lifetime to be this many minutes from now. This will start a new session if one doesn't already exist,
134
+ # returning both an opaque `session_token` and `session_jwt` for this session. Remember that the `session_jwt` will have a fixed lifetime of
135
+ # five minutes regardless of the underlying session duration, and will need to be refreshed over time.
136
+ #
137
+ # This value must be a minimum of 5 and a maximum of 527040 minutes (366 days).
138
+ #
139
+ # If a `session_token` or `session_jwt` is provided then a successful authentication will continue to extend the session this many minutes.
140
+ #
141
+ # If the `session_duration_minutes` parameter is not specified, a Stytch session will not be created.
142
+ # The type of this field is nilable +Integer+.
143
+ # session_jwt::
144
+ # The `session_jwt` associated with a User's existing Session.
145
+ # The type of this field is nilable +String+.
146
+ # session_custom_claims::
147
+ # 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.
148
+ #
149
+ # Custom claims made with reserved claims ("iss", "sub", "aud", "exp", "nbf", "iat", "jti") will be ignored. Total custom claims size cannot exceed four kilobytes.
150
+ # The type of this field is nilable +object+.
151
+ #
152
+ # == Returns:
153
+ # An object with the following fields:
154
+ # request_id::
155
+ # Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
156
+ # The type of this field is +String+.
157
+ # user_id::
158
+ # The unique ID of the affected User.
159
+ # The type of this field is +String+.
160
+ # session_token::
161
+ # A secret token for a given Stytch Session.
162
+ # The type of this field is +String+.
163
+ # session_jwt::
164
+ # The JSON Web Token (JWT) for a given Stytch Session.
165
+ # The type of this field is +String+.
166
+ # user::
167
+ # 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.
168
+ # The type of this field is +User+ (+object+).
169
+ # status_code::
170
+ # 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.
171
+ # The type of this field is +Integer+.
172
+ # session::
173
+ # If you initiate a Session, by including `session_duration_minutes` in your authenticate call, you'll receive a full Session object in the response.
174
+ #
175
+ # See [GET sessions](https://stytch.com/docs/api/session-get) for complete response fields.
176
+ #
177
+ # The type of this field is nilable +Session+ (+object+).
44
178
  def authenticate(
45
179
  email:,
46
180
  password:,
47
181
  session_token: nil,
48
- session_jwt: nil,
49
182
  session_duration_minutes: nil,
183
+ session_jwt: nil,
50
184
  session_custom_claims: nil
51
185
  )
52
186
  request = {
53
187
  email: email,
54
188
  password: password
55
189
  }
56
-
57
190
  request[:session_token] = session_token unless session_token.nil?
58
- request[:session_jwt] = session_jwt unless session_jwt.nil?
59
191
  request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
192
+ request[:session_jwt] = session_jwt unless session_jwt.nil?
60
193
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
61
194
 
62
- post_request("#{PATH}/authenticate", request)
195
+ post_request('/v1/passwords/authenticate', request)
63
196
  end
64
197
 
198
+ # 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.
199
+ #
200
+ # This endpoint adapts to your Project's password strength configuration. If you're using [zxcvbn](https://stytch.com/docs/passwords#strength-requirements), the default, your passwords are considered valid if the strength score is >= 3. If you're using [LUDS](https://stytch.com/docs/passwords#strength-requirements), your passwords are considered valid if they meet the requirements that you've set with Stytch. You may update your password strength configuration in the [stytch dashboard](https://stytch.com/dashboard/password-strength-config).
201
+ #
202
+ #
203
+ # ### Password feedback
204
+ #
205
+ # The `feedback` object contains relevant fields for you to relay feedback to users that failed to create a strong enough password.
206
+ #
207
+ # If you're using zxcvbn, the `feedback` object will contain `warning` and `suggestions` for any password that does not meet the zxcvbn strength requirements. You can return these strings directly to the user to help them craft a strong password.
208
+ #
209
+ # If you're using LUDS, the `feedback` object will contain an object named `luds_requirements` which contain a collection of fields that the user failed or passed. You'll want to prompt the user to create a password that meets all of the requirements that they failed.
210
+ #
211
+ # == Parameters:
212
+ # password::
213
+ # The password of the user
214
+ # The type of this field is +String+.
215
+ # email::
216
+ # The email address of the end user.
217
+ # The type of this field is nilable +String+.
218
+ #
219
+ # == Returns:
220
+ # An object with the following fields:
221
+ # request_id::
222
+ # Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
223
+ # The type of this field is +String+.
224
+ # valid_password::
225
+ # Returns `true` if the password passes our password validation. We offer two validation options, [zxcvbn](https://stytch.com/docs/passwords#strength-requirements) is the default option which offers a high level of sophistication. We also offer [LUDS](https://stytch.com/docs/passwords#strength-requirements). If an email address is included in the call we also require that the password hasn't been compromised using built-in breach detection powered by [HaveIBeenPwned](https://haveibeenpwned.com/).
226
+ # The type of this field is +Boolean+.
227
+ # score::
228
+ # The score of the password determined by [zxcvbn](https://github.com/dropbox/zxcvbn). Values will be between 1 and 4, a 3 or greater is required to pass validation.
229
+ # The type of this field is +Integer+.
230
+ # breached_password::
231
+ # Returns `true` if the password has been breached. Powered by [HaveIBeenPwned](https://haveibeenpwned.com/).
232
+ # The type of this field is +Boolean+.
233
+ # strength_policy::
234
+ # The strength policy type enforced, either `zxcvbn` or `luds`.
235
+ # The type of this field is +String+.
236
+ # breach_detection_on_create::
237
+ # Will return `true` if breach detection will be evaluated. By default this option is enabled. This option can be disabled by contacting [support@stytch.com](mailto:support@stytch.com?subject=Password%20strength%20configuration). If this value is `false` then `breached_password` will always be `false` as well.
238
+ # The type of this field is +Boolean+.
239
+ # status_code::
240
+ # 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.
241
+ # The type of this field is +Integer+.
242
+ # feedback::
243
+ # Feedback for how to improve the password's strength [HaveIBeenPwned](https://haveibeenpwned.com/).
244
+ # The type of this field is nilable +Feedback+ (+object+).
65
245
  def strength_check(
66
246
  password:,
67
247
  email: nil
@@ -69,123 +249,358 @@ module Stytch
69
249
  request = {
70
250
  password: password
71
251
  }
72
-
73
252
  request[:email] = email unless email.nil?
74
253
 
75
- post_request("#{PATH}/strength_check", request)
254
+ post_request('/v1/passwords/strength_check', request)
76
255
  end
77
256
 
257
+ # 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.
258
+ #
259
+ # == Parameters:
260
+ # email::
261
+ # The email address of the end user.
262
+ # The type of this field is +String+.
263
+ # hash::
264
+ # The password hash. For a Scrypt or PBKDF2 hash, the hash needs to be a base64 encoded string.
265
+ # The type of this field is +String+.
266
+ # hash_type::
267
+ # The password hash used. Currently `bcrypt`, `scrypt`, `argon_2i`, `argon_2id`, `md_5`, `sha_1`, and `pbkdf_2` are supported.
268
+ # The type of this field is +MigrateRequestHashType+ (string enum).
269
+ # md_5_config::
270
+ # Optional parameters for MD-5 hash types.
271
+ # The type of this field is nilable +MD5Config+ (+object+).
272
+ # argon_2_config::
273
+ # Required parameters if the argon2 hex form, as opposed to the encoded form, is supplied.
274
+ # The type of this field is nilable +Argon2Config+ (+object+).
275
+ # sha_1_config::
276
+ # Optional parameters for SHA-1 hash types.
277
+ # The type of this field is nilable +SHA1Config+ (+object+).
278
+ # scrypt_config::
279
+ # Required parameters if the scrypt is not provided in a [PHC encoded form](https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md#phc-string-format).
280
+ # The type of this field is nilable +ScryptConfig+ (+object+).
281
+ # pbkdf_2_config::
282
+ # Required additional parameters for PBKDF2 hash keys.
283
+ # The type of this field is nilable +PBKDF2Config+ (+object+).
284
+ # trusted_metadata::
285
+ # The `trusted_metadata` field contains an arbitrary JSON object of application-specific data. See the [Metadata](https://stytch.com/docs/api/metadata) reference for complete field behavior details.
286
+ # The type of this field is nilable +object+.
287
+ # untrusted_metadata::
288
+ # 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.
289
+ # The type of this field is nilable +object+.
290
+ # name::
291
+ # The name of the user. Each field in the name object is optional.
292
+ # The type of this field is nilable +Name+ (+object+).
293
+ #
294
+ # == Returns:
295
+ # An object with the following fields:
296
+ # request_id::
297
+ # Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
298
+ # The type of this field is +String+.
299
+ # user_id::
300
+ # The unique ID of the affected User.
301
+ # The type of this field is +String+.
302
+ # email_id::
303
+ # The unique ID of a specific email address.
304
+ # The type of this field is +String+.
305
+ # user_created::
306
+ # In `login_or_create` endpoints, this field indicates whether or not a User was just created.
307
+ # The type of this field is +Boolean+.
308
+ # user::
309
+ # 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.
310
+ # The type of this field is +User+ (+object+).
311
+ # status_code::
312
+ # 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.
313
+ # The type of this field is +Integer+.
78
314
  def migrate(
79
315
  email:,
80
316
  hash:,
81
317
  hash_type:,
82
- name: {},
83
- trusted_metadata: {},
84
- untrusted_metadata: {},
85
- md_5_config: {},
86
- argon_2_config: {},
87
- sha_1_config: {},
88
- scrypt_config: {}
318
+ md_5_config: nil,
319
+ argon_2_config: nil,
320
+ sha_1_config: nil,
321
+ scrypt_config: nil,
322
+ pbkdf_2_config: nil,
323
+ trusted_metadata: nil,
324
+ untrusted_metadata: nil,
325
+ name: nil
89
326
  )
90
327
  request = {
91
328
  email: email,
92
329
  hash: hash,
93
330
  hash_type: hash_type
94
331
  }
95
-
96
- request[:name] = name if name != {}
97
- request[:trusted_metadata] = trusted_metadata if trusted_metadata != {}
98
- request[:untrusted_metadata] = untrusted_metadata if untrusted_metadata != {}
99
-
100
- request[:md_5_config] = md_5_config unless md_5_config != {}
101
- request[:argon_2_config] = argon_2_config unless argon_2_config != {}
102
- request[:sha_1_config] = sha_1_config unless sha_1_config != {}
103
- request[:scrypt_config] = scrypt_config unless scrypt_config != {}
104
-
105
- post_request("#{PATH}/migrate", request)
332
+ request[:md_5_config] = md_5_config unless md_5_config.nil?
333
+ request[:argon_2_config] = argon_2_config unless argon_2_config.nil?
334
+ request[:sha_1_config] = sha_1_config unless sha_1_config.nil?
335
+ request[:scrypt_config] = scrypt_config unless scrypt_config.nil?
336
+ request[:pbkdf_2_config] = pbkdf_2_config unless pbkdf_2_config.nil?
337
+ request[:trusted_metadata] = trusted_metadata unless trusted_metadata.nil?
338
+ request[:untrusted_metadata] = untrusted_metadata unless untrusted_metadata.nil?
339
+ request[:name] = name unless name.nil?
340
+
341
+ post_request('/v1/passwords/migrate', request)
106
342
  end
107
343
 
108
344
  class Email
109
345
  include Stytch::RequestHelper
110
346
 
111
- PATH = "#{Stytch::Passwords::PATH}/email"
112
-
113
347
  def initialize(connection)
114
348
  @connection = connection
115
349
  end
116
350
 
351
+ # Initiates a password reset for the email address provided. This will trigger an email to be sent to the address, containing a magic link that will allow them to set a new password and authenticate.
352
+ #
353
+ # == Parameters:
354
+ # email::
355
+ # The email of the User that requested the password reset.
356
+ # The type of this field is +String+.
357
+ # reset_password_redirect_url::
358
+ # The url that the user clicks from the password reset email to finish the reset password flow.
359
+ # This should be a url that your app receives and parses before showing your app's reset password page.
360
+ # After the user submits a new password to your app, it should send an API request to complete the password reset process.
361
+ # If this value is not passed, the default reset password redirect URL that you set in your Dashboard is used.
362
+ # If you have not set a default reset password redirect URL, an error is returned.
363
+ # The type of this field is nilable +String+.
364
+ # reset_password_expiration_minutes::
365
+ # Set the expiration for the password reset, in minutes. By default, it expires in 30 minutes.
366
+ # The minimum expiration is 5 minutes and the maximum is 7 days (10080 mins).
367
+ # The type of this field is nilable +Integer+.
368
+ # code_challenge::
369
+ # A base64url encoded SHA256 hash of a one time secret used to validate that the request starts and ends on the same device.
370
+ # The type of this field is nilable +String+.
371
+ # attributes::
372
+ # Provided attributes help with fraud detection.
373
+ # The type of this field is nilable +Attributes+ (+object+).
374
+ # login_redirect_url::
375
+ # The URL Stytch redirects to after the OAuth flow is completed for a user that already exists. This URL should be a route in your application which will run `oauth.authenticate` (see below) and finish the login.
376
+ #
377
+ # The URL must be configured as a Login URL in the [Redirect URL page](/dashboard/redirect-urls). If the field is not specified, the default Login URL will be used.
378
+ # The type of this field is nilable +String+.
379
+ # locale::
380
+ # Used to determine which language to use when sending the user this delivery method. Parameter is a [IETF BCP 47 language tag](https://www.w3.org/International/articles/language-tags/), e.g. `"en"`.
381
+ #
382
+ # Currently supported languages are English (`"en"`), Spanish (`"es"`), and Brazilian Portuguese (`"pt-br"`); if no value is provided, the copy defaults to English.
383
+ #
384
+ # Request support for additional languages [here](https://docs.google.com/forms/d/e/1FAIpQLScZSpAu_m2AmLXRT3F3kap-s_mcV6UTBitYn6CdyWP0-o7YjQ/viewform?usp=sf_link")!
385
+ #
386
+ # The type of this field is nilable +ResetStartRequestLocale+ (string enum).
387
+ # reset_password_template_id::
388
+ # Use a custom template for password reset emails. By default, it will use your default email template.
389
+ # The template must be a template using our built-in customizations or a custom HTML email for Passwords - Password reset.
390
+ # The type of this field is nilable +String+.
391
+ #
392
+ # == Returns:
393
+ # An object with the following fields:
394
+ # request_id::
395
+ # Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
396
+ # The type of this field is +String+.
397
+ # user_id::
398
+ # The unique ID of the affected User.
399
+ # The type of this field is +String+.
400
+ # email_id::
401
+ # The unique ID of a specific email address.
402
+ # The type of this field is +String+.
403
+ # status_code::
404
+ # 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.
405
+ # The type of this field is +Integer+.
117
406
  def reset_start(
118
407
  email:,
119
- login_redirect_url: nil,
120
408
  reset_password_redirect_url: nil,
121
409
  reset_password_expiration_minutes: nil,
122
- attributes: {},
123
410
  code_challenge: nil,
411
+ attributes: nil,
412
+ login_redirect_url: nil,
124
413
  locale: nil,
125
414
  reset_password_template_id: nil
126
415
  )
127
416
  request = {
128
417
  email: email
129
418
  }
130
-
131
- request[:login_redirect_url] = login_redirect_url unless login_redirect_url.nil?
132
419
  request[:reset_password_redirect_url] = reset_password_redirect_url unless reset_password_redirect_url.nil?
133
420
  unless reset_password_expiration_minutes.nil?
134
421
  request[:reset_password_expiration_minutes] =
135
422
  reset_password_expiration_minutes
136
423
  end
137
- request[:attributes] = attributes if attributes != {}
138
424
  request[:code_challenge] = code_challenge unless code_challenge.nil?
425
+ request[:attributes] = attributes unless attributes.nil?
426
+ request[:login_redirect_url] = login_redirect_url unless login_redirect_url.nil?
139
427
  request[:locale] = locale unless locale.nil?
140
428
  request[:reset_password_template_id] = reset_password_template_id unless reset_password_template_id.nil?
141
429
 
142
- post_request("#{PATH}/reset/start", request)
430
+ post_request('/v1/passwords/email/reset/start', request)
143
431
  end
144
432
 
433
+ # 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.
434
+ #
435
+ # 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.
436
+ #
437
+ # == Parameters:
438
+ # token::
439
+ # The token to authenticate.
440
+ # The type of this field is +String+.
441
+ # password::
442
+ # The password of the user
443
+ # The type of this field is +String+.
444
+ # session_token::
445
+ # The `session_token` associated with a User's existing Session.
446
+ # The type of this field is nilable +String+.
447
+ # session_duration_minutes::
448
+ # Set the session lifetime to be this many minutes from now. This will start a new session if one doesn't already exist,
449
+ # returning both an opaque `session_token` and `session_jwt` for this session. Remember that the `session_jwt` will have a fixed lifetime of
450
+ # five minutes regardless of the underlying session duration, and will need to be refreshed over time.
451
+ #
452
+ # This value must be a minimum of 5 and a maximum of 527040 minutes (366 days).
453
+ #
454
+ # If a `session_token` or `session_jwt` is provided then a successful authentication will continue to extend the session this many minutes.
455
+ #
456
+ # If the `session_duration_minutes` parameter is not specified, a Stytch session will not be created.
457
+ # The type of this field is nilable +Integer+.
458
+ # session_jwt::
459
+ # The `session_jwt` associated with a User's existing Session.
460
+ # The type of this field is nilable +String+.
461
+ # code_verifier::
462
+ # A base64url encoded one time secret used to validate that the request starts and ends on the same device.
463
+ # The type of this field is nilable +String+.
464
+ # session_custom_claims::
465
+ # 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.
466
+ #
467
+ # Custom claims made with reserved claims ("iss", "sub", "aud", "exp", "nbf", "iat", "jti") will be ignored. Total custom claims size cannot exceed four kilobytes.
468
+ # The type of this field is nilable +object+.
469
+ # attributes::
470
+ # Provided attributes help with fraud detection.
471
+ # The type of this field is nilable +Attributes+ (+object+).
472
+ # options::
473
+ # Specify optional security settings.
474
+ # The type of this field is nilable +Options+ (+object+).
475
+ #
476
+ # == Returns:
477
+ # An object with the following fields:
478
+ # request_id::
479
+ # Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
480
+ # The type of this field is +String+.
481
+ # user_id::
482
+ # The unique ID of the affected User.
483
+ # The type of this field is +String+.
484
+ # session_token::
485
+ # A secret token for a given Stytch Session.
486
+ # The type of this field is +String+.
487
+ # session_jwt::
488
+ # The JSON Web Token (JWT) for a given Stytch Session.
489
+ # The type of this field is +String+.
490
+ # user::
491
+ # 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.
492
+ # The type of this field is +User+ (+object+).
493
+ # status_code::
494
+ # 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.
495
+ # The type of this field is +Integer+.
496
+ # session::
497
+ # If you initiate a Session, by including `session_duration_minutes` in your authenticate call, you'll receive a full Session object in the response.
498
+ #
499
+ # See [GET sessions](https://stytch.com/docs/api/session-get) for complete response fields.
500
+ #
501
+ # The type of this field is nilable +Session+ (+object+).
145
502
  def reset(
146
503
  token:,
147
504
  password:,
148
505
  session_token: nil,
149
- session_jwt: nil,
150
506
  session_duration_minutes: nil,
507
+ session_jwt: nil,
508
+ code_verifier: nil,
151
509
  session_custom_claims: nil,
152
- attributes: {},
153
- options: {},
154
- code_verifier: nil
510
+ attributes: nil,
511
+ options: nil
155
512
  )
156
513
  request = {
157
514
  token: token,
158
515
  password: password
159
516
  }
160
-
161
517
  request[:session_token] = session_token unless session_token.nil?
162
- request[:session_jwt] = session_jwt unless session_jwt.nil?
163
518
  request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
164
- request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
165
- request[:attributes] = attributes if attributes != {}
166
- request[:options] = options if options != {}
519
+ request[:session_jwt] = session_jwt unless session_jwt.nil?
167
520
  request[:code_verifier] = code_verifier unless code_verifier.nil?
521
+ request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
522
+ request[:attributes] = attributes unless attributes.nil?
523
+ request[:options] = options unless options.nil?
168
524
 
169
- post_request("#{PATH}/reset", request)
525
+ post_request('/v1/passwords/email/reset', request)
170
526
  end
171
527
  end
172
528
 
173
529
  class ExistingPassword
174
530
  include Stytch::RequestHelper
175
531
 
176
- PATH = "#{Stytch::Passwords::PATH}/existing_password"
177
-
178
532
  def initialize(connection)
179
533
  @connection = connection
180
534
  end
181
535
 
536
+ # Reset the User’s password using their existing password.
537
+ #
538
+ # == Parameters:
539
+ # email::
540
+ # The email address of the end user.
541
+ # The type of this field is +String+.
542
+ # existing_password::
543
+ # The user's existing password.
544
+ # The type of this field is +String+.
545
+ # new_password::
546
+ # The new password for the user.
547
+ # The type of this field is +String+.
548
+ # session_token::
549
+ # The `session_token` associated with a User's existing Session.
550
+ # The type of this field is nilable +String+.
551
+ # session_duration_minutes::
552
+ # Set the session lifetime to be this many minutes from now. This will start a new session if one doesn't already exist,
553
+ # returning both an opaque `session_token` and `session_jwt` for this session. Remember that the `session_jwt` will have a fixed lifetime of
554
+ # five minutes regardless of the underlying session duration, and will need to be refreshed over time.
555
+ #
556
+ # This value must be a minimum of 5 and a maximum of 527040 minutes (366 days).
557
+ #
558
+ # If a `session_token` or `session_jwt` is provided then a successful authentication will continue to extend the session this many minutes.
559
+ #
560
+ # If the `session_duration_minutes` parameter is not specified, a Stytch session will not be created.
561
+ # The type of this field is nilable +Integer+.
562
+ # session_jwt::
563
+ # The `session_jwt` associated with a User's existing Session.
564
+ # The type of this field is nilable +String+.
565
+ # session_custom_claims::
566
+ # 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.
567
+ #
568
+ # Custom claims made with reserved claims ("iss", "sub", "aud", "exp", "nbf", "iat", "jti") will be ignored. Total custom claims size cannot exceed four kilobytes.
569
+ # The type of this field is nilable +object+.
570
+ #
571
+ # == Returns:
572
+ # An object with the following fields:
573
+ # request_id::
574
+ # Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
575
+ # The type of this field is +String+.
576
+ # user_id::
577
+ # The unique ID of the affected User.
578
+ # The type of this field is +String+.
579
+ # session_token::
580
+ # A secret token for a given Stytch Session.
581
+ # The type of this field is +String+.
582
+ # session_jwt::
583
+ # The JSON Web Token (JWT) for a given Stytch Session.
584
+ # The type of this field is +String+.
585
+ # user::
586
+ # 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.
587
+ # The type of this field is +User+ (+object+).
588
+ # status_code::
589
+ # 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.
590
+ # The type of this field is +Integer+.
591
+ # session::
592
+ # If you initiate a Session, by including `session_duration_minutes` in your authenticate call, you'll receive a full Session object in the response.
593
+ #
594
+ # See [GET sessions](https://stytch.com/docs/api/session-get) for complete response fields.
595
+ #
596
+ # The type of this field is nilable +Session+ (+object+).
182
597
  def reset(
183
598
  email:,
184
599
  existing_password:,
185
600
  new_password:,
186
601
  session_token: nil,
187
- session_jwt: nil,
188
602
  session_duration_minutes: nil,
603
+ session_jwt: nil,
189
604
  session_custom_claims: nil
190
605
  )
191
606
  request = {
@@ -193,36 +608,67 @@ module Stytch
193
608
  existing_password: existing_password,
194
609
  new_password: new_password
195
610
  }
196
-
197
611
  request[:session_token] = session_token unless session_token.nil?
198
- request[:session_jwt] = session_jwt unless session_jwt.nil?
199
612
  request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
613
+ request[:session_jwt] = session_jwt unless session_jwt.nil?
200
614
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
201
615
 
202
- post_request("#{PATH}/reset", request)
616
+ post_request('/v1/passwords/existing_password/reset', request)
203
617
  end
204
618
  end
205
619
 
206
- class Session
620
+ class Sessions
207
621
  include Stytch::RequestHelper
208
622
 
209
- PATH = "#{Stytch::Passwords::PATH}/session"
210
-
211
623
  def initialize(connection)
212
624
  @connection = connection
213
625
  end
214
626
 
627
+ # 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.
628
+ #
629
+ # == Parameters:
630
+ # password::
631
+ # The password of the user
632
+ # The type of this field is +String+.
633
+ # session_token::
634
+ # The `session_token` associated with a User's existing Session.
635
+ # The type of this field is nilable +String+.
636
+ # session_jwt::
637
+ # The `session_jwt` associated with a User's existing Session.
638
+ # The type of this field is nilable +String+.
639
+ #
640
+ # == Returns:
641
+ # An object with the following fields:
642
+ # request_id::
643
+ # Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
644
+ # The type of this field is +String+.
645
+ # user_id::
646
+ # The unique ID of the affected User.
647
+ # The type of this field is +String+.
648
+ # user::
649
+ # 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.
650
+ # The type of this field is +User+ (+object+).
651
+ # status_code::
652
+ # 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.
653
+ # The type of this field is +Integer+.
654
+ # session::
655
+ # If you initiate a Session, by including `session_duration_minutes` in your authenticate call, you'll receive a full Session object in the response.
656
+ #
657
+ # See [GET sessions](https://stytch.com/docs/api/session-get) for complete response fields.
658
+ #
659
+ # The type of this field is nilable +Session+ (+object+).
215
660
  def reset(
216
661
  password:,
217
662
  session_token: nil,
218
663
  session_jwt: nil
219
664
  )
220
- request = { password: password }
221
-
665
+ request = {
666
+ password: password
667
+ }
222
668
  request[:session_token] = session_token unless session_token.nil?
223
669
  request[:session_jwt] = session_jwt unless session_jwt.nil?
224
670
 
225
- post_request("#{PATH}/reset", request)
671
+ post_request('/v1/passwords/session/reset', request)
226
672
  end
227
673
  end
228
674
  end