stytch 6.1.0 → 6.2.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.
- checksums.yaml +4 -4
- data/.github/workflows/check-links.yml +29 -0
- data/README.md +9 -9
- data/lib/stytch/b2b_client.rb +3 -1
- data/lib/stytch/b2b_discovery.rb +66 -7
- data/lib/stytch/b2b_magic_links.rb +33 -3
- data/lib/stytch/b2b_oauth.rb +33 -4
- data/lib/stytch/b2b_organizations.rb +28 -22
- data/lib/stytch/b2b_otp.rb +130 -2
- data/lib/stytch/b2b_passwords.rb +82 -10
- data/lib/stytch/b2b_sessions.rb +31 -7
- data/lib/stytch/b2b_sso.rb +30 -11
- data/lib/stytch/client.rb +3 -1
- data/lib/stytch/m2m.rb +482 -0
- data/lib/stytch/magic_links.rb +1 -1
- data/lib/stytch/otps.rb +6 -6
- data/lib/stytch/passwords.rb +2 -2
- data/lib/stytch/sessions.rb +11 -14
- data/lib/stytch/users.rb +4 -8
- data/lib/stytch/version.rb +1 -1
- metadata +4 -2
data/lib/stytch/m2m.rb
ADDED
@@ -0,0 +1,482 @@
|
|
1
|
+
# frozen_string_literal: true
|
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
|
+
|
9
|
+
require_relative 'request_helper'
|
10
|
+
|
11
|
+
module Stytch
|
12
|
+
class M2M
|
13
|
+
include Stytch::RequestHelper
|
14
|
+
attr_reader :clients
|
15
|
+
|
16
|
+
def initialize(connection, project_id)
|
17
|
+
@connection = connection
|
18
|
+
|
19
|
+
@clients = Stytch::M2M::Clients.new(@connection)
|
20
|
+
|
21
|
+
@project_id = project_id
|
22
|
+
@cache_last_update = 0
|
23
|
+
@jwks_loader = lambda do |options|
|
24
|
+
@cached_keys = nil if options[:invalidate] && @cache_last_update < Time.now.to_i - 300
|
25
|
+
@cached_keys ||= begin
|
26
|
+
@cache_last_update = Time.now.to_i
|
27
|
+
keys = []
|
28
|
+
get_jwks(project_id: @project_id)['keys'].each do |r|
|
29
|
+
keys << r
|
30
|
+
end
|
31
|
+
{ keys: keys }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
# MANUAL(M2M::get_jwks)(SERVICE_METHOD)
|
38
|
+
# This is a helper so we can retrieve the JWKS for a project for decoding M2M access tokens
|
39
|
+
def get_jwks(
|
40
|
+
project_id:
|
41
|
+
)
|
42
|
+
query_params = {}
|
43
|
+
request = request_with_query_params("/v1/sessions/jwks/#{project_id}", query_params)
|
44
|
+
get_request(request)
|
45
|
+
end
|
46
|
+
# ENDMANUAL(M2M::get_jwks)
|
47
|
+
|
48
|
+
# MANUAL(M2M::token)(SERVICE_METHOD)
|
49
|
+
# +token+ retrieves an access token for the given M2M Client.
|
50
|
+
# Access tokens are JWTs signed with the project's JWKs, and are valid for one hour after issuance.
|
51
|
+
# M2M Access tokens contain a standard set of claims as well as any custom claims generated from templates.
|
52
|
+
#
|
53
|
+
# == Parameters:
|
54
|
+
# client_id::
|
55
|
+
# The ID of the client.
|
56
|
+
# The type of this field is +String+.
|
57
|
+
# client_secret::
|
58
|
+
# The secret of the client.
|
59
|
+
# The type of this field is +String+.
|
60
|
+
# scopes::
|
61
|
+
# An array scopes requested. If omitted, all scopes assigned to the client will be returned.
|
62
|
+
# The type of this field is nilable list of +String+.
|
63
|
+
#
|
64
|
+
# == Returns:
|
65
|
+
# An object with the following fields:
|
66
|
+
# access_token::
|
67
|
+
# The access token granted to the client. Access tokens are JWTs signed with the project's JWKs.
|
68
|
+
# The type of this field is +String+.
|
69
|
+
# expires_in::
|
70
|
+
# The lifetime in seconds of the access token.
|
71
|
+
# For example, the value 3600 denotes that the access token will expire in one hour from the time the response was generated.
|
72
|
+
# The type of this field is +Integer+.
|
73
|
+
# token_type::
|
74
|
+
# The type of the returned access token. Today, this value will always be equal to "bearer"
|
75
|
+
# The type of this field is +String+.
|
76
|
+
def token(client_id:, client_secret:, scopes: nil)
|
77
|
+
request = {
|
78
|
+
grant_type: 'client_credentials',
|
79
|
+
client_id: client_id,
|
80
|
+
client_secret: client_secret
|
81
|
+
}
|
82
|
+
request[:scope] = scopes.join(' ') unless scopes.nil?
|
83
|
+
|
84
|
+
JSON.parse(post_request("/v1/public/#{@project_id}/oauth2/token", request), {:symbolize_names => true})
|
85
|
+
end
|
86
|
+
# ENDMANUAL(M2M::token)
|
87
|
+
|
88
|
+
# MANUAL(M2M::authenticate_token)(SERVICE_METHOD)
|
89
|
+
# +authenticate_token+ validates a M2M JWT locally.
|
90
|
+
#
|
91
|
+
# == Parameters:
|
92
|
+
# access_token::
|
93
|
+
# The access token granted to the client. Access tokens are JWTs signed with the project's JWKs.
|
94
|
+
# The type of this field is +String+.
|
95
|
+
# required_scopes::
|
96
|
+
# A list of scopes the token must have to be valid.
|
97
|
+
# The type of this field is nilable list of +String+.
|
98
|
+
# max_token_age::
|
99
|
+
# The maximum possible lifetime in seconds for the token to be valid.
|
100
|
+
# The type of this field is nilable +Integer+.
|
101
|
+
# == Returns:
|
102
|
+
# +nil+ if the token could not be validated, or an object with the following fields:
|
103
|
+
# scopes::
|
104
|
+
# An array of scopes granted to the token holder.
|
105
|
+
# The type of this field is list of +String+.
|
106
|
+
# client_id::
|
107
|
+
# The ID of the client that was issued the token
|
108
|
+
# The type of this field is +String+.
|
109
|
+
# custom_claims::
|
110
|
+
# A map of custom claims present in the token.
|
111
|
+
# The type of this field is +object+.
|
112
|
+
def authenticate_token(access_token:, required_scopes: nil, max_token_age: nil)
|
113
|
+
begin
|
114
|
+
decoded_jwt = authenticate_token_local(access_token)
|
115
|
+
rescue StandardError
|
116
|
+
# Could not authenticate locally
|
117
|
+
return nil
|
118
|
+
end
|
119
|
+
|
120
|
+
iat_time = Time.at(decoded_jwt['iat']).to_datetime
|
121
|
+
|
122
|
+
# Token too old
|
123
|
+
unless max_token_age.nil?
|
124
|
+
return nil if iat_time + max_token_age < Time.now
|
125
|
+
end
|
126
|
+
|
127
|
+
resp = marshal_jwt_into_response(decoded_jwt)
|
128
|
+
|
129
|
+
unless required_scopes.nil?
|
130
|
+
for scope in required_scopes
|
131
|
+
unless resp['scopes'].include?(scope)
|
132
|
+
# Token missing a required scope
|
133
|
+
return nil
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
resp
|
139
|
+
end
|
140
|
+
|
141
|
+
# Parse a M2M token and verify the signature locally (without calling /authenticate in the API)
|
142
|
+
def authenticate_token_local(jwt)
|
143
|
+
issuer = 'stytch.com/' + @project_id
|
144
|
+
begin
|
145
|
+
decoded_token = JWT.decode jwt, nil, true,
|
146
|
+
{ jwks: @jwks_loader, iss: issuer, verify_iss: true, aud: @project_id, verify_aud: true, algorithms: ['RS256'] }
|
147
|
+
decoded_token[0]
|
148
|
+
rescue JWT::InvalidIssuerError
|
149
|
+
raise JWTInvalidIssuerError
|
150
|
+
rescue JWT::InvalidAudError
|
151
|
+
raise JWTInvalidAudienceError
|
152
|
+
rescue JWT::ExpiredSignature
|
153
|
+
raise JWTExpiredSignatureError
|
154
|
+
rescue JWT::IncorrectAlgorithm
|
155
|
+
raise JWTIncorrectAlgorithmError
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def marshal_jwt_into_response(jwt)
|
160
|
+
# The custom claim set is all the claims in the payload except for the standard claims.
|
161
|
+
# The cleanest way to collect those seems to be naming what we want
|
162
|
+
# to omit and filtering the rest to collect the custom claims.
|
163
|
+
reserved_claims = %w[aud exp iat iss jti nbf sub]
|
164
|
+
custom_claims = jwt.reject { |key, _| reserved_claims.include?(key) }
|
165
|
+
{
|
166
|
+
'scopes' => jwt['scope'].split(' '),
|
167
|
+
'client_id' => jwt['sub'],
|
168
|
+
'custom_claims' => custom_claims
|
169
|
+
}
|
170
|
+
end
|
171
|
+
# ENDMANUAL(M2M::authenticate_token)
|
172
|
+
|
173
|
+
class Clients
|
174
|
+
include Stytch::RequestHelper
|
175
|
+
attr_reader :secrets
|
176
|
+
|
177
|
+
def initialize(connection)
|
178
|
+
@connection = connection
|
179
|
+
|
180
|
+
@secrets = Stytch::M2M::Clients::Secrets.new(@connection)
|
181
|
+
end
|
182
|
+
|
183
|
+
# Gets information about an existing M2M Client.
|
184
|
+
#
|
185
|
+
# == Parameters:
|
186
|
+
# client_id::
|
187
|
+
# The ID of the client.
|
188
|
+
# The type of this field is +String+.
|
189
|
+
#
|
190
|
+
# == Returns:
|
191
|
+
# An object with the following fields:
|
192
|
+
# request_id::
|
193
|
+
# 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.
|
194
|
+
# The type of this field is +String+.
|
195
|
+
# status_code::
|
196
|
+
# 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.
|
197
|
+
# The type of this field is +Integer+.
|
198
|
+
# m2m_client::
|
199
|
+
# The M2M Client affected by this operation.
|
200
|
+
# The type of this field is nilable +M2MClient+ (+object+).
|
201
|
+
def get(
|
202
|
+
client_id:
|
203
|
+
)
|
204
|
+
query_params = {}
|
205
|
+
request = request_with_query_params("/v1/m2m/clients/#{client_id}", query_params)
|
206
|
+
get_request(request)
|
207
|
+
end
|
208
|
+
|
209
|
+
# Search for M2M Clients within your Stytch Project. Submit an empty `query` in the request to return all M2M Clients.
|
210
|
+
#
|
211
|
+
# The following search filters are supported today:
|
212
|
+
# - `client_id`: Pass in a list of client IDs to get many clients in a single request
|
213
|
+
# - `client_name`: Search for clients by exact match on client name
|
214
|
+
# - `scopes`: Search for clients assigned a specific scope
|
215
|
+
#
|
216
|
+
# == Parameters:
|
217
|
+
# cursor::
|
218
|
+
# The `cursor` field allows you to paginate through your results. Each result array is limited to 1000 results. If your query returns more than 1000 results, you will need to paginate the responses using the `cursor`. If you receive a response that includes a non-null `next_cursor` in the `results_metadata` object, repeat the search call with the `next_cursor` value set to the `cursor` field to retrieve the next page of results. Continue to make search calls until the `next_cursor` in the response is null.
|
219
|
+
# The type of this field is nilable +String+.
|
220
|
+
# limit::
|
221
|
+
# The number of search results to return per page. The default limit is 100. A maximum of 1000 results can be returned by a single search request. If the total size of your result set is greater than one page size, you must paginate the response. See the `cursor` field.
|
222
|
+
# The type of this field is nilable +Integer+.
|
223
|
+
# query::
|
224
|
+
# The optional query object contains the operator, i.e. `AND` or `OR`, and the operands that will filter your results. Only an operator is required. If you include no operands, no filtering will be applied. If you include no query object, it will return all results with no filtering applied.
|
225
|
+
# The type of this field is nilable +M2MSearchQuery+ (+object+).
|
226
|
+
#
|
227
|
+
# == Returns:
|
228
|
+
# An object with the following fields:
|
229
|
+
# request_id::
|
230
|
+
# 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.
|
231
|
+
# The type of this field is +String+.
|
232
|
+
# m2m_clients::
|
233
|
+
# An array of M2M Clients that match your search query.
|
234
|
+
# The type of this field is list of +M2MClient+ (+object+).
|
235
|
+
# results_metadata::
|
236
|
+
# The search `results_metadata` object contains metadata relevant to your specific query like total and `next_cursor`.
|
237
|
+
# The type of this field is +ResultsMetadata+ (+object+).
|
238
|
+
# status_code::
|
239
|
+
# 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.
|
240
|
+
# The type of this field is +Integer+.
|
241
|
+
def search(
|
242
|
+
cursor: nil,
|
243
|
+
limit: nil,
|
244
|
+
query: nil
|
245
|
+
)
|
246
|
+
request = {}
|
247
|
+
request[:cursor] = cursor unless cursor.nil?
|
248
|
+
request[:limit] = limit unless limit.nil?
|
249
|
+
request[:query] = query unless query.nil?
|
250
|
+
|
251
|
+
post_request('/v1/m2m/clients/search', request)
|
252
|
+
end
|
253
|
+
|
254
|
+
# Updates an existing M2M Client. You can use this endpoint to activate or deactivate a M2M Client by changing its `status`. A deactivated M2M Client will not be allowed to perform future token exchange flows until it is reactivated.
|
255
|
+
#
|
256
|
+
# **Important:** Deactivating a M2M Client will not invalidate any existing JWTs issued to the client, only prevent it from receiving new ones.
|
257
|
+
# To protect more-sensitive routes, pass a lower `max_token_age` value when[authenticating the token](https://stytch.com/docs/b2b/api/authenticate-m2m-token)[authenticating the token](https://stytch.com/docs/api/authenticate-m2m-token).
|
258
|
+
#
|
259
|
+
# == Parameters:
|
260
|
+
# client_id::
|
261
|
+
# The ID of the client.
|
262
|
+
# The type of this field is +String+.
|
263
|
+
# client_name::
|
264
|
+
# A human-readable name for the client.
|
265
|
+
# The type of this field is nilable +String+.
|
266
|
+
# client_description::
|
267
|
+
# A human-readable description for the client.
|
268
|
+
# The type of this field is nilable +String+.
|
269
|
+
# status::
|
270
|
+
# The status of the client - either `active` or `inactive`.
|
271
|
+
# The type of this field is nilable +UpdateRequestStatus+ (string enum).
|
272
|
+
# scopes::
|
273
|
+
# An array of scopes assigned to the client.
|
274
|
+
# The type of this field is nilable list of +String+.
|
275
|
+
# trusted_metadata::
|
276
|
+
# 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.
|
277
|
+
# The type of this field is nilable +object+.
|
278
|
+
#
|
279
|
+
# == Returns:
|
280
|
+
# An object with the following fields:
|
281
|
+
# request_id::
|
282
|
+
# 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.
|
283
|
+
# The type of this field is +String+.
|
284
|
+
# status_code::
|
285
|
+
# 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.
|
286
|
+
# The type of this field is +Integer+.
|
287
|
+
# m2m_client::
|
288
|
+
# The M2M Client affected by this operation.
|
289
|
+
# The type of this field is nilable +M2MClient+ (+object+).
|
290
|
+
def update(
|
291
|
+
client_id:,
|
292
|
+
client_name: nil,
|
293
|
+
client_description: nil,
|
294
|
+
status: nil,
|
295
|
+
scopes: nil,
|
296
|
+
trusted_metadata: nil
|
297
|
+
)
|
298
|
+
request = {}
|
299
|
+
request[:client_name] = client_name unless client_name.nil?
|
300
|
+
request[:client_description] = client_description unless client_description.nil?
|
301
|
+
request[:status] = status unless status.nil?
|
302
|
+
request[:scopes] = scopes unless scopes.nil?
|
303
|
+
request[:trusted_metadata] = trusted_metadata unless trusted_metadata.nil?
|
304
|
+
|
305
|
+
put_request("/v1/m2m/clients/#{client_id}", request)
|
306
|
+
end
|
307
|
+
|
308
|
+
# Deletes the M2M Client.
|
309
|
+
#
|
310
|
+
# **Important:** Deleting a M2M Client will not invalidate any existing JWTs issued to the client, only prevent it from receiving new ones.
|
311
|
+
# To protect more-sensitive routes, pass a lower `max_token_age` value when[authenticating the token](https://stytch.com/docs/b2b/api/authenticate-m2m-token)[authenticating the token](https://stytch.com/docs/api/authenticate-m2m-token).
|
312
|
+
#
|
313
|
+
# == Parameters:
|
314
|
+
# client_id::
|
315
|
+
# The ID of the client.
|
316
|
+
# The type of this field is +String+.
|
317
|
+
#
|
318
|
+
# == Returns:
|
319
|
+
# An object with the following fields:
|
320
|
+
# request_id::
|
321
|
+
# 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.
|
322
|
+
# The type of this field is +String+.
|
323
|
+
# client_id::
|
324
|
+
# The ID of the client.
|
325
|
+
# The type of this field is +String+.
|
326
|
+
# status_code::
|
327
|
+
# 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.
|
328
|
+
# The type of this field is +Integer+.
|
329
|
+
def delete(
|
330
|
+
client_id:
|
331
|
+
)
|
332
|
+
delete_request("/v1/m2m/clients/#{client_id}")
|
333
|
+
end
|
334
|
+
|
335
|
+
# Creates a new M2M Client. On initial client creation, you may pass in a custom `client_id` or `client_secret` to import an existing M2M client. If you do not pass in a custom `client_id` or `client_secret`, one will be generated automatically. The `client_id` must be unique among all clients in your project.
|
336
|
+
#
|
337
|
+
# **Important:** This is the only time you will be able to view the generated `client_secret` in the API response. Stytch stores a hash of the `client_secret` and cannot recover the value if lost. Be sure to persist the `client_secret` in a secure location. If the `client_secret` is lost, you will need to trigger a secret rotation flow to receive another one.
|
338
|
+
#
|
339
|
+
# == Parameters:
|
340
|
+
# scopes::
|
341
|
+
# An array of scopes assigned to the client.
|
342
|
+
# The type of this field is list of +String+.
|
343
|
+
# client_id::
|
344
|
+
# If provided, the ID of the client to create. If not provided, Stytch will generate this value for you. The `client_id` must be unique within your project.
|
345
|
+
# The type of this field is nilable +String+.
|
346
|
+
# client_secret::
|
347
|
+
# If provided, the stored secret of the client to create. If not provided, Stytch will generate this value for you. If provided, the `client_secret` must be at least 8 characters long and pass entropy requirements.
|
348
|
+
# The type of this field is nilable +String+.
|
349
|
+
# client_name::
|
350
|
+
# A human-readable name for the client.
|
351
|
+
# The type of this field is nilable +String+.
|
352
|
+
# client_description::
|
353
|
+
# A human-readable description for the client.
|
354
|
+
# The type of this field is nilable +String+.
|
355
|
+
# trusted_metadata::
|
356
|
+
# 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.
|
357
|
+
# The type of this field is nilable +object+.
|
358
|
+
#
|
359
|
+
# == Returns:
|
360
|
+
# An object with the following fields:
|
361
|
+
# request_id::
|
362
|
+
# 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.
|
363
|
+
# The type of this field is +String+.
|
364
|
+
# status_code::
|
365
|
+
# 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.
|
366
|
+
# The type of this field is +Integer+.
|
367
|
+
# m2m_client::
|
368
|
+
# The M2M Client created by this API call.
|
369
|
+
# The type of this field is nilable +M2MClientWithClientSecret+ (+object+).
|
370
|
+
def create(
|
371
|
+
scopes:,
|
372
|
+
client_id: nil,
|
373
|
+
client_secret: nil,
|
374
|
+
client_name: nil,
|
375
|
+
client_description: nil,
|
376
|
+
trusted_metadata: nil
|
377
|
+
)
|
378
|
+
request = {
|
379
|
+
scopes: scopes
|
380
|
+
}
|
381
|
+
request[:client_id] = client_id unless client_id.nil?
|
382
|
+
request[:client_secret] = client_secret unless client_secret.nil?
|
383
|
+
request[:client_name] = client_name unless client_name.nil?
|
384
|
+
request[:client_description] = client_description unless client_description.nil?
|
385
|
+
request[:trusted_metadata] = trusted_metadata unless trusted_metadata.nil?
|
386
|
+
|
387
|
+
post_request('/v1/m2m/clients', request)
|
388
|
+
end
|
389
|
+
|
390
|
+
class Secrets
|
391
|
+
include Stytch::RequestHelper
|
392
|
+
|
393
|
+
def initialize(connection)
|
394
|
+
@connection = connection
|
395
|
+
end
|
396
|
+
|
397
|
+
# Initiate the rotation of an M2M client secret. After this endpoint is called, both the client's `client_secret` and `next_client_secret` will be valid. To complete the secret rotation flow, update all usages of `client_secret` to `next_client_secret` and call the[Rotate Secret Endpoint](https://stytch.com/docs/b2b/api/m2m-rotate-secret)[Rotate Secret Endpoint](https://stytch.com/docs/api/m2m-rotate-secret) to complete the flow.
|
398
|
+
# Secret rotation can be cancelled using the[Rotate Cancel Endpoint](https://stytch.com/docs/b2b/api/m2m-rotate-secret-cancel)[Rotate Cancel Endpoint](https://stytch.com/docs/api/m2m-rotate-secret-cancel).
|
399
|
+
#
|
400
|
+
# **Important:** This is the only time you will be able to view the generated `next_client_secret` in the API response. Stytch stores a hash of the `next_client_secret` and cannot recover the value if lost. Be sure to persist the `next_client_secret` in a secure location. If the `next_client_secret` is lost, you will need to trigger a secret rotation flow to receive another one.
|
401
|
+
#
|
402
|
+
# == Parameters:
|
403
|
+
# client_id::
|
404
|
+
# The ID of the client.
|
405
|
+
# The type of this field is +String+.
|
406
|
+
#
|
407
|
+
# == Returns:
|
408
|
+
# An object with the following fields:
|
409
|
+
# request_id::
|
410
|
+
# 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.
|
411
|
+
# The type of this field is +String+.
|
412
|
+
# status_code::
|
413
|
+
# 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.
|
414
|
+
# The type of this field is +Integer+.
|
415
|
+
# m2m_client::
|
416
|
+
# The M2M Client affected by this operation.
|
417
|
+
# The type of this field is nilable +M2MClientWithNextClientSecret+ (+object+).
|
418
|
+
def rotate_start(
|
419
|
+
client_id:
|
420
|
+
)
|
421
|
+
request = {}
|
422
|
+
|
423
|
+
post_request("/v1/m2m/clients/#{client_id}/secrets/rotate/start", request)
|
424
|
+
end
|
425
|
+
|
426
|
+
# Cancel the rotation of an M2M client secret started with the[Start Secret Rotation Endpoint](https://stytch.com/docs/b2b/api/m2m-rotate-secret-start)[Start Secret Rotation Endpoint](https://stytch.com/docs/api/m2m-rotate-secret-start).
|
427
|
+
# After this endpoint is called, the client's `next_client_secret` is discarded and only the original `client_secret` will be valid.
|
428
|
+
#
|
429
|
+
# == Parameters:
|
430
|
+
# client_id::
|
431
|
+
# The ID of the client.
|
432
|
+
# The type of this field is +String+.
|
433
|
+
#
|
434
|
+
# == Returns:
|
435
|
+
# An object with the following fields:
|
436
|
+
# request_id::
|
437
|
+
# 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.
|
438
|
+
# The type of this field is +String+.
|
439
|
+
# status_code::
|
440
|
+
# 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.
|
441
|
+
# The type of this field is +Integer+.
|
442
|
+
# m2m_client::
|
443
|
+
# The M2M Client affected by this operation.
|
444
|
+
# The type of this field is nilable +M2MClient+ (+object+).
|
445
|
+
def rotate_cancel(
|
446
|
+
client_id:
|
447
|
+
)
|
448
|
+
request = {}
|
449
|
+
|
450
|
+
post_request("/v1/m2m/clients/#{client_id}/secrets/rotate/cancel", request)
|
451
|
+
end
|
452
|
+
|
453
|
+
# Complete the rotation of an M2M client secret started with the[Start Secret Rotation Endpoint](https://stytch.com/docs/b2b/api/m2m-rotate-secret-start)[Start Secret Rotation Endpoint](https://stytch.com/docs/api/m2m-rotate-secret-start).
|
454
|
+
# After this endpoint is called, the client's `next_client_secret` becomes its `client_secret` and the previous `client_secret` will no longer be valid.
|
455
|
+
#
|
456
|
+
# == Parameters:
|
457
|
+
# client_id::
|
458
|
+
# The ID of the client.
|
459
|
+
# The type of this field is +String+.
|
460
|
+
#
|
461
|
+
# == Returns:
|
462
|
+
# An object with the following fields:
|
463
|
+
# request_id::
|
464
|
+
# 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.
|
465
|
+
# The type of this field is +String+.
|
466
|
+
# status_code::
|
467
|
+
# 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.
|
468
|
+
# The type of this field is +Integer+.
|
469
|
+
# m2m_client::
|
470
|
+
# The M2M Client affected by this operation.
|
471
|
+
# The type of this field is nilable +M2MClient+ (+object+).
|
472
|
+
def rotate(
|
473
|
+
client_id:
|
474
|
+
)
|
475
|
+
request = {}
|
476
|
+
|
477
|
+
post_request("/v1/m2m/clients/#{client_id}/secrets/rotate", request)
|
478
|
+
end
|
479
|
+
end
|
480
|
+
end
|
481
|
+
end
|
482
|
+
end
|
data/lib/stytch/magic_links.rb
CHANGED
@@ -172,7 +172,7 @@ module Stytch
|
|
172
172
|
# Adding a new email to an existing Stytch User requires the user to be present and validate the email via magic link. This requirement is in place to prevent account takeover attacks.
|
173
173
|
#
|
174
174
|
# ### Next steps
|
175
|
-
# The user is emailed a magic link which redirects them to the provided [redirect URL](https://stytch.com/docs/magic-links
|
175
|
+
# The user is emailed a magic link which redirects them to the provided [redirect URL](https://stytch.com/docs/guides/magic-links/email-magic-links/redirect-routing). Collect the `token` from the URL query parameters, and call [Authenticate magic link](https://stytch.com/docs/api/authenticate-magic-link) to complete authentication.
|
176
176
|
#
|
177
177
|
# == Parameters:
|
178
178
|
# email::
|
data/lib/stytch/otps.rb
CHANGED
@@ -141,7 +141,7 @@ module Stytch
|
|
141
141
|
# The phone number to use for one-time passcodes. The phone number should be in E.164 format. The phone number should be in E.164 format (i.e. +1XXXXXXXXXX). You may use +10000000000 to test this endpoint, see [Testing](https://stytch.com/docs/home#resources_testing) for more detail.
|
142
142
|
# The type of this field is +String+.
|
143
143
|
# expiration_minutes::
|
144
|
-
# Set the expiration for the
|
144
|
+
# Set the expiration for the one-time passcode, in minutes. The minimum expiration is 1 minute and the maximum is 10 minutes. The default expiration is 2 minutes.
|
145
145
|
# The type of this field is nilable +Integer+.
|
146
146
|
# attributes::
|
147
147
|
# Provided attributes help with fraud detection.
|
@@ -211,7 +211,7 @@ module Stytch
|
|
211
211
|
# The phone number to use for one-time passcodes. The phone number should be in E.164 format. The phone number should be in E.164 format (i.e. +1XXXXXXXXXX). You may use +10000000000 to test this endpoint, see [Testing](https://stytch.com/docs/home#resources_testing) for more detail.
|
212
212
|
# The type of this field is +String+.
|
213
213
|
# expiration_minutes::
|
214
|
-
# Set the expiration for the
|
214
|
+
# Set the expiration for the one-time passcode, in minutes. The minimum expiration is 1 minute and the maximum is 10 minutes. The default expiration is 2 minutes.
|
215
215
|
# The type of this field is nilable +Integer+.
|
216
216
|
# attributes::
|
217
217
|
# Provided attributes help with fraud detection.
|
@@ -294,7 +294,7 @@ module Stytch
|
|
294
294
|
# The phone number to use for one-time passcodes. The phone number should be in E.164 format. The phone number should be in E.164 format (i.e. +1XXXXXXXXXX). You may use +10000000000 to test this endpoint, see [Testing](https://stytch.com/docs/home#resources_testing) for more detail.
|
295
295
|
# The type of this field is +String+.
|
296
296
|
# expiration_minutes::
|
297
|
-
# Set the expiration for the
|
297
|
+
# Set the expiration for the one-time passcode, in minutes. The minimum expiration is 1 minute and the maximum is 10 minutes. The default expiration is 2 minutes.
|
298
298
|
# The type of this field is nilable +Integer+.
|
299
299
|
# attributes::
|
300
300
|
# Provided attributes help with fraud detection.
|
@@ -364,7 +364,7 @@ module Stytch
|
|
364
364
|
# The phone number to use for one-time passcodes. The phone number should be in E.164 format. The phone number should be in E.164 format (i.e. +1XXXXXXXXXX). You may use +10000000000 to test this endpoint, see [Testing](https://stytch.com/docs/home#resources_testing) for more detail.
|
365
365
|
# The type of this field is +String+.
|
366
366
|
# expiration_minutes::
|
367
|
-
# Set the expiration for the
|
367
|
+
# Set the expiration for the one-time passcode, in minutes. The minimum expiration is 1 minute and the maximum is 10 minutes. The default expiration is 2 minutes.
|
368
368
|
# The type of this field is nilable +Integer+.
|
369
369
|
# attributes::
|
370
370
|
# Provided attributes help with fraud detection.
|
@@ -443,7 +443,7 @@ module Stytch
|
|
443
443
|
# The email address of the user to send the one-time passcode to. You may use sandbox@stytch.com to test this endpoint, see [Testing](https://stytch.com/docs/home#resources_testing) for more detail.
|
444
444
|
# The type of this field is +String+.
|
445
445
|
# expiration_minutes::
|
446
|
-
# Set the expiration for the
|
446
|
+
# Set the expiration for the one-time passcode, in minutes. The minimum expiration is 1 minute and the maximum is 10 minutes. The default expiration is 2 minutes.
|
447
447
|
# The type of this field is nilable +Integer+.
|
448
448
|
# attributes::
|
449
449
|
# Provided attributes help with fraud detection.
|
@@ -523,7 +523,7 @@ module Stytch
|
|
523
523
|
# The email address of the user to send the one-time passcode to. You may use sandbox@stytch.com to test this endpoint, see [Testing](https://stytch.com/docs/home#resources_testing) for more detail.
|
524
524
|
# The type of this field is +String+.
|
525
525
|
# expiration_minutes::
|
526
|
-
# Set the expiration for the
|
526
|
+
# Set the expiration for the one-time passcode, in minutes. The minimum expiration is 1 minute and the maximum is 10 minutes. The default expiration is 2 minutes.
|
527
527
|
# The type of this field is nilable +Integer+.
|
528
528
|
# attributes::
|
529
529
|
# Provided attributes help with fraud detection.
|
data/lib/stytch/passwords.rb
CHANGED
@@ -197,7 +197,7 @@ module Stytch
|
|
197
197
|
|
198
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
199
|
#
|
200
|
-
# This endpoint adapts to your Project's password strength configuration. If you're using [zxcvbn](https://stytch.com/docs/passwords
|
200
|
+
# This endpoint adapts to your Project's password strength configuration. If you're using [zxcvbn](https://stytch.com/docs/guides/passwords/strength-policy), the default, your passwords are considered valid if the strength score is >= 3. If you're using [LUDS](https://stytch.com/docs/guides/passwords/strength-policy), 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
201
|
#
|
202
202
|
#
|
203
203
|
# ### Password feedback
|
@@ -624,7 +624,7 @@ module Stytch
|
|
624
624
|
@connection = connection
|
625
625
|
end
|
626
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.
|
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. This endpoint requires either a `session_jwt` or `session_token` be included in the request.
|
628
628
|
#
|
629
629
|
# == Parameters:
|
630
630
|
# password::
|
data/lib/stytch/sessions.rb
CHANGED
@@ -84,6 +84,12 @@ module Stytch
|
|
84
84
|
# request_id::
|
85
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
86
|
# The type of this field is +String+.
|
87
|
+
# session::
|
88
|
+
# If you initiate a Session, by including `session_duration_minutes` in your authenticate call, you'll receive a full Session object in the response.
|
89
|
+
#
|
90
|
+
# See [GET sessions](https://stytch.com/docs/api/session-get) for complete response fields.
|
91
|
+
#
|
92
|
+
# The type of this field is +Session+ (+object+).
|
87
93
|
# session_token::
|
88
94
|
# A secret token for a given Stytch Session.
|
89
95
|
# The type of this field is +String+.
|
@@ -96,20 +102,13 @@ module Stytch
|
|
96
102
|
# status_code::
|
97
103
|
# 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
104
|
# 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+).
|
105
105
|
def authenticate(
|
106
106
|
session_token: nil,
|
107
107
|
session_duration_minutes: nil,
|
108
108
|
session_jwt: nil,
|
109
109
|
session_custom_claims: nil
|
110
110
|
)
|
111
|
-
request = {
|
112
|
-
}
|
111
|
+
request = {}
|
113
112
|
request[:session_token] = session_token unless session_token.nil?
|
114
113
|
request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
|
115
114
|
request[:session_jwt] = session_jwt unless session_jwt.nil?
|
@@ -144,8 +143,7 @@ module Stytch
|
|
144
143
|
session_token: nil,
|
145
144
|
session_jwt: nil
|
146
145
|
)
|
147
|
-
request = {
|
148
|
-
}
|
146
|
+
request = {}
|
149
147
|
request[:session_id] = session_id unless session_id.nil?
|
150
148
|
request[:session_token] = session_token unless session_token.nil?
|
151
149
|
request[:session_jwt] = session_jwt unless session_jwt.nil?
|
@@ -174,13 +172,12 @@ module Stytch
|
|
174
172
|
def get_jwks(
|
175
173
|
project_id:
|
176
174
|
)
|
177
|
-
query_params = {
|
178
|
-
}
|
175
|
+
query_params = {}
|
179
176
|
request = request_with_query_params("/v1/sessions/jwks/#{project_id}", query_params)
|
180
177
|
get_request(request)
|
181
178
|
end
|
182
179
|
|
183
|
-
# MANUAL(authenticate_jwt)(SERVICE_METHOD)
|
180
|
+
# MANUAL(Sessions::authenticate_jwt)(SERVICE_METHOD)
|
184
181
|
# ADDIMPORT: require 'jwt'
|
185
182
|
# ADDIMPORT: require 'json/jwt'
|
186
183
|
# ADDIMPORT: require_relative 'errors'
|
@@ -265,6 +262,6 @@ module Stytch
|
|
265
262
|
'custom_claims' => custom_claims
|
266
263
|
}
|
267
264
|
end
|
268
|
-
# ENDMANUAL(authenticate_jwt)
|
265
|
+
# ENDMANUAL(Sessions::authenticate_jwt)
|
269
266
|
end
|
270
267
|
end
|