stytch 5.0.2 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/stytch/b2b_client.rb +3 -1
- data/lib/stytch/b2b_discovery.rb +229 -0
- data/lib/stytch/b2b_magic_links.rb +270 -0
- data/lib/stytch/b2b_organizations.rb +474 -50
- data/lib/stytch/b2b_passwords.rb +435 -0
- data/lib/stytch/b2b_sessions.rb +183 -4
- data/lib/stytch/b2b_sso.rb +298 -14
- data/lib/stytch/client.rb +9 -9
- data/lib/stytch/crypto_wallets.rb +112 -13
- data/lib/stytch/errors.rb +16 -16
- data/lib/stytch/magic_links.rb +350 -56
- data/lib/stytch/oauth.rb +129 -22
- data/lib/stytch/otps.rb +454 -71
- data/lib/stytch/passwords.rb +513 -67
- data/lib/stytch/sessions.rb +147 -38
- data/lib/stytch/totps.rb +193 -13
- data/lib/stytch/users.rb +433 -106
- data/lib/stytch/version.rb +1 -1
- data/lib/stytch/webauthn.rb +156 -10
- metadata +2 -2
data/lib/stytch/sessions.rb
CHANGED
@@ -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
|
-
|
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,155 @@ module Stytch
|
|
29
33
|
end
|
30
34
|
end
|
31
35
|
|
32
|
-
|
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
111
|
request = {}
|
49
|
-
|
50
112
|
request[:session_token] = session_token unless session_token.nil?
|
51
|
-
request[:session_jwt] = session_jwt unless session_jwt.nil?
|
52
113
|
request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
|
114
|
+
request[:session_jwt] = session_jwt unless session_jwt.nil?
|
53
115
|
request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
|
54
116
|
|
55
|
-
post_request(
|
117
|
+
post_request('/v1/sessions/authenticate', request)
|
56
118
|
end
|
57
119
|
|
120
|
+
# 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.
|
121
|
+
#
|
122
|
+
# == Parameters:
|
123
|
+
# session_id::
|
124
|
+
# The `session_id` to revoke.
|
125
|
+
# The type of this field is nilable +String+.
|
126
|
+
# session_token::
|
127
|
+
# The session token to revoke.
|
128
|
+
# The type of this field is nilable +String+.
|
129
|
+
# session_jwt::
|
130
|
+
# A JWT for the session to revoke.
|
131
|
+
# The type of this field is nilable +String+.
|
132
|
+
#
|
133
|
+
# == Returns:
|
134
|
+
# An object with the following fields:
|
135
|
+
# request_id::
|
136
|
+
# 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.
|
137
|
+
# The type of this field is +String+.
|
138
|
+
# status_code::
|
139
|
+
# 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.
|
140
|
+
# The type of this field is +Integer+.
|
58
141
|
def revoke(
|
59
142
|
session_id: nil,
|
60
143
|
session_token: nil,
|
61
144
|
session_jwt: nil
|
62
145
|
)
|
63
146
|
request = {}
|
64
|
-
|
65
147
|
request[:session_id] = session_id unless session_id.nil?
|
66
148
|
request[:session_token] = session_token unless session_token.nil?
|
67
149
|
request[:session_jwt] = session_jwt unless session_jwt.nil?
|
68
150
|
|
69
|
-
post_request(
|
151
|
+
post_request('/v1/sessions/revoke', request)
|
70
152
|
end
|
71
153
|
|
72
|
-
|
73
|
-
|
74
|
-
|
154
|
+
# Get the JSON Web Key Set (JWKS) for a Stytch Project.
|
155
|
+
#
|
156
|
+
# == Parameters:
|
157
|
+
# project_id::
|
158
|
+
# The `project_id` to get the JWKS for.
|
159
|
+
# The type of this field is +String+.
|
160
|
+
#
|
161
|
+
# == Returns:
|
162
|
+
# An object with the following fields:
|
163
|
+
# keys::
|
164
|
+
# The JWK
|
165
|
+
# The type of this field is list of +JWK+ (+object+).
|
166
|
+
# request_id::
|
167
|
+
# 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.
|
168
|
+
# The type of this field is +String+.
|
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
|
+
def get_jwks(
|
173
|
+
project_id:
|
174
|
+
)
|
175
|
+
query_params = {}
|
176
|
+
request = request_with_query_params("/v1/sessions/jwks/#{project_id}", query_params)
|
177
|
+
get_request(request)
|
75
178
|
end
|
76
179
|
|
180
|
+
# MANUAL(authenticate_jwt)(SERVICE_METHOD)
|
181
|
+
# ADDIMPORT: require 'jwt'
|
182
|
+
# ADDIMPORT: require 'json/jwt'
|
183
|
+
# ADDIMPORT: require_relative 'errors'
|
184
|
+
|
77
185
|
# Parse a JWT and verify the signature. If max_token_age_seconds is unset, call the API directly
|
78
186
|
# If max_token_age_seconds is set and the JWT was issued (based on the "iat" claim) less than
|
79
187
|
# max_token_age_seconds seconds ago, then just verify locally and don't call the API
|
@@ -88,28 +196,28 @@ module Stytch
|
|
88
196
|
return authenticate(
|
89
197
|
session_jwt: session_jwt,
|
90
198
|
session_duration_minutes: session_duration_minutes,
|
91
|
-
session_custom_claims: session_custom_claims
|
199
|
+
session_custom_claims: session_custom_claims
|
92
200
|
)
|
93
201
|
end
|
94
202
|
|
95
203
|
decoded_jwt = authenticate_jwt_local(session_jwt)
|
96
|
-
iat_time = Time.at(decoded_jwt[
|
204
|
+
iat_time = Time.at(decoded_jwt['iat']).to_datetime
|
97
205
|
if iat_time + max_token_age_seconds >= Time.now
|
98
206
|
session = marshal_jwt_into_session(decoded_jwt)
|
99
|
-
|
207
|
+
{ 'session' => session }
|
100
208
|
else
|
101
|
-
|
209
|
+
authenticate(
|
102
210
|
session_jwt: session_jwt,
|
103
211
|
session_duration_minutes: session_duration_minutes,
|
104
|
-
session_custom_claims: session_custom_claims
|
212
|
+
session_custom_claims: session_custom_claims
|
105
213
|
)
|
106
214
|
end
|
107
215
|
rescue StandardError
|
108
216
|
# JWT could not be verified locally. Check with the Stytch API.
|
109
|
-
|
217
|
+
authenticate(
|
110
218
|
session_jwt: session_jwt,
|
111
219
|
session_duration_minutes: session_duration_minutes,
|
112
|
-
session_custom_claims: session_custom_claims
|
220
|
+
session_custom_claims: session_custom_claims
|
113
221
|
)
|
114
222
|
end
|
115
223
|
|
@@ -118,11 +226,11 @@ module Stytch
|
|
118
226
|
# function to get the JWK
|
119
227
|
# This method never authenticates a JWT directly with the API
|
120
228
|
def authenticate_jwt_local(session_jwt)
|
121
|
-
issuer =
|
229
|
+
issuer = 'stytch.com/' + @project_id
|
122
230
|
begin
|
123
231
|
decoded_token = JWT.decode session_jwt, nil, true,
|
124
|
-
|
125
|
-
|
232
|
+
{ jwks: @jwks_loader, iss: issuer, verify_iss: true, aud: @project_id, verify_aud: true, algorithms: ['RS256'] }
|
233
|
+
decoded_token[0]
|
126
234
|
rescue JWT::InvalidIssuerError
|
127
235
|
raise JWTInvalidIssuerError
|
128
236
|
rescue JWT::InvalidAudError
|
@@ -135,24 +243,25 @@ module Stytch
|
|
135
243
|
end
|
136
244
|
|
137
245
|
def marshal_jwt_into_session(jwt)
|
138
|
-
stytch_claim =
|
139
|
-
expires_at = jwt[stytch_claim][
|
246
|
+
stytch_claim = 'https://stytch.com/session'
|
247
|
+
expires_at = jwt[stytch_claim]['expires_at'] || Time.at(jwt['exp']).to_datetime.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
|
140
248
|
# The custom claim set is all the claims in the payload except for the standard claims and
|
141
249
|
# the Stytch session claim. The cleanest way to collect those seems to be naming what we want
|
142
250
|
# to omit and filtering the rest to collect the custom claims.
|
143
251
|
reserved_claims = ['aud', 'exp', 'iat', 'iss', 'jti', 'nbf', 'sub', stytch_claim]
|
144
252
|
custom_claims = jwt.reject { |key, _| reserved_claims.include?(key) }
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
253
|
+
{
|
254
|
+
'session_id' => jwt[stytch_claim]['id'],
|
255
|
+
'user_id' => jwt['sub'],
|
256
|
+
'started_at' => jwt[stytch_claim]['started_at'],
|
257
|
+
'last_accessed_at' => jwt[stytch_claim]['last_accessed_at'],
|
150
258
|
# For JWTs that include it, prefer the inner expires_at claim.
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
259
|
+
'expires_at' => expires_at,
|
260
|
+
'attributes' => jwt[stytch_claim]['attributes'],
|
261
|
+
'authentication_factors' => jwt[stytch_claim]['authentication_factors'],
|
262
|
+
'custom_claims' => custom_claims
|
155
263
|
}
|
156
264
|
end
|
265
|
+
# ENDMANUAL(authenticate_jwt)
|
157
266
|
end
|
158
267
|
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(
|
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(
|
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(
|
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(
|
257
|
+
post_request('/v1/totps/recover', request)
|
78
258
|
end
|
79
259
|
end
|
80
260
|
end
|