stytch 5.0.2 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,13 @@
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 'jwt'
4
10
  require 'json/jwt'
5
-
6
11
  require_relative 'errors'
7
12
  require_relative 'request_helper'
8
13
 
@@ -10,10 +15,9 @@ module Stytch
10
15
  class Sessions
11
16
  include Stytch::RequestHelper
12
17
 
13
- PATH = '/v1/sessions'
14
-
15
18
  def initialize(connection, project_id)
16
19
  @connection = connection
20
+
17
21
  @project_id = project_id
18
22
  @cache_last_update = 0
19
23
  @jwks_loader = lambda do |options|
@@ -21,7 +25,7 @@ module Stytch
21
25
  @cached_keys ||= begin
22
26
  @cache_last_update = Time.now.to_i
23
27
  keys = []
24
- jwks(project_id: @project_id)['keys'].each do |r|
28
+ get_jwks(project_id: @project_id)['keys'].each do |r|
25
29
  keys << r
26
30
  end
27
31
  { keys: keys }
@@ -29,51 +33,158 @@ module Stytch
29
33
  end
30
34
  end
31
35
 
32
- def get(user_id:)
36
+ # List all active Sessions for a given `user_id`. All timestamps are formatted according to the RFC 3339 standard and are expressed in UTC, e.g. `2021-12-29T12:33:09Z`.
37
+ #
38
+ # == Parameters:
39
+ # user_id::
40
+ # The `user_id` to get active Sessions for.
41
+ # The type of this field is +String+.
42
+ #
43
+ # == Returns:
44
+ # An object with the following fields:
45
+ # request_id::
46
+ # 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.
47
+ # The type of this field is +String+.
48
+ # sessions::
49
+ # An array of Session objects.
50
+ # The type of this field is list of +Session+ (+object+).
51
+ # status_code::
52
+ # 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.
53
+ # The type of this field is +Integer+.
54
+ def get(
55
+ user_id:
56
+ )
33
57
  query_params = {
34
58
  user_id: user_id
35
59
  }
36
-
37
- request = request_with_query_params(PATH, query_params)
38
-
60
+ request = request_with_query_params('/v1/sessions', query_params)
39
61
  get_request(request)
40
62
  end
41
63
 
64
+ # Authenticate a session token and retrieve associated session data. If `session_duration_minutes` is included, update the lifetime of the session to be that many minutes from now. All timestamps are formatted according to the RFC 3339 standard and are expressed in UTC, e.g. `2021-12-29T12:33:09Z`. This endpoint requires exactly one `session_jwt` or `session_token` as part of the request. If both are included you will receive a `too_many_session_arguments` error.
65
+ #
66
+ # == Parameters:
67
+ # session_token::
68
+ # The session token to authenticate.
69
+ # The type of this field is nilable +String+.
70
+ # session_duration_minutes::
71
+ # Set the session lifetime to be this many minutes from now; minimum of 5 and a maximum of 527040 minutes (366 days). Note that a successful authentication will continue to extend the session this many minutes.
72
+ # The type of this field is nilable +Integer+.
73
+ # session_jwt::
74
+ # The JWT to authenticate. You may provide a JWT that has expired according to its `exp` claim and needs to be refreshed. If the signature is valid and the underlying session is still active then Stytch will return a new JWT.
75
+ # The type of this field is nilable +String+.
76
+ # session_custom_claims::
77
+ # 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.
78
+ #
79
+ # Custom claims made with reserved claims ("iss", "sub", "aud", "exp", "nbf", "iat", "jti") will be ignored. Total custom claims size cannot exceed four kilobytes.
80
+ # The type of this field is nilable +object+.
81
+ #
82
+ # == Returns:
83
+ # An object with the following fields:
84
+ # request_id::
85
+ # 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.
86
+ # The type of this field is +String+.
87
+ # session_token::
88
+ # A secret token for a given Stytch Session.
89
+ # The type of this field is +String+.
90
+ # session_jwt::
91
+ # The JSON Web Token (JWT) for a given Stytch Session.
92
+ # The type of this field is +String+.
93
+ # user::
94
+ # 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.
95
+ # The type of this field is +User+ (+object+).
96
+ # status_code::
97
+ # 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.
98
+ # The type of this field is +Integer+.
99
+ # session::
100
+ # If you initiate a Session, by including `session_duration_minutes` in your authenticate call, you'll receive a full Session object in the response.
101
+ #
102
+ # See [GET sessions](https://stytch.com/docs/api/session-get) for complete response fields.
103
+ #
104
+ # The type of this field is nilable +Session+ (+object+).
42
105
  def authenticate(
43
106
  session_token: nil,
44
- session_jwt: nil,
45
107
  session_duration_minutes: nil,
108
+ session_jwt: nil,
46
109
  session_custom_claims: nil
47
110
  )
48
- request = {}
49
-
111
+ request = {
112
+ }
50
113
  request[:session_token] = session_token unless session_token.nil?
51
- request[:session_jwt] = session_jwt unless session_jwt.nil?
52
114
  request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
115
+ request[:session_jwt] = session_jwt unless session_jwt.nil?
53
116
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
54
117
 
55
- post_request("#{PATH}/authenticate", request)
118
+ post_request('/v1/sessions/authenticate', request)
56
119
  end
57
120
 
121
+ # Revoke a Session, immediately invalidating all of its session tokens. You can revoke a session in three ways: using its ID, or using one of its session tokens, or one of its JWTs. This endpoint requires exactly one of those to be included in the request. It will return an error if multiple are present.
122
+ #
123
+ # == Parameters:
124
+ # session_id::
125
+ # The `session_id` to revoke.
126
+ # The type of this field is nilable +String+.
127
+ # session_token::
128
+ # The session token to revoke.
129
+ # The type of this field is nilable +String+.
130
+ # session_jwt::
131
+ # A JWT for the session to revoke.
132
+ # The type of this field is nilable +String+.
133
+ #
134
+ # == Returns:
135
+ # An object with the following fields:
136
+ # request_id::
137
+ # 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.
138
+ # The type of this field is +String+.
139
+ # status_code::
140
+ # 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.
141
+ # The type of this field is +Integer+.
58
142
  def revoke(
59
143
  session_id: nil,
60
144
  session_token: nil,
61
145
  session_jwt: nil
62
146
  )
63
- request = {}
64
-
147
+ request = {
148
+ }
65
149
  request[:session_id] = session_id unless session_id.nil?
66
150
  request[:session_token] = session_token unless session_token.nil?
67
151
  request[:session_jwt] = session_jwt unless session_jwt.nil?
68
152
 
69
- post_request("#{PATH}/revoke", request)
153
+ post_request('/v1/sessions/revoke', request)
70
154
  end
71
155
 
72
- def jwks(project_id:)
73
- request_path = "#{PATH}/jwks/" + project_id
74
- get_request(request_path)
156
+ # Get the JSON Web Key Set (JWKS) for a Stytch Project.
157
+ #
158
+ # == Parameters:
159
+ # project_id::
160
+ # The `project_id` to get the JWKS for.
161
+ # The type of this field is +String+.
162
+ #
163
+ # == Returns:
164
+ # An object with the following fields:
165
+ # keys::
166
+ # The JWK
167
+ # The type of this field is list of +JWK+ (+object+).
168
+ # request_id::
169
+ # 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.
170
+ # The type of this field is +String+.
171
+ # status_code::
172
+ # 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.
173
+ # The type of this field is +Integer+.
174
+ def get_jwks(
175
+ project_id:
176
+ )
177
+ query_params = {
178
+ }
179
+ request = request_with_query_params("/v1/sessions/jwks/#{project_id}", query_params)
180
+ get_request(request)
75
181
  end
76
182
 
183
+ # MANUAL(authenticate_jwt)(SERVICE_METHOD)
184
+ # ADDIMPORT: require 'jwt'
185
+ # ADDIMPORT: require 'json/jwt'
186
+ # ADDIMPORT: require_relative 'errors'
187
+
77
188
  # Parse a JWT and verify the signature. If max_token_age_seconds is unset, call the API directly
78
189
  # If max_token_age_seconds is set and the JWT was issued (based on the "iat" claim) less than
79
190
  # max_token_age_seconds seconds ago, then just verify locally and don't call the API
@@ -88,28 +199,28 @@ module Stytch
88
199
  return authenticate(
89
200
  session_jwt: session_jwt,
90
201
  session_duration_minutes: session_duration_minutes,
91
- session_custom_claims: session_custom_claims,
202
+ session_custom_claims: session_custom_claims
92
203
  )
93
204
  end
94
205
 
95
206
  decoded_jwt = authenticate_jwt_local(session_jwt)
96
- iat_time = Time.at(decoded_jwt["iat"]).to_datetime
207
+ iat_time = Time.at(decoded_jwt['iat']).to_datetime
97
208
  if iat_time + max_token_age_seconds >= Time.now
98
209
  session = marshal_jwt_into_session(decoded_jwt)
99
- return {"session" => session}
210
+ { 'session' => session }
100
211
  else
101
- return authenticate(
212
+ authenticate(
102
213
  session_jwt: session_jwt,
103
214
  session_duration_minutes: session_duration_minutes,
104
- session_custom_claims: session_custom_claims,
215
+ session_custom_claims: session_custom_claims
105
216
  )
106
217
  end
107
218
  rescue StandardError
108
219
  # JWT could not be verified locally. Check with the Stytch API.
109
- return authenticate(
220
+ authenticate(
110
221
  session_jwt: session_jwt,
111
222
  session_duration_minutes: session_duration_minutes,
112
- session_custom_claims: session_custom_claims,
223
+ session_custom_claims: session_custom_claims
113
224
  )
114
225
  end
115
226
 
@@ -118,11 +229,11 @@ module Stytch
118
229
  # function to get the JWK
119
230
  # This method never authenticates a JWT directly with the API
120
231
  def authenticate_jwt_local(session_jwt)
121
- issuer = "stytch.com/" + @project_id
232
+ issuer = 'stytch.com/' + @project_id
122
233
  begin
123
234
  decoded_token = JWT.decode session_jwt, nil, true,
124
- { jwks: @jwks_loader, iss: issuer, verify_iss: true, aud: @project_id, verify_aud: true, algorithms: ["RS256"]}
125
- return decoded_token[0]
235
+ { jwks: @jwks_loader, iss: issuer, verify_iss: true, aud: @project_id, verify_aud: true, algorithms: ['RS256'] }
236
+ decoded_token[0]
126
237
  rescue JWT::InvalidIssuerError
127
238
  raise JWTInvalidIssuerError
128
239
  rescue JWT::InvalidAudError
@@ -135,24 +246,25 @@ module Stytch
135
246
  end
136
247
 
137
248
  def marshal_jwt_into_session(jwt)
138
- stytch_claim = "https://stytch.com/session"
139
- expires_at = jwt[stytch_claim]["expires_at"] || Time.at(jwt["exp"]).to_datetime.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
249
+ stytch_claim = 'https://stytch.com/session'
250
+ expires_at = jwt[stytch_claim]['expires_at'] || Time.at(jwt['exp']).to_datetime.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
140
251
  # The custom claim set is all the claims in the payload except for the standard claims and
141
252
  # the Stytch session claim. The cleanest way to collect those seems to be naming what we want
142
253
  # to omit and filtering the rest to collect the custom claims.
143
254
  reserved_claims = ['aud', 'exp', 'iat', 'iss', 'jti', 'nbf', 'sub', stytch_claim]
144
255
  custom_claims = jwt.reject { |key, _| reserved_claims.include?(key) }
145
- return {
146
- "session_id" => jwt[stytch_claim]["id"],
147
- "user_id" => jwt["sub"],
148
- "started_at" => jwt[stytch_claim]["started_at"],
149
- "last_accessed_at" => jwt[stytch_claim]["last_accessed_at"],
256
+ {
257
+ 'session_id' => jwt[stytch_claim]['id'],
258
+ 'user_id' => jwt['sub'],
259
+ 'started_at' => jwt[stytch_claim]['started_at'],
260
+ 'last_accessed_at' => jwt[stytch_claim]['last_accessed_at'],
150
261
  # For JWTs that include it, prefer the inner expires_at claim.
151
- "expires_at" => expires_at,
152
- "attributes" => jwt[stytch_claim]["attributes"],
153
- "authentication_factors" => jwt[stytch_claim]["authentication_factors"],
154
- "custom_claims" => custom_claims,
262
+ 'expires_at' => expires_at,
263
+ 'attributes' => jwt[stytch_claim]['attributes'],
264
+ 'authentication_factors' => jwt[stytch_claim]['authentication_factors'],
265
+ 'custom_claims' => custom_claims
155
266
  }
156
267
  end
268
+ # ENDMANUAL(authenticate_jwt)
157
269
  end
158
270
  end
data/lib/stytch/totps.rb CHANGED
@@ -1,17 +1,57 @@
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 TOTPs
7
13
  include Stytch::RequestHelper
8
14
 
9
- PATH = '/v1/totps'
10
-
11
15
  def initialize(connection)
12
16
  @connection = connection
13
17
  end
14
18
 
19
+ # Create a new TOTP instance for a user. The user can use the authenticator application of their choice to scan the QR code or enter the secret.
20
+ #
21
+ # == Parameters:
22
+ # user_id::
23
+ # The `user_id` of an active user the TOTP registration should be tied to.
24
+ # The type of this field is +String+.
25
+ # expiration_minutes::
26
+ # The expiration for the TOTP instance. If the newly created TOTP is not authenticated within this time frame the TOTP will be unusable. Defaults to 60 (1 hour) with a minimum of 5 and a maximum of 1440.
27
+ # The type of this field is nilable +Integer+.
28
+ #
29
+ # == Returns:
30
+ # An object with the following fields:
31
+ # request_id::
32
+ # 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.
33
+ # The type of this field is +String+.
34
+ # totp_id::
35
+ # The unique ID for a TOTP instance.
36
+ # The type of this field is +String+.
37
+ # secret::
38
+ # The TOTP secret key shared between the authenticator app and the server used to generate TOTP codes.
39
+ # The type of this field is +String+.
40
+ # qr_code::
41
+ # The QR code image encoded in base64.
42
+ # The type of this field is +String+.
43
+ # recovery_codes::
44
+ # The recovery codes used to authenticate the user without an authenticator app.
45
+ # The type of this field is list of +String+.
46
+ # user::
47
+ # 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.
48
+ # The type of this field is +User+ (+object+).
49
+ # user_id::
50
+ # The unique ID of the affected User.
51
+ # The type of this field is +String+.
52
+ # status_code::
53
+ # 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.
54
+ # The type of this field is +Integer+.
15
55
  def create(
16
56
  user_id:,
17
57
  expiration_minutes: nil
@@ -19,33 +59,113 @@ module Stytch
19
59
  request = {
20
60
  user_id: user_id
21
61
  }
22
-
23
62
  request[:expiration_minutes] = expiration_minutes unless expiration_minutes.nil?
24
63
 
25
- post_request(PATH, request)
64
+ post_request('/v1/totps', request)
26
65
  end
27
66
 
67
+ # Authenticate a TOTP code entered by a user.
68
+ #
69
+ # == Parameters:
70
+ # user_id::
71
+ # The `user_id` of an active user the TOTP registration should be tied to.
72
+ # The type of this field is +String+.
73
+ # totp_code::
74
+ # The TOTP code to authenticate. The TOTP code should consist of 6 digits.
75
+ # The type of this field is +String+.
76
+ # session_token::
77
+ # The `session_token` associated with a User's existing Session.
78
+ # The type of this field is nilable +String+.
79
+ # session_duration_minutes::
80
+ # Set the session lifetime to be this many minutes from now. This will start a new session if one doesn't already exist,
81
+ # returning both an opaque `session_token` and `session_jwt` for this session. Remember that the `session_jwt` will have a fixed lifetime of
82
+ # five minutes regardless of the underlying session duration, and will need to be refreshed over time.
83
+ #
84
+ # This value must be a minimum of 5 and a maximum of 527040 minutes (366 days).
85
+ #
86
+ # If a `session_token` or `session_jwt` is provided then a successful authentication will continue to extend the session this many minutes.
87
+ #
88
+ # If the `session_duration_minutes` parameter is not specified, a Stytch session will not be created.
89
+ # The type of this field is nilable +Integer+.
90
+ # session_jwt::
91
+ # The `session_jwt` associated with a User's existing Session.
92
+ # The type of this field is nilable +String+.
93
+ # session_custom_claims::
94
+ # 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.
95
+ #
96
+ # Custom claims made with reserved claims ("iss", "sub", "aud", "exp", "nbf", "iat", "jti") will be ignored. Total custom claims size cannot exceed four kilobytes.
97
+ # The type of this field is nilable +object+.
98
+ #
99
+ # == Returns:
100
+ # An object with the following fields:
101
+ # request_id::
102
+ # 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.
103
+ # The type of this field is +String+.
104
+ # user_id::
105
+ # The unique ID of the affected User.
106
+ # The type of this field is +String+.
107
+ # session_token::
108
+ # A secret token for a given Stytch Session.
109
+ # The type of this field is +String+.
110
+ # totp_id::
111
+ # The unique ID for a TOTP instance.
112
+ # The type of this field is +String+.
113
+ # session_jwt::
114
+ # The JSON Web Token (JWT) for a given Stytch Session.
115
+ # The type of this field is +String+.
116
+ # user::
117
+ # 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.
118
+ # The type of this field is +User+ (+object+).
119
+ # status_code::
120
+ # 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.
121
+ # The type of this field is +Integer+.
122
+ # session::
123
+ # If you initiate a Session, by including `session_duration_minutes` in your authenticate call, you'll receive a full Session object in the response.
124
+ #
125
+ # See [GET sessions](https://stytch.com/docs/api/session-get) for complete response fields.
126
+ #
127
+ # The type of this field is nilable +Session+ (+object+).
28
128
  def authenticate(
29
129
  user_id:,
30
130
  totp_code:,
31
131
  session_token: nil,
32
- session_jwt: nil,
33
132
  session_duration_minutes: nil,
133
+ session_jwt: nil,
34
134
  session_custom_claims: nil
35
135
  )
36
136
  request = {
37
137
  user_id: user_id,
38
138
  totp_code: totp_code
39
139
  }
40
-
41
140
  request[:session_token] = session_token unless session_token.nil?
42
- request[:session_jwt] = session_jwt unless session_jwt.nil?
43
141
  request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
142
+ request[:session_jwt] = session_jwt unless session_jwt.nil?
44
143
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
45
144
 
46
- post_request("#{PATH}/authenticate", request)
145
+ post_request('/v1/totps/authenticate', request)
47
146
  end
48
147
 
148
+ # Retrieve the recovery codes for a TOTP instance tied to a User.
149
+ #
150
+ # == Parameters:
151
+ # user_id::
152
+ # The `user_id` of an active user the TOTP registration should be tied to.
153
+ # The type of this field is +String+.
154
+ #
155
+ # == Returns:
156
+ # An object with the following fields:
157
+ # request_id::
158
+ # 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.
159
+ # The type of this field is +String+.
160
+ # user_id::
161
+ # The unique ID of the affected User.
162
+ # The type of this field is +String+.
163
+ # totps::
164
+ # An array containing a list of all TOTP instances (along with their recovery codes) for a given User in the Stytch API.
165
+ # The type of this field is list of +TOTP+ (+object+).
166
+ # status_code::
167
+ # 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.
168
+ # The type of this field is +Integer+.
49
169
  def recovery_codes(
50
170
  user_id:
51
171
  )
@@ -53,28 +173,88 @@ module Stytch
53
173
  user_id: user_id
54
174
  }
55
175
 
56
- post_request("#{PATH}/recovery_codes", request)
176
+ post_request('/v1/totps/recovery_codes', request)
57
177
  end
58
178
 
179
+ # Authenticate a recovery code for a TOTP instance.
180
+ #
181
+ # == Parameters:
182
+ # user_id::
183
+ # The `user_id` of an active user the TOTP registration should be tied to.
184
+ # The type of this field is +String+.
185
+ # recovery_code::
186
+ # The recovery code to authenticate.
187
+ # The type of this field is +String+.
188
+ # session_token::
189
+ # The `session_token` associated with a User's existing Session.
190
+ # The type of this field is nilable +String+.
191
+ # session_duration_minutes::
192
+ # Set the session lifetime to be this many minutes from now. This will start a new session if one doesn't already exist,
193
+ # returning both an opaque `session_token` and `session_jwt` for this session. Remember that the `session_jwt` will have a fixed lifetime of
194
+ # five minutes regardless of the underlying session duration, and will need to be refreshed over time.
195
+ #
196
+ # This value must be a minimum of 5 and a maximum of 527040 minutes (366 days).
197
+ #
198
+ # If a `session_token` or `session_jwt` is provided then a successful authentication will continue to extend the session this many minutes.
199
+ #
200
+ # If the `session_duration_minutes` parameter is not specified, a Stytch session will not be created.
201
+ # The type of this field is nilable +Integer+.
202
+ # session_jwt::
203
+ # The `session_jwt` associated with a User's existing Session.
204
+ # The type of this field is nilable +String+.
205
+ # session_custom_claims::
206
+ # 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.
207
+ #
208
+ # Custom claims made with reserved claims ("iss", "sub", "aud", "exp", "nbf", "iat", "jti") will be ignored. Total custom claims size cannot exceed four kilobytes.
209
+ # The type of this field is nilable +object+.
210
+ #
211
+ # == Returns:
212
+ # An object with the following fields:
213
+ # request_id::
214
+ # 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.
215
+ # The type of this field is +String+.
216
+ # totp_id::
217
+ # The unique ID for a TOTP instance.
218
+ # The type of this field is +String+.
219
+ # user_id::
220
+ # The unique ID of the affected User.
221
+ # The type of this field is +String+.
222
+ # session_token::
223
+ # A secret token for a given Stytch Session.
224
+ # The type of this field is +String+.
225
+ # session_jwt::
226
+ # The JSON Web Token (JWT) for a given Stytch Session.
227
+ # The type of this field is +String+.
228
+ # user::
229
+ # 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.
230
+ # The type of this field is +User+ (+object+).
231
+ # status_code::
232
+ # 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.
233
+ # The type of this field is +Integer+.
234
+ # session::
235
+ # If you initiate a Session, by including `session_duration_minutes` in your authenticate call, you'll receive a full Session object in the response.
236
+ #
237
+ # See [GET sessions](https://stytch.com/docs/api/session-get) for complete response fields.
238
+ #
239
+ # The type of this field is nilable +Session+ (+object+).
59
240
  def recover(
60
241
  user_id:,
61
242
  recovery_code:,
62
243
  session_token: nil,
63
- session_jwt: nil,
64
244
  session_duration_minutes: nil,
245
+ session_jwt: nil,
65
246
  session_custom_claims: nil
66
247
  )
67
248
  request = {
68
249
  user_id: user_id,
69
250
  recovery_code: recovery_code
70
251
  }
71
-
72
252
  request[:session_token] = session_token unless session_token.nil?
73
- request[:session_jwt] = session_jwt unless session_jwt.nil?
74
253
  request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
254
+ request[:session_jwt] = session_jwt unless session_jwt.nil?
75
255
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
76
256
 
77
- post_request("#{PATH}/recover", request)
257
+ post_request('/v1/totps/recover', request)
78
258
  end
79
259
  end
80
260
  end