stytch 6.3.0 → 6.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stytch/b2b_client.rb +1 -1
- data/lib/stytch/b2b_discovery.rb +8 -8
- data/lib/stytch/b2b_magic_links.rb +6 -6
- data/lib/stytch/b2b_oauth.rb +4 -4
- data/lib/stytch/b2b_organizations.rb +80 -11
- data/lib/stytch/b2b_otp.rb +20 -6
- data/lib/stytch/b2b_passwords.rb +14 -14
- data/lib/stytch/b2b_sessions.rb +110 -6
- data/lib/stytch/b2b_sso.rb +4 -4
- data/lib/stytch/m2m.rb +25 -32
- data/lib/stytch/magic_links.rb +1 -3
- data/lib/stytch/otps.rb +21 -16
- data/lib/stytch/passwords.rb +5 -3
- data/lib/stytch/users.rb +35 -2
- data/lib/stytch/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0bc5efc1c2c0c36d794db592adba102628de2cd5cec77ffce94652b31e0007f
|
4
|
+
data.tar.gz: 689602f4ab5dc19c149c541eb3b15125d82ce515db9771583b8d6f22123eb577
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be5a989fee14537da3dac34ecea235509a9b1a1366fc1d9539c79ea600ea4b9abb9f9205faee9bfca0ad8ad07429d659d46af6f9b8815ac17343d8757fcc2098
|
7
|
+
data.tar.gz: e4f51e5f088df37798b52df974c376a52ebd3375270278b647b6e8d41e0355b5b1f4af53149cc1459eb5b7ca5b8f617bbe375e4ec57f55eb8819310662b09e9c
|
data/lib/stytch/b2b_client.rb
CHANGED
@@ -31,7 +31,7 @@ module StytchB2B
|
|
31
31
|
@organizations = StytchB2B::Organizations.new(@connection)
|
32
32
|
@passwords = StytchB2B::Passwords.new(@connection)
|
33
33
|
@sso = StytchB2B::SSO.new(@connection)
|
34
|
-
@sessions = StytchB2B::Sessions.new(@connection)
|
34
|
+
@sessions = StytchB2B::Sessions.new(@connection, project_id)
|
35
35
|
end
|
36
36
|
|
37
37
|
private
|
data/lib/stytch/b2b_discovery.rb
CHANGED
@@ -32,7 +32,7 @@ module StytchB2B
|
|
32
32
|
#
|
33
33
|
# This endpoint can be used to accept invites and create new members via domain matching.
|
34
34
|
#
|
35
|
-
#
|
35
|
+
# If the Member is required to complete MFA to log in to the Organization, the returned value of `member_authenticated` will be `false`.
|
36
36
|
# The `intermediate_session_token` will not be consumed and instead will be returned in the response.
|
37
37
|
# The `intermediate_session_token` can be passed into the [OTP SMS Authenticate endpoint](https://stytch.com/docs/b2b/api/authenticate-otp-sms) to complete the MFA step and acquire a full member session.
|
38
38
|
# The `intermediate_session_token` can also be used with the [Exchange Intermediate Session endpoint](https://stytch.com/docs/b2b/api/exchange-intermediate-session) or the [Create Organization via Discovery endpoint](https://stytch.com/docs/b2b/api/create-organization-via-discovery) to join a different Organization or create a new one.
|
@@ -67,7 +67,7 @@ module StytchB2B
|
|
67
67
|
# Total custom claims size cannot exceed four kilobytes.
|
68
68
|
# The type of this field is nilable +object+.
|
69
69
|
# locale::
|
70
|
-
#
|
70
|
+
# If the Member needs to complete an MFA step, and the Member has a phone number, this endpoint will pre-emptively send a one-time passcode (OTP) to the Member's phone number. The locale argument will be used to determine which language to use when sending the passcode.
|
71
71
|
#
|
72
72
|
# Parameter is a [IETF BCP 47 language tag](https://www.w3.org/International/articles/language-tags/), e.g. `"en"`.
|
73
73
|
#
|
@@ -92,7 +92,7 @@ module StytchB2B
|
|
92
92
|
# The JSON Web Token (JWT) for a given Stytch Session.
|
93
93
|
# The type of this field is +String+.
|
94
94
|
# member::
|
95
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
95
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
96
96
|
# The type of this field is +Member+ (+object+).
|
97
97
|
# organization::
|
98
98
|
# The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
|
@@ -113,7 +113,7 @@ module StytchB2B
|
|
113
113
|
# The [Session object](https://stytch.com/docs/b2b/api/session-object).
|
114
114
|
# The type of this field is nilable +MemberSession+ (+object+).
|
115
115
|
# mfa_required::
|
116
|
-
#
|
116
|
+
# Information about the MFA requirements of the Organization and the Member's options for fulfilling MFA.
|
117
117
|
# The type of this field is nilable +MfaRequired+ (+object+).
|
118
118
|
def exchange(
|
119
119
|
intermediate_session_token:,
|
@@ -148,7 +148,7 @@ module StytchB2B
|
|
148
148
|
#
|
149
149
|
# This endpoint can also be used to start an initial session for the newly created member and organization.
|
150
150
|
#
|
151
|
-
#
|
151
|
+
# If the new Organization is created with a `mfa_policy` of `REQUIRED_FOR_ALL`, the newly created Member will need to complete an MFA step to log in to the Organization.
|
152
152
|
# The `intermediate_session_token` will not be consumed and instead will be returned in the response.
|
153
153
|
# The `intermediate_session_token` can be passed into the [OTP SMS Authenticate endpoint](https://stytch.com/docs/b2b/api/authenticate-otp-sms) to complete the MFA step and acquire a full member session.
|
154
154
|
# The `intermediate_session_token` can also be used with the [Exchange Intermediate Session endpoint](https://stytch.com/docs/b2b/api/exchange-intermediate-session) or the [Create Organization via Discovery endpoint](https://stytch.com/docs/b2b/api/create-organization-via-discovery) to join a different Organization or create a new one.
|
@@ -240,7 +240,7 @@ module StytchB2B
|
|
240
240
|
#
|
241
241
|
# The type of this field is nilable list of +String+.
|
242
242
|
# mfa_policy::
|
243
|
-
#
|
243
|
+
# The setting that controls the MFA policy for all Members in the Organization. The accepted values are:
|
244
244
|
#
|
245
245
|
# `REQUIRED_FOR_ALL` – All Members within the Organization will be required to complete MFA every time they wish to log in.
|
246
246
|
#
|
@@ -263,7 +263,7 @@ module StytchB2B
|
|
263
263
|
# The JSON Web Token (JWT) for a given Stytch Session.
|
264
264
|
# The type of this field is +String+.
|
265
265
|
# member::
|
266
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
266
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
267
267
|
# The type of this field is +Member+ (+object+).
|
268
268
|
# member_authenticated::
|
269
269
|
# Indicates whether the Member is fully authenticated. If false, the Member needs to complete an MFA step to log in to the Organization.
|
@@ -284,7 +284,7 @@ module StytchB2B
|
|
284
284
|
# The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
|
285
285
|
# The type of this field is nilable +Organization+ (+object+).
|
286
286
|
# mfa_required::
|
287
|
-
#
|
287
|
+
# Information about the MFA requirements of the Organization and the Member's options for fulfilling MFA.
|
288
288
|
# The type of this field is nilable +MfaRequired+ (+object+).
|
289
289
|
def create(
|
290
290
|
intermediate_session_token:,
|
@@ -23,7 +23,7 @@ module StytchB2B
|
|
23
23
|
# Authenticate a Member with a Magic Link. This endpoint requires a Magic Link token that is not expired or previously used. If the Member’s status is `pending` or `invited`, they will be updated to `active`.
|
24
24
|
# Provide the `session_duration_minutes` parameter to set the lifetime of the session. If the `session_duration_minutes` parameter is not specified, a Stytch session will be created with a 60 minute duration.
|
25
25
|
#
|
26
|
-
#
|
26
|
+
# If the Member is required to complete MFA to log in to the Organization, the returned value of `member_authenticated` will be `false`, and an `intermediate_session_token` will be returned.
|
27
27
|
# The `intermediate_session_token` can be passed into the [OTP SMS Authenticate endpoint](https://stytch.com/docs/b2b/api/authenticate-otp-sms) to complete the MFA step and acquire a full member session.
|
28
28
|
# The `intermediate_session_token` can also be used with the [Exchange Intermediate Session endpoint](https://stytch.com/docs/b2b/api/exchange-intermediate-session) or the [Create Organization via Discovery endpoint](https://stytch.com/docs/b2b/api/create-organization-via-discovery) to join a different Organization or create a new one.
|
29
29
|
# The `session_duration_minutes` and `session_custom_claims` parameters will be ignored.
|
@@ -66,7 +66,7 @@ module StytchB2B
|
|
66
66
|
# Total custom claims size cannot exceed four kilobytes.
|
67
67
|
# The type of this field is nilable +object+.
|
68
68
|
# locale::
|
69
|
-
#
|
69
|
+
# If the Member needs to complete an MFA step, and the Member has a phone number, this endpoint will pre-emptively send a one-time passcode (OTP) to the Member's phone number. The locale argument will be used to determine which language to use when sending the passcode.
|
70
70
|
#
|
71
71
|
# Parameter is a [IETF BCP 47 language tag](https://www.w3.org/International/articles/language-tags/), e.g. `"en"`.
|
72
72
|
#
|
@@ -95,7 +95,7 @@ module StytchB2B
|
|
95
95
|
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
|
96
96
|
# The type of this field is +String+.
|
97
97
|
# member::
|
98
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
98
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
99
99
|
# The type of this field is +Member+ (+object+).
|
100
100
|
# session_token::
|
101
101
|
# A secret token for a given Stytch Session.
|
@@ -122,7 +122,7 @@ module StytchB2B
|
|
122
122
|
# 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.
|
123
123
|
# The type of this field is +Integer+.
|
124
124
|
# mfa_required::
|
125
|
-
#
|
125
|
+
# Information about the MFA requirements of the Organization and the Member's options for fulfilling MFA.
|
126
126
|
# The type of this field is nilable +MfaRequired+ (+object+).
|
127
127
|
def authenticate(
|
128
128
|
magic_links_token:,
|
@@ -207,7 +207,7 @@ module StytchB2B
|
|
207
207
|
# A flag indicating `true` if a new Member object was created and `false` if the Member object already existed.
|
208
208
|
# The type of this field is +Boolean+.
|
209
209
|
# member::
|
210
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
210
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
211
211
|
# The type of this field is +Member+ (+object+).
|
212
212
|
# organization::
|
213
213
|
# The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
|
@@ -289,7 +289,7 @@ module StytchB2B
|
|
289
289
|
# Globally unique UUID that identifies a specific Member.
|
290
290
|
# The type of this field is +String+.
|
291
291
|
# member::
|
292
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
292
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
293
293
|
# The type of this field is +Member+ (+object+).
|
294
294
|
# organization::
|
295
295
|
# The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
|
data/lib/stytch/b2b_oauth.rb
CHANGED
@@ -21,7 +21,7 @@ module StytchB2B
|
|
21
21
|
|
22
22
|
# Authenticate a Member given a `token`. This endpoint verifies that the member completed the OAuth flow by verifying that the token is valid and hasn't expired. Provide the `session_duration_minutes` parameter to set the lifetime of the session. If the `session_duration_minutes` parameter is not specified, a Stytch session will be created with a 60 minute duration.
|
23
23
|
#
|
24
|
-
#
|
24
|
+
# If the Member is required to complete MFA to log in to the Organization, the returned value of `member_authenticated` will be `false`, and an `intermediate_session_token` will be returned.
|
25
25
|
# The `intermediate_session_token` can be passed into the [OTP SMS Authenticate endpoint](https://stytch.com/docs/b2b/api/authenticate-otp-sms) to complete the MFA step and acquire a full member session.
|
26
26
|
# The `intermediate_session_token` can also be used with the [Exchange Intermediate Session endpoint](https://stytch.com/docs/b2b/api/exchange-intermediate-session) or the [Create Organization via Discovery endpoint](https://stytch.com/docs/b2b/api/create-organization-via-discovery) to join a different Organization or create a new one.
|
27
27
|
# The `session_duration_minutes` and `session_custom_claims` parameters will be ignored.
|
@@ -60,7 +60,7 @@ module StytchB2B
|
|
60
60
|
# A base64url encoded one time secret used to validate that the request starts and ends on the same device.
|
61
61
|
# The type of this field is nilable +String+.
|
62
62
|
# locale::
|
63
|
-
#
|
63
|
+
# If the Member needs to complete an MFA step, and the Member has a phone number, this endpoint will pre-emptively send a one-time passcode (OTP) to the Member's phone number. The locale argument will be used to determine which language to use when sending the passcode.
|
64
64
|
#
|
65
65
|
# Parameter is a [IETF BCP 47 language tag](https://www.w3.org/International/articles/language-tags/), e.g. `"en"`.
|
66
66
|
#
|
@@ -91,7 +91,7 @@ module StytchB2B
|
|
91
91
|
# The JSON Web Token (JWT) for a given Stytch Session.
|
92
92
|
# The type of this field is +String+.
|
93
93
|
# member::
|
94
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
94
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
95
95
|
# The type of this field is +Member+ (+object+).
|
96
96
|
# organization_id::
|
97
97
|
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
|
@@ -123,7 +123,7 @@ module StytchB2B
|
|
123
123
|
# Note that these values will vary based on the OAuth provider in question, e.g. `id_token` is only returned by Microsoft.
|
124
124
|
# The type of this field is nilable +ProviderValues+ (+object+).
|
125
125
|
# mfa_required::
|
126
|
-
#
|
126
|
+
# Information about the MFA requirements of the Organization and the Member's options for fulfilling MFA.
|
127
127
|
# The type of this field is nilable +MfaRequired+ (+object+).
|
128
128
|
def authenticate(
|
129
129
|
oauth_token:,
|
@@ -87,7 +87,7 @@ module StytchB2B
|
|
87
87
|
#
|
88
88
|
# The type of this field is nilable list of +String+.
|
89
89
|
# mfa_policy::
|
90
|
-
#
|
90
|
+
# The setting that controls the MFA policy for all Members in the Organization. The accepted values are:
|
91
91
|
#
|
92
92
|
# `REQUIRED_FOR_ALL` – All Members within the Organization will be required to complete MFA every time they wish to log in.
|
93
93
|
#
|
@@ -238,7 +238,7 @@ module StytchB2B
|
|
238
238
|
#
|
239
239
|
# The type of this field is nilable list of +String+.
|
240
240
|
# mfa_policy::
|
241
|
-
#
|
241
|
+
# The setting that controls the MFA policy for all Members in the Organization. The accepted values are:
|
242
242
|
#
|
243
243
|
# `REQUIRED_FOR_ALL` – All Members within the Organization will be required to complete MFA every time they wish to log in.
|
244
244
|
#
|
@@ -389,10 +389,10 @@ module StytchB2B
|
|
389
389
|
# Identifies the Member as a break glass user - someone who has permissions to authenticate into an Organization by bypassing the Organization's settings. A break glass account is typically used for emergency purposes to gain access outside of normal authentication procedures. Refer to the [Organization object](organization-object) and its `auth_methods` and `allowed_auth_methods` fields for more details.
|
390
390
|
# The type of this field is nilable +Boolean+.
|
391
391
|
# mfa_phone_number::
|
392
|
-
# (
|
392
|
+
# Sets the Member's phone number. Throws an error if the Member already has a phone number. To change the Member's phone number, use the [Delete member phone number endpoint](https://stytch.com/docs/b2b/api/delete-member-mfa-phone-number) to delete the Member's existing phone number first.
|
393
393
|
# The type of this field is nilable +String+.
|
394
394
|
# mfa_enrolled::
|
395
|
-
#
|
395
|
+
# Sets whether the Member is enrolled in MFA. If true, the Member must complete an MFA step whenever they wish to log in to their Organization. If false, the Member only needs to complete an MFA step if the Organization's MFA policy is set to `REQUIRED_FOR_ALL`.
|
396
396
|
# The type of this field is nilable +Boolean+.
|
397
397
|
#
|
398
398
|
# == Returns:
|
@@ -404,7 +404,7 @@ module StytchB2B
|
|
404
404
|
# Globally unique UUID that identifies a specific Member.
|
405
405
|
# The type of this field is +String+.
|
406
406
|
# member::
|
407
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
407
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
408
408
|
# The type of this field is +Member+ (+object+).
|
409
409
|
# organization::
|
410
410
|
# The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
|
@@ -461,6 +461,75 @@ module StytchB2B
|
|
461
461
|
delete_request("/v1/b2b/organizations/#{organization_id}/members/#{member_id}")
|
462
462
|
end
|
463
463
|
|
464
|
+
# Reactivates a deleted Member's status and its associated email status (if applicable) to active, specified by `organization_id` and `member_id`.
|
465
|
+
#
|
466
|
+
# == Parameters:
|
467
|
+
# organization_id::
|
468
|
+
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
|
469
|
+
# The type of this field is +String+.
|
470
|
+
# member_id::
|
471
|
+
# Globally unique UUID that identifies a specific Member. The `member_id` is critical to perform operations on a Member, so be sure to preserve this value.
|
472
|
+
# The type of this field is +String+.
|
473
|
+
#
|
474
|
+
# == Returns:
|
475
|
+
# An object with the following fields:
|
476
|
+
# request_id::
|
477
|
+
# 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.
|
478
|
+
# The type of this field is +String+.
|
479
|
+
# member_id::
|
480
|
+
# Globally unique UUID that identifies a specific Member.
|
481
|
+
# The type of this field is +String+.
|
482
|
+
# member::
|
483
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
484
|
+
# The type of this field is +Member+ (+object+).
|
485
|
+
# organization::
|
486
|
+
# The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
|
487
|
+
# The type of this field is +Organization+ (+object+).
|
488
|
+
# status_code::
|
489
|
+
# 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.
|
490
|
+
# The type of this field is +Integer+.
|
491
|
+
def reactivate(
|
492
|
+
organization_id:,
|
493
|
+
member_id:
|
494
|
+
)
|
495
|
+
request = {}
|
496
|
+
|
497
|
+
put_request("/v1/b2b/organizations/#{organization_id}/members/#{member_id}/reactivate", request)
|
498
|
+
end
|
499
|
+
|
500
|
+
# Delete a Member's MFA phone number.
|
501
|
+
#
|
502
|
+
# To change a Member's phone number, you must first call this endpoint to delete the existing phone number.
|
503
|
+
#
|
504
|
+
# Existing Member Sessions that include a phone number authentication factor will not be revoked if the phone number is deleted, and MFA will not be enforced until the Member logs in again.
|
505
|
+
# If you wish to enforce MFA immediately after a phone number is deleted, you can do so by prompting the Member to enter a new phone number
|
506
|
+
# and calling the [OTP SMS send](https://stytch.com/docs/b2b/api/otp-sms-send) endpoint, then calling the [OTP SMS Authenticate](https://stytch.com/docs/b2b/api/authenticate-otp-sms) endpoint.
|
507
|
+
#
|
508
|
+
# == Parameters:
|
509
|
+
# organization_id::
|
510
|
+
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
|
511
|
+
# The type of this field is +String+.
|
512
|
+
# member_id::
|
513
|
+
# Globally unique UUID that identifies a specific Member. The `member_id` is critical to perform operations on a Member, so be sure to preserve this value.
|
514
|
+
# The type of this field is +String+.
|
515
|
+
#
|
516
|
+
# == Returns:
|
517
|
+
# An object with the following fields:
|
518
|
+
# request_id::
|
519
|
+
# 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.
|
520
|
+
# The type of this field is +String+.
|
521
|
+
# member_id::
|
522
|
+
# Globally unique UUID that identifies a specific Member.
|
523
|
+
# The type of this field is +String+.
|
524
|
+
# member::
|
525
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
526
|
+
# The type of this field is +Member+ (+object+).
|
527
|
+
# organization::
|
528
|
+
# The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
|
529
|
+
# The type of this field is +Organization+ (+object+).
|
530
|
+
# status_code::
|
531
|
+
# 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.
|
532
|
+
# The type of this field is +Integer+.
|
464
533
|
def delete_mfa_phone_number(
|
465
534
|
organization_id:,
|
466
535
|
member_id:
|
@@ -468,7 +537,7 @@ module StytchB2B
|
|
468
537
|
delete_request("/v1/b2b/organizations/#{organization_id}/members/mfa_phone_numbers/#{member_id}")
|
469
538
|
end
|
470
539
|
|
471
|
-
# Search for Members within specified Organizations. An array with at least one `organization_id` is required. Submitting an empty `query` returns all Members within the specified Organizations.
|
540
|
+
# Search for Members within specified Organizations. An array with at least one `organization_id` is required. Submitting an empty `query` returns all non-deleted Members within the specified Organizations.
|
472
541
|
#
|
473
542
|
# *All fuzzy search filters require a minimum of three characters.
|
474
543
|
#
|
@@ -538,7 +607,7 @@ module StytchB2B
|
|
538
607
|
# Globally unique UUID that identifies a specific Member.
|
539
608
|
# The type of this field is +String+.
|
540
609
|
# member::
|
541
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
610
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
542
611
|
# The type of this field is +Member+ (+object+).
|
543
612
|
# organization::
|
544
613
|
# The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
|
@@ -580,10 +649,10 @@ module StytchB2B
|
|
580
649
|
# Identifies the Member as a break glass user - someone who has permissions to authenticate into an Organization by bypassing the Organization's settings. A break glass account is typically used for emergency purposes to gain access outside of normal authentication procedures. Refer to the [Organization object](organization-object) and its `auth_methods` and `allowed_auth_methods` fields for more details.
|
581
650
|
# The type of this field is nilable +Boolean+.
|
582
651
|
# mfa_phone_number::
|
583
|
-
#
|
652
|
+
# The Member's phone number. A Member may only have one phone number.
|
584
653
|
# The type of this field is nilable +String+.
|
585
654
|
# mfa_enrolled::
|
586
|
-
#
|
655
|
+
# Sets whether the Member is enrolled in MFA. If true, the Member must complete an MFA step whenever they wish to log in to their Organization. If false, the Member only needs to complete an MFA step if the Organization's MFA policy is set to `REQUIRED_FOR_ALL`.
|
587
656
|
# The type of this field is nilable +Boolean+.
|
588
657
|
#
|
589
658
|
# == Returns:
|
@@ -595,7 +664,7 @@ module StytchB2B
|
|
595
664
|
# Globally unique UUID that identifies a specific Member.
|
596
665
|
# The type of this field is +String+.
|
597
666
|
# member::
|
598
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
667
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
599
668
|
# The type of this field is +Member+ (+object+).
|
600
669
|
# organization::
|
601
670
|
# The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
|
@@ -650,7 +719,7 @@ module StytchB2B
|
|
650
719
|
# Globally unique UUID that identifies a specific Member.
|
651
720
|
# The type of this field is +String+.
|
652
721
|
# member::
|
653
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
722
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
654
723
|
# The type of this field is +Member+ (+object+).
|
655
724
|
# organization::
|
656
725
|
# The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
|
data/lib/stytch/b2b_otp.rb
CHANGED
@@ -26,13 +26,20 @@ module StytchB2B
|
|
26
26
|
@connection = connection
|
27
27
|
end
|
28
28
|
|
29
|
-
# Send a
|
30
|
-
#
|
29
|
+
# Send a One-Time Passcode (OTP) to a Member's phone number.
|
30
|
+
#
|
31
|
+
# If the Member already has a phone number, the `mfa_phone_number` field is not needed; the endpoint will send an OTP to the number associated with the Member.
|
32
|
+
# If the Member does not have a phone number, the endpoint will send an OTP to the `mfa_phone_number` provided and link the `mfa_phone_number` with the Member.
|
33
|
+
#
|
34
|
+
# An error will be thrown if the Member already has a phone number and the provided `mfa_phone_number` does not match the existing one.
|
31
35
|
#
|
32
36
|
# Note that sending another OTP code before the first has expired will invalidate the first code.
|
33
37
|
#
|
34
38
|
# If a Member has a phone number and is enrolled in MFA, then after a successful primary authentication event (e.g. [email magic link](https://stytch.com/docs/b2b/api/authenticate-magic-link) or [SSO](https://stytch.com/docs/b2b/api/sso-authenticate) login is complete), an SMS OTP will automatically be sent to their phone number. In that case, this endpoint should only be used for subsequent authentication events, such as prompting a Member for an OTP again after a period of inactivity.
|
35
39
|
#
|
40
|
+
# ### Cost to send SMS OTP
|
41
|
+
# Before configuring SMS or WhatsApp OTPs, please review how Stytch [bills the costs of international OTPs](https://stytch.com/pricing) and understand how to protect your app against [toll fraud](https://stytch.com/docs/guides/passcodes/toll-fraud/overview).
|
42
|
+
#
|
36
43
|
# == Parameters:
|
37
44
|
# organization_id::
|
38
45
|
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
|
@@ -41,7 +48,7 @@ module StytchB2B
|
|
41
48
|
# Globally unique UUID that identifies a specific Member. The `member_id` is critical to perform operations on a Member, so be sure to preserve this value.
|
42
49
|
# The type of this field is +String+.
|
43
50
|
# mfa_phone_number::
|
44
|
-
#
|
51
|
+
# The phone number to send the OTP to. If the Member already has a phone number, this argument is not needed.
|
45
52
|
# The type of this field is nilable +String+.
|
46
53
|
# locale::
|
47
54
|
# Used to determine which language to use when sending the user this delivery method. Parameter is a [IETF BCP 47 language tag](https://www.w3.org/International/articles/language-tags/), e.g. `"en"`.
|
@@ -61,7 +68,7 @@ module StytchB2B
|
|
61
68
|
# Globally unique UUID that identifies a specific Member.
|
62
69
|
# The type of this field is +String+.
|
63
70
|
# member::
|
64
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
71
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
65
72
|
# The type of this field is +Member+ (+object+).
|
66
73
|
# organization::
|
67
74
|
# The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
|
@@ -85,13 +92,20 @@ module StytchB2B
|
|
85
92
|
post_request('/v1/b2b/otps/sms/send', request)
|
86
93
|
end
|
87
94
|
|
88
|
-
#
|
95
|
+
# SMS OTPs may not be used as a primary authentication mechanism. They can be used to complete an MFA requirement, or they can be used as a step-up factor to be added to an existing session.
|
96
|
+
#
|
97
|
+
# This endpoint verifies that the one-time passcode (OTP) is valid and hasn't expired or been previously used. A given Member may only have a single active OTP code at any given time. If a Member requests another OTP code before the first one has expired, the first one will be invalidated.
|
89
98
|
#
|
90
99
|
# Exactly one of `intermediate_session_token`, `session_token`, or `session_jwt` must be provided in the request.
|
91
100
|
# If an intermediate session token is provided, this operation will consume it.
|
92
101
|
#
|
102
|
+
# Intermediate session tokens are generated upon successful calls to primary authenticate methods in the case where MFA is required,
|
103
|
+
# such as [email magic link authenticate](https://stytch.com/docs/b2b/api/authenticate-magic-link),
|
104
|
+
# or upon successful calls to discovery authenticate methods, such as [email magic link discovery authenticate](https://stytch.com/docs/b2b/api/authenticate-discovery-magic-link).
|
105
|
+
#
|
93
106
|
# If the Organization's MFA policy is `REQUIRED_FOR_ALL`, a successful OTP authentication will change the Member's `mfa_enrolled` status to `true` if it is not already `true`.
|
94
107
|
# If the Organization's MFA policy is `OPTIONAL`, the Member's MFA enrollment can be toggled by passing in a value for the `set_mfa_enrollment` field.
|
108
|
+
# The Member's MFA enrollment can also be toggled through the [Update Member](https://stytch.com/docs/b2b/api/update-member) endpoint.
|
95
109
|
#
|
96
110
|
# Provide the `session_duration_minutes` parameter to set the lifetime of the session. If the `session_duration_minutes` parameter is not specified, a Stytch session will be created with a duration of 60 minutes.
|
97
111
|
#
|
@@ -153,7 +167,7 @@ module StytchB2B
|
|
153
167
|
# Globally unique UUID that identifies a specific Member.
|
154
168
|
# The type of this field is +String+.
|
155
169
|
# member::
|
156
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
170
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
157
171
|
# The type of this field is +Member+ (+object+).
|
158
172
|
# organization::
|
159
173
|
# The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
|
data/lib/stytch/b2b_passwords.rb
CHANGED
@@ -140,7 +140,7 @@ module StytchB2B
|
|
140
140
|
# A flag indicating `true` if a new Member object was created and `false` if the Member object already existed.
|
141
141
|
# The type of this field is +Boolean+.
|
142
142
|
# member::
|
143
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
143
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
144
144
|
# The type of this field is +Member+ (+object+).
|
145
145
|
# organization::
|
146
146
|
# The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
|
@@ -187,7 +187,7 @@ module StytchB2B
|
|
187
187
|
# * We force a password reset in this instance in order to safely deduplicate the account by email address, without introducing the risk of a pre-hijack account takeover attack.
|
188
188
|
# * Imagine a bad actor creates many accounts using passwords and the known email addresses of their victims. If a victim comes to the site and logs in for the first time with an email-based passwordless authentication method then both the victim and the bad actor have credentials to access to the same account. To prevent this, any further email/password login attempts first require a password reset which can only be accomplished by someone with access to the underlying email address.
|
189
189
|
#
|
190
|
-
#
|
190
|
+
# If the Member is required to complete MFA to log in to the Organization, the returned value of `member_authenticated` will be `false`, and an `intermediate_session_token` will be returned.
|
191
191
|
# The `intermediate_session_token` can be passed into the [OTP SMS Authenticate endpoint](https://stytch.com/docs/b2b/api/authenticate-otp-sms) to complete the MFA step and acquire a full member session.
|
192
192
|
# The `session_duration_minutes` and `session_custom_claims` parameters will be ignored.
|
193
193
|
#
|
@@ -228,7 +228,7 @@ module StytchB2B
|
|
228
228
|
# Total custom claims size cannot exceed four kilobytes.
|
229
229
|
# The type of this field is nilable +object+.
|
230
230
|
# locale::
|
231
|
-
#
|
231
|
+
# If the Member needs to complete an MFA step, and the Member has a phone number, this endpoint will pre-emptively send a one-time passcode (OTP) to the Member's phone number. The locale argument will be used to determine which language to use when sending the passcode.
|
232
232
|
#
|
233
233
|
# Parameter is a [IETF BCP 47 language tag](https://www.w3.org/International/articles/language-tags/), e.g. `"en"`.
|
234
234
|
#
|
@@ -250,7 +250,7 @@ module StytchB2B
|
|
250
250
|
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
|
251
251
|
# The type of this field is +String+.
|
252
252
|
# member::
|
253
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
253
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
254
254
|
# The type of this field is +Member+ (+object+).
|
255
255
|
# session_token::
|
256
256
|
# A secret token for a given Stytch Session.
|
@@ -276,7 +276,7 @@ module StytchB2B
|
|
276
276
|
# The [Session object](https://stytch.com/docs/b2b/api/session-object).
|
277
277
|
# The type of this field is nilable +MemberSession+ (+object+).
|
278
278
|
# mfa_required::
|
279
|
-
#
|
279
|
+
# Information about the MFA requirements of the Organization and the Member's options for fulfilling MFA.
|
280
280
|
# The type of this field is nilable +MfaRequired+ (+object+).
|
281
281
|
def authenticate(
|
282
282
|
organization_id:,
|
@@ -398,7 +398,7 @@ module StytchB2B
|
|
398
398
|
#
|
399
399
|
# The provided password needs to meet our password strength requirements, which can be checked in advance with the password strength endpoint. If the token and password are accepted, the password is securely stored for future authentication and the user is authenticated.
|
400
400
|
#
|
401
|
-
#
|
401
|
+
# If the Member is required to complete MFA to log in to the Organization, the returned value of `member_authenticated` will be `false`, and an `intermediate_session_token` will be returned.
|
402
402
|
# The `intermediate_session_token` can be passed into the [OTP SMS Authenticate endpoint](https://stytch.com/docs/b2b/api/authenticate-otp-sms) to complete the MFA step and acquire a full member session.
|
403
403
|
# The `session_duration_minutes` and `session_custom_claims` parameters will be ignored.
|
404
404
|
#
|
@@ -443,7 +443,7 @@ module StytchB2B
|
|
443
443
|
# Total custom claims size cannot exceed four kilobytes.
|
444
444
|
# The type of this field is nilable +object+.
|
445
445
|
# locale::
|
446
|
-
#
|
446
|
+
# If the Member needs to complete an MFA step, and the Member has a phone number, this endpoint will pre-emptively send a one-time passcode (OTP) to the Member's phone number. The locale argument will be used to determine which language to use when sending the passcode.
|
447
447
|
#
|
448
448
|
# Parameter is a [IETF BCP 47 language tag](https://www.w3.org/International/articles/language-tags/), e.g. `"en"`.
|
449
449
|
#
|
@@ -468,7 +468,7 @@ module StytchB2B
|
|
468
468
|
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
|
469
469
|
# The type of this field is +String+.
|
470
470
|
# member::
|
471
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
471
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
472
472
|
# The type of this field is +Member+ (+object+).
|
473
473
|
# session_token::
|
474
474
|
# A secret token for a given Stytch Session.
|
@@ -494,7 +494,7 @@ module StytchB2B
|
|
494
494
|
# The [Session object](https://stytch.com/docs/b2b/api/session-object).
|
495
495
|
# The type of this field is nilable +MemberSession+ (+object+).
|
496
496
|
# mfa_required::
|
497
|
-
#
|
497
|
+
# Information about the MFA requirements of the Organization and the Member's options for fulfilling MFA.
|
498
498
|
# The type of this field is nilable +MfaRequired+ (+object+).
|
499
499
|
def reset(
|
500
500
|
password_reset_token:,
|
@@ -553,7 +553,7 @@ module StytchB2B
|
|
553
553
|
# Globally unique UUID that identifies a specific Member.
|
554
554
|
# The type of this field is +String+.
|
555
555
|
# member::
|
556
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
556
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
557
557
|
# The type of this field is +Member+ (+object+).
|
558
558
|
# organization::
|
559
559
|
# The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
|
@@ -596,7 +596,7 @@ module StytchB2B
|
|
596
596
|
# considered valid if they meet the requirements that you've set with Stytch.
|
597
597
|
# You may update your password strength configuration in the [stytch dashboard](https://stytch.com/dashboard/password-strength-config).
|
598
598
|
#
|
599
|
-
#
|
599
|
+
# If the Member is required to complete MFA to log in to the Organization, the returned value of `member_authenticated` will be `false`, and an `intermediate_session_token` will be returned.
|
600
600
|
# The `intermediate_session_token` can be passed into the [OTP SMS Authenticate endpoint](https://stytch.com/docs/b2b/api/authenticate-otp-sms) to complete the MFA step and acquire a full member session.
|
601
601
|
# The `session_duration_minutes` and `session_custom_claims` parameters will be ignored.
|
602
602
|
#
|
@@ -640,7 +640,7 @@ module StytchB2B
|
|
640
640
|
# Total custom claims size cannot exceed four kilobytes.
|
641
641
|
# The type of this field is nilable +object+.
|
642
642
|
# locale::
|
643
|
-
#
|
643
|
+
# If the Member needs to complete an MFA step, and the Member has a phone number, this endpoint will pre-emptively send a one-time passcode (OTP) to the Member's phone number. The locale argument will be used to determine which language to use when sending the passcode.
|
644
644
|
#
|
645
645
|
# Parameter is a [IETF BCP 47 language tag](https://www.w3.org/International/articles/language-tags/), e.g. `"en"`.
|
646
646
|
#
|
@@ -659,7 +659,7 @@ module StytchB2B
|
|
659
659
|
# Globally unique UUID that identifies a specific Member.
|
660
660
|
# The type of this field is +String+.
|
661
661
|
# member::
|
662
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
662
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
663
663
|
# The type of this field is +Member+ (+object+).
|
664
664
|
# session_token::
|
665
665
|
# A secret token for a given Stytch Session.
|
@@ -685,7 +685,7 @@ module StytchB2B
|
|
685
685
|
# The [Session object](https://stytch.com/docs/b2b/api/session-object).
|
686
686
|
# The type of this field is nilable +MemberSession+ (+object+).
|
687
687
|
# mfa_required::
|
688
|
-
#
|
688
|
+
# Information about the MFA requirements of the Organization and the Member's options for fulfilling MFA.
|
689
689
|
# The type of this field is nilable +MfaRequired+ (+object+).
|
690
690
|
def reset(
|
691
691
|
email_address:,
|
data/lib/stytch/b2b_sessions.rb
CHANGED
@@ -6,14 +6,31 @@
|
|
6
6
|
# or your changes may be overwritten later!
|
7
7
|
# !!!
|
8
8
|
|
9
|
+
require 'jwt'
|
10
|
+
require 'json/jwt'
|
11
|
+
require_relative 'errors'
|
9
12
|
require_relative 'request_helper'
|
10
13
|
|
11
14
|
module StytchB2B
|
12
15
|
class Sessions
|
13
16
|
include Stytch::RequestHelper
|
14
17
|
|
15
|
-
def initialize(connection)
|
18
|
+
def initialize(connection, project_id)
|
16
19
|
@connection = 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
|
17
34
|
end
|
18
35
|
|
19
36
|
# Retrieves all active Sessions for a Member.
|
@@ -94,7 +111,7 @@ module StytchB2B
|
|
94
111
|
# The JSON Web Token (JWT) for a given Stytch Session.
|
95
112
|
# The type of this field is +String+.
|
96
113
|
# member::
|
97
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
114
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
98
115
|
# The type of this field is +Member+ (+object+).
|
99
116
|
# organization::
|
100
117
|
# The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
|
@@ -163,7 +180,7 @@ module StytchB2B
|
|
163
180
|
# Only Email Magic Link, OAuth, and SMS OTP factors can be transferred between sessions. Other authentication factors, such as password factors, will not be transferred to the new session.
|
164
181
|
# SMS OTP factors can be used to fulfill MFA requirements for the target Organization if both the original and target Member have the same phone number and the phone number is verified for both Members.
|
165
182
|
#
|
166
|
-
#
|
183
|
+
# If the Member is required to complete MFA to log in to the Organization, the returned value of `member_authenticated` will be `false`, and an `intermediate_session_token` will be returned.
|
167
184
|
# The `intermediate_session_token` can be passed into the [OTP SMS Authenticate endpoint](https://stytch.com/docs/b2b/api/authenticate-otp-sms) to complete the MFA step and acquire a full member session.
|
168
185
|
# The `intermediate_session_token` can also be used with the [Exchange Intermediate Session endpoint](https://stytch.com/docs/b2b/api/exchange-intermediate-session) or the [Create Organization via Discovery endpoint](https://stytch.com/docs/b2b/api/create-organization-via-discovery) to join a different Organization or create a new one.
|
169
186
|
# The `session_duration_minutes` and `session_custom_claims` parameters will be ignored.
|
@@ -197,7 +214,7 @@ module StytchB2B
|
|
197
214
|
# Total custom claims size cannot exceed four kilobytes.
|
198
215
|
# The type of this field is nilable +object+.
|
199
216
|
# locale::
|
200
|
-
#
|
217
|
+
# If the Member needs to complete an MFA step, and the Member has a phone number, this endpoint will pre-emptively send a one-time passcode (OTP) to the Member's phone number. The locale argument will be used to determine which language to use when sending the passcode.
|
201
218
|
#
|
202
219
|
# Parameter is a [IETF BCP 47 language tag](https://www.w3.org/International/articles/language-tags/), e.g. `"en"`.
|
203
220
|
#
|
@@ -225,7 +242,7 @@ module StytchB2B
|
|
225
242
|
# The JSON Web Token (JWT) for a given Stytch Session.
|
226
243
|
# The type of this field is +String+.
|
227
244
|
# member::
|
228
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
245
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
229
246
|
# The type of this field is +Member+ (+object+).
|
230
247
|
# organization::
|
231
248
|
# The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
|
@@ -243,7 +260,7 @@ module StytchB2B
|
|
243
260
|
# 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.
|
244
261
|
# The type of this field is +Integer+.
|
245
262
|
# mfa_required::
|
246
|
-
#
|
263
|
+
# Information about the MFA requirements of the Organization and the Member's options for fulfilling MFA.
|
247
264
|
# The type of this field is nilable +MfaRequired+ (+object+).
|
248
265
|
def exchange(
|
249
266
|
organization_id:,
|
@@ -290,5 +307,92 @@ module StytchB2B
|
|
290
307
|
request = request_with_query_params("/v1/b2b/sessions/jwks/#{project_id}", query_params)
|
291
308
|
get_request(request)
|
292
309
|
end
|
310
|
+
|
311
|
+
# MANUAL(Sessions::authenticate_jwt)(SERVICE_METHOD)
|
312
|
+
# ADDIMPORT: require 'jwt'
|
313
|
+
# ADDIMPORT: require 'json/jwt'
|
314
|
+
# ADDIMPORT: require_relative 'errors'
|
315
|
+
|
316
|
+
# Parse a JWT and verify the signature. If max_token_age_seconds is unset, call the API directly
|
317
|
+
# If max_token_age_seconds is set and the JWT was issued (based on the "iat" claim) less than
|
318
|
+
# max_token_age_seconds seconds ago, then just verify locally and don't call the API
|
319
|
+
# To force remote validation for all tokens, set max_token_age_seconds to 0 or call authenticate()
|
320
|
+
def authenticate_jwt(
|
321
|
+
session_jwt,
|
322
|
+
max_token_age_seconds: nil,
|
323
|
+
session_duration_minutes: nil,
|
324
|
+
session_custom_claims: nil
|
325
|
+
)
|
326
|
+
if max_token_age_seconds == 0
|
327
|
+
return authenticate(
|
328
|
+
session_jwt: session_jwt,
|
329
|
+
session_duration_minutes: session_duration_minutes,
|
330
|
+
session_custom_claims: session_custom_claims
|
331
|
+
)
|
332
|
+
end
|
333
|
+
|
334
|
+
decoded_jwt = authenticate_jwt_local(session_jwt)
|
335
|
+
iat_time = Time.at(decoded_jwt['iat']).to_datetime
|
336
|
+
if iat_time + max_token_age_seconds >= Time.now
|
337
|
+
session = marshal_jwt_into_session(decoded_jwt)
|
338
|
+
{ 'session' => session }
|
339
|
+
else
|
340
|
+
authenticate(
|
341
|
+
session_jwt: session_jwt,
|
342
|
+
session_duration_minutes: session_duration_minutes,
|
343
|
+
session_custom_claims: session_custom_claims
|
344
|
+
)
|
345
|
+
end
|
346
|
+
rescue StandardError
|
347
|
+
# JWT could not be verified locally. Check with the Stytch API.
|
348
|
+
authenticate(
|
349
|
+
session_jwt: session_jwt,
|
350
|
+
session_duration_minutes: session_duration_minutes,
|
351
|
+
session_custom_claims: session_custom_claims
|
352
|
+
)
|
353
|
+
end
|
354
|
+
|
355
|
+
# Parse a JWT and verify the signature locally (without calling /authenticate in the API)
|
356
|
+
# Uses the cached value to get the JWK but if it is unavailable, it calls the get_jwks()
|
357
|
+
# function to get the JWK
|
358
|
+
# This method never authenticates a JWT directly with the API
|
359
|
+
def authenticate_jwt_local(session_jwt)
|
360
|
+
issuer = 'stytch.com/' + @project_id
|
361
|
+
begin
|
362
|
+
decoded_token = JWT.decode session_jwt, nil, true,
|
363
|
+
{ jwks: @jwks_loader, iss: issuer, verify_iss: true, aud: @project_id, verify_aud: true, algorithms: ['RS256'] }
|
364
|
+
decoded_token[0]
|
365
|
+
rescue JWT::InvalidIssuerError
|
366
|
+
raise JWTInvalidIssuerError
|
367
|
+
rescue JWT::InvalidAudError
|
368
|
+
raise JWTInvalidAudienceError
|
369
|
+
rescue JWT::ExpiredSignature
|
370
|
+
raise JWTExpiredSignatureError
|
371
|
+
rescue JWT::IncorrectAlgorithm
|
372
|
+
raise JWTIncorrectAlgorithmError
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
def marshal_jwt_into_session(jwt)
|
377
|
+
stytch_claim = 'https://stytch.com/session'
|
378
|
+
expires_at = jwt[stytch_claim]['expires_at'] || Time.at(jwt['exp']).to_datetime.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
|
379
|
+
# The custom claim set is all the claims in the payload except for the standard claims and
|
380
|
+
# the Stytch session claim. The cleanest way to collect those seems to be naming what we want
|
381
|
+
# to omit and filtering the rest to collect the custom claims.
|
382
|
+
reserved_claims = ['aud', 'exp', 'iat', 'iss', 'jti', 'nbf', 'sub', stytch_claim]
|
383
|
+
custom_claims = jwt.reject { |key, _| reserved_claims.include?(key) }
|
384
|
+
{
|
385
|
+
'session_id' => jwt[stytch_claim]['id'],
|
386
|
+
'user_id' => jwt['sub'],
|
387
|
+
'started_at' => jwt[stytch_claim]['started_at'],
|
388
|
+
'last_accessed_at' => jwt[stytch_claim]['last_accessed_at'],
|
389
|
+
# For JWTs that include it, prefer the inner expires_at claim.
|
390
|
+
'expires_at' => expires_at,
|
391
|
+
'attributes' => jwt[stytch_claim]['attributes'],
|
392
|
+
'authentication_factors' => jwt[stytch_claim]['authentication_factors'],
|
393
|
+
'custom_claims' => custom_claims
|
394
|
+
}
|
395
|
+
end
|
396
|
+
# ENDMANUAL(Sessions::authenticate_jwt)
|
293
397
|
end
|
294
398
|
end
|
data/lib/stytch/b2b_sso.rb
CHANGED
@@ -83,7 +83,7 @@ module StytchB2B
|
|
83
83
|
# If the `session_duration_minutes` parameter is not specified, a Stytch session will be created with a 60 minute duration.
|
84
84
|
# To link this authentication event to an existing Stytch session, include either the `session_token` or `session_jwt` param.
|
85
85
|
#
|
86
|
-
#
|
86
|
+
# If the Member is required to complete MFA to log in to the Organization, the returned value of `member_authenticated` will be `false`, and an `intermediate_session_token` will be returned.
|
87
87
|
# The `intermediate_session_token` can be passed into the [OTP SMS Authenticate endpoint](https://stytch.com/docs/b2b/api/authenticate-otp-sms) to complete the MFA step and acquire a full member session.
|
88
88
|
# The `session_duration_minutes` and `session_custom_claims` parameters will be ignored.
|
89
89
|
#
|
@@ -121,7 +121,7 @@ module StytchB2B
|
|
121
121
|
# Total custom claims size cannot exceed four kilobytes.
|
122
122
|
# The type of this field is nilable +object+.
|
123
123
|
# locale::
|
124
|
-
#
|
124
|
+
# If the Member needs to complete an MFA step, and the Member has a phone number, this endpoint will pre-emptively send a one-time passcode (OTP) to the Member's phone number. The locale argument will be used to determine which language to use when sending the passcode.
|
125
125
|
#
|
126
126
|
# Parameter is a [IETF BCP 47 language tag](https://www.w3.org/International/articles/language-tags/), e.g. `"en"`.
|
127
127
|
#
|
@@ -143,7 +143,7 @@ module StytchB2B
|
|
143
143
|
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
|
144
144
|
# The type of this field is +String+.
|
145
145
|
# member::
|
146
|
-
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
146
|
+
# The [Member object](https://stytch.com/docs/b2b/api/member-object)
|
147
147
|
# The type of this field is +Member+ (+object+).
|
148
148
|
# session_token::
|
149
149
|
# A secret token for a given Stytch Session.
|
@@ -173,7 +173,7 @@ module StytchB2B
|
|
173
173
|
# The [Session object](https://stytch.com/docs/b2b/api/session-object).
|
174
174
|
# The type of this field is nilable +MemberSession+ (+object+).
|
175
175
|
# mfa_required::
|
176
|
-
#
|
176
|
+
# Information about the MFA requirements of the Organization and the Member's options for fulfilling MFA.
|
177
177
|
# The type of this field is nilable +MfaRequired+ (+object+).
|
178
178
|
def authenticate(
|
179
179
|
sso_token:,
|
data/lib/stytch/m2m.rb
CHANGED
@@ -33,7 +33,6 @@ module Stytch
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
36
|
# MANUAL(M2M::get_jwks)(SERVICE_METHOD)
|
38
37
|
# This is a helper so we can retrieve the JWKS for a project for decoding M2M access tokens
|
39
38
|
def get_jwks(
|
@@ -81,7 +80,7 @@ module Stytch
|
|
81
80
|
}
|
82
81
|
request[:scope] = scopes.join(' ') unless scopes.nil?
|
83
82
|
|
84
|
-
JSON.parse(post_request("/v1/public/#{@project_id}/oauth2/token", request), {:
|
83
|
+
JSON.parse(post_request("/v1/public/#{@project_id}/oauth2/token", request), { symbolize_names: true })
|
85
84
|
end
|
86
85
|
# ENDMANUAL(M2M::token)
|
87
86
|
|
@@ -116,19 +115,13 @@ module Stytch
|
|
116
115
|
iat_time = Time.at(decoded_jwt['iat']).to_datetime
|
117
116
|
|
118
117
|
# Token too old
|
119
|
-
|
120
|
-
if iat_time + max_token_age < Time.now
|
121
|
-
raise JWTExpiredError
|
122
|
-
end
|
123
|
-
end
|
118
|
+
raise JWTExpiredError if !max_token_age.nil? && (iat_time + max_token_age < Time.now)
|
124
119
|
|
125
120
|
resp = marshal_jwt_into_response(decoded_jwt)
|
126
121
|
|
127
122
|
unless required_scopes.nil?
|
128
123
|
for scope in required_scopes
|
129
|
-
unless resp['scopes'].include?(scope)
|
130
|
-
raise TokenMissingScopeError.new(scope)
|
131
|
-
end
|
124
|
+
raise TokenMissingScopeError, scope unless resp['scopes'].include?(scope)
|
132
125
|
end
|
133
126
|
end
|
134
127
|
|
@@ -189,12 +182,12 @@ module Stytch
|
|
189
182
|
# request_id::
|
190
183
|
# 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.
|
191
184
|
# The type of this field is +String+.
|
185
|
+
# m2m_client::
|
186
|
+
# The M2M Client affected by this operation.
|
187
|
+
# The type of this field is +M2MClient+ (+object+).
|
192
188
|
# status_code::
|
193
189
|
# 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.
|
194
190
|
# The type of this field is +Integer+.
|
195
|
-
# m2m_client::
|
196
|
-
# The M2M Client affected by this operation.
|
197
|
-
# The type of this field is nilable +M2MClient+ (+object+).
|
198
191
|
def get(
|
199
192
|
client_id:
|
200
193
|
)
|
@@ -278,12 +271,12 @@ module Stytch
|
|
278
271
|
# request_id::
|
279
272
|
# 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.
|
280
273
|
# The type of this field is +String+.
|
274
|
+
# m2m_client::
|
275
|
+
# The M2M Client affected by this operation.
|
276
|
+
# The type of this field is +M2MClient+ (+object+).
|
281
277
|
# status_code::
|
282
278
|
# 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.
|
283
279
|
# The type of this field is +Integer+.
|
284
|
-
# m2m_client::
|
285
|
-
# The M2M Client affected by this operation.
|
286
|
-
# The type of this field is nilable +M2MClient+ (+object+).
|
287
280
|
def update(
|
288
281
|
client_id:,
|
289
282
|
client_name: nil,
|
@@ -358,12 +351,12 @@ module Stytch
|
|
358
351
|
# request_id::
|
359
352
|
# 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.
|
360
353
|
# The type of this field is +String+.
|
354
|
+
# m2m_client::
|
355
|
+
# The M2M Client created by this API call.
|
356
|
+
# The type of this field is +M2MClientWithClientSecret+ (+object+).
|
361
357
|
# status_code::
|
362
358
|
# 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.
|
363
359
|
# The type of this field is +Integer+.
|
364
|
-
# m2m_client::
|
365
|
-
# The M2M Client created by this API call.
|
366
|
-
# The type of this field is nilable +M2MClientWithClientSecret+ (+object+).
|
367
360
|
def create(
|
368
361
|
scopes:,
|
369
362
|
client_id: nil,
|
@@ -391,8 +384,8 @@ module Stytch
|
|
391
384
|
@connection = connection
|
392
385
|
end
|
393
386
|
|
394
|
-
# 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.
|
395
|
-
# 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).
|
387
|
+
# 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.
|
388
|
+
# 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).
|
396
389
|
#
|
397
390
|
# **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.
|
398
391
|
#
|
@@ -406,12 +399,12 @@ module Stytch
|
|
406
399
|
# request_id::
|
407
400
|
# 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.
|
408
401
|
# The type of this field is +String+.
|
402
|
+
# m2m_client::
|
403
|
+
# The M2M Client affected by this operation.
|
404
|
+
# The type of this field is +M2MClientWithNextClientSecret+ (+object+).
|
409
405
|
# status_code::
|
410
406
|
# 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.
|
411
407
|
# The type of this field is +Integer+.
|
412
|
-
# m2m_client::
|
413
|
-
# The M2M Client affected by this operation.
|
414
|
-
# The type of this field is nilable +M2MClientWithNextClientSecret+ (+object+).
|
415
408
|
def rotate_start(
|
416
409
|
client_id:
|
417
410
|
)
|
@@ -420,7 +413,7 @@ module Stytch
|
|
420
413
|
post_request("/v1/m2m/clients/#{client_id}/secrets/rotate/start", request)
|
421
414
|
end
|
422
415
|
|
423
|
-
# 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).
|
416
|
+
# 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).
|
424
417
|
# After this endpoint is called, the client's `next_client_secret` is discarded and only the original `client_secret` will be valid.
|
425
418
|
#
|
426
419
|
# == Parameters:
|
@@ -433,12 +426,12 @@ module Stytch
|
|
433
426
|
# request_id::
|
434
427
|
# 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.
|
435
428
|
# The type of this field is +String+.
|
429
|
+
# m2m_client::
|
430
|
+
# The M2M Client affected by this operation.
|
431
|
+
# The type of this field is +M2MClient+ (+object+).
|
436
432
|
# status_code::
|
437
433
|
# 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.
|
438
434
|
# The type of this field is +Integer+.
|
439
|
-
# m2m_client::
|
440
|
-
# The M2M Client affected by this operation.
|
441
|
-
# The type of this field is nilable +M2MClient+ (+object+).
|
442
435
|
def rotate_cancel(
|
443
436
|
client_id:
|
444
437
|
)
|
@@ -447,7 +440,7 @@ module Stytch
|
|
447
440
|
post_request("/v1/m2m/clients/#{client_id}/secrets/rotate/cancel", request)
|
448
441
|
end
|
449
442
|
|
450
|
-
# 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).
|
443
|
+
# 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).
|
451
444
|
# 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.
|
452
445
|
#
|
453
446
|
# == Parameters:
|
@@ -460,12 +453,12 @@ module Stytch
|
|
460
453
|
# request_id::
|
461
454
|
# 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.
|
462
455
|
# The type of this field is +String+.
|
456
|
+
# m2m_client::
|
457
|
+
# The M2M Client affected by this operation.
|
458
|
+
# The type of this field is +M2MClient+ (+object+).
|
463
459
|
# status_code::
|
464
460
|
# 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.
|
465
461
|
# The type of this field is +Integer+.
|
466
|
-
# m2m_client::
|
467
|
-
# The M2M Client affected by this operation.
|
468
|
-
# The type of this field is nilable +M2MClient+ (+object+).
|
469
462
|
def rotate(
|
470
463
|
client_id:
|
471
464
|
)
|
data/lib/stytch/magic_links.rb
CHANGED
@@ -167,9 +167,7 @@ module Stytch
|
|
167
167
|
# Send a magic link to an existing Stytch user using their email address. If you'd like to create a user and send them a magic link by email with one request, use our [log in or create endpoint](https://stytch.com/docs/api/log-in-or-create-user-by-email).
|
168
168
|
#
|
169
169
|
# ### Add an email to an existing user
|
170
|
-
# This endpoint also allows you to add a new email to an existing Stytch User. Including a `user_id`, `session_token`, or `session_jwt` in
|
171
|
-
#
|
172
|
-
# Adding a new email to an existing Stytch User requires the user to be present and validate the email via magic link. This requirement is in place to prevent account takeover attacks.
|
170
|
+
# This endpoint also allows you to add a new email address to an existing Stytch User. Including a `user_id`, `session_token`, or `session_jwt` in your Send Magic Link by email request will add the new, unverified email address to the existing Stytch User. Upon successful authentication, the email address will be marked as verified.
|
173
171
|
#
|
174
172
|
# ### Next steps
|
175
173
|
# 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.
|
data/lib/stytch/otps.rb
CHANGED
@@ -126,11 +126,12 @@ module Stytch
|
|
126
126
|
#
|
127
127
|
# Note that sending another OTP code before the first has expired will invalidate the first code.
|
128
128
|
#
|
129
|
-
# ###
|
129
|
+
# ### Cost to send SMS OTP
|
130
|
+
# Before configuring SMS or WhatsApp OTPs, please review how Stytch [bills the costs of international OTPs](https://stytch.com/pricing) and understand how to protect your app against [toll fraud](https://stytch.com/docs/guides/passcodes/toll-fraud/overview).
|
130
131
|
#
|
131
|
-
#
|
132
|
+
# ### Add a phone number to an existing user
|
132
133
|
#
|
133
|
-
#
|
134
|
+
# This endpoint also allows you to add a new phone number to an existing Stytch User. Including a `user_id`, `session_token`, or `session_jwt` in your Send one-time passcode by SMS request will add the new, unverified phone number to the existing Stytch User. Upon successful authentication, the phone number will be marked as verified.
|
134
135
|
#
|
135
136
|
# ### Next steps
|
136
137
|
#
|
@@ -138,7 +139,7 @@ module Stytch
|
|
138
139
|
#
|
139
140
|
# == Parameters:
|
140
141
|
# phone_number::
|
141
|
-
# The phone number to use for one-time passcodes. The phone number should be in E.164 format
|
142
|
+
# The phone number to use for one-time passcodes. 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
143
|
# The type of this field is +String+.
|
143
144
|
# expiration_minutes::
|
144
145
|
# 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.
|
@@ -200,15 +201,17 @@ module Stytch
|
|
200
201
|
post_request('/v1/otps/sms/send', request)
|
201
202
|
end
|
202
203
|
|
203
|
-
# Send a
|
204
|
+
# Send a One-Time Passcode (OTP) to a User using their phone number. If the phone number is not associated with a user already, a user will be created.
|
204
205
|
#
|
206
|
+
# ### Cost to send SMS OTP
|
207
|
+
# Before configuring SMS or WhatsApp OTPs, please review how Stytch [bills the costs of international OTPs](https://stytch.com/pricing) and understand how to protect your app against [toll fraud](https://stytch.com/docs/guides/passcodes/toll-fraud/overview).
|
205
208
|
# ### Next steps
|
206
209
|
#
|
207
210
|
# Collect the OTP which was delivered to the User. Call [Authenticate OTP](https://stytch.com/docs/api/authenticate-otp) using the OTP `code` along with the `phone_id` found in the response as the `method_id`.
|
208
211
|
#
|
209
212
|
# == Parameters:
|
210
213
|
# phone_number::
|
211
|
-
# The phone number to use for one-time passcodes. The phone number should be in E.164 format
|
214
|
+
# The phone number to use for one-time passcodes. 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
215
|
# The type of this field is +String+.
|
213
216
|
# expiration_minutes::
|
214
217
|
# 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.
|
@@ -275,15 +278,16 @@ module Stytch
|
|
275
278
|
@connection = connection
|
276
279
|
end
|
277
280
|
|
278
|
-
# Send a
|
281
|
+
# Send a One-Time Passcode (OTP) to a User's WhatsApp. If you'd like to create a user and send them a passcode with one request, use our [log in or create](https://stytch.com/docs/api/whatsapp-login-or-create) endpoint.
|
279
282
|
#
|
280
283
|
# Note that sending another OTP code before the first has expired will invalidate the first code.
|
281
284
|
#
|
282
|
-
# ###
|
285
|
+
# ### Cost to send SMS OTP
|
286
|
+
# Before configuring SMS or WhatsApp OTPs, please review how Stytch [bills the costs of international OTPs](https://stytch.com/pricing) and understand how to protect your app against [toll fraud](https://stytch.com/docs/guides/passcodes/toll-fraud/overview).
|
283
287
|
#
|
284
|
-
#
|
288
|
+
# ### Add a phone number to an existing user
|
285
289
|
#
|
286
|
-
#
|
290
|
+
# This endpoint also allows you to add a new phone number to an existing Stytch User. Including a `user_id`, `session_token`, or `session_jwt` in your Send one-time passcode by WhatsApp request will add the new, unverified phone number to the existing Stytch User. Upon successful authentication, the phone number will be marked as verified.
|
287
291
|
#
|
288
292
|
# ### Next steps
|
289
293
|
#
|
@@ -291,7 +295,7 @@ module Stytch
|
|
291
295
|
#
|
292
296
|
# == Parameters:
|
293
297
|
# phone_number::
|
294
|
-
# The phone number to use for one-time passcodes. The phone number should be in E.164 format
|
298
|
+
# The phone number to use for one-time passcodes. 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
299
|
# The type of this field is +String+.
|
296
300
|
# expiration_minutes::
|
297
301
|
# 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.
|
@@ -355,13 +359,16 @@ module Stytch
|
|
355
359
|
|
356
360
|
# Send a one-time passcode (OTP) to a User's WhatsApp using their phone number. If the phone number is not associated with a User already, a User will be created.
|
357
361
|
#
|
362
|
+
# ### Cost to send SMS OTP
|
363
|
+
# Before configuring SMS or WhatsApp OTPs, please review how Stytch [bills the costs of international OTPs](https://stytch.com/pricing) and understand how to protect your app against [toll fraud](https://stytch.com/docs/guides/passcodes/toll-fraud/overview).
|
364
|
+
#
|
358
365
|
# ### Next steps
|
359
366
|
#
|
360
367
|
# Collect the OTP which was delivered to the User. Call [Authenticate OTP](https://stytch.com/docs/api/authenticate-otp) using the OTP `code` along with the `phone_id` found in the response as the `method_id`.
|
361
368
|
#
|
362
369
|
# == Parameters:
|
363
370
|
# phone_number::
|
364
|
-
# The phone number to use for one-time passcodes. The phone number should be in E.164 format
|
371
|
+
# The phone number to use for one-time passcodes. 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
372
|
# The type of this field is +String+.
|
366
373
|
# expiration_minutes::
|
367
374
|
# 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.
|
@@ -428,12 +435,10 @@ module Stytch
|
|
428
435
|
@connection = connection
|
429
436
|
end
|
430
437
|
|
431
|
-
# Send a
|
438
|
+
# Send a One-Time Passcode (OTP) to a User using their email. If you'd like to create a user and send them a passcode with one request, use our [log in or create endpoint](https://stytch.com/docs/api/log-in-or-create-user-by-email-otp).
|
432
439
|
#
|
433
440
|
# ### Add an email to an existing user
|
434
|
-
# This endpoint also allows you to add a new email to an existing Stytch User. Including a `user_id`, `session_token`, or `session_jwt` in
|
435
|
-
#
|
436
|
-
# Adding a new email to an existing Stytch User requires the User to be present and validate the email via OTP. This requirement is in place to prevent account takeover attacks.
|
441
|
+
# This endpoint also allows you to add a new email address to an existing Stytch User. Including a `user_id`, `session_token`, or `session_jwt` in your Send one-time passcode by email request will add the new, unverified email address to the existing Stytch User. Upon successful authentication, the email address will be marked as verified.
|
437
442
|
#
|
438
443
|
# ### Next steps
|
439
444
|
# Collect the OTP which was delivered to the user. Call [Authenticate OTP](https://stytch.com/docs/api/authenticate-otp) using the OTP `code` along with the `phone_id` found in the response as the `method_id`.
|
data/lib/stytch/passwords.rb
CHANGED
@@ -21,11 +21,13 @@ module Stytch
|
|
21
21
|
@sessions = Stytch::Passwords::Sessions.new(@connection)
|
22
22
|
end
|
23
23
|
|
24
|
-
# Create a new user with a password
|
24
|
+
# Create a new user with a password. If `session_duration_minutes` is specified, a new session will be started as well.
|
25
25
|
#
|
26
|
-
#
|
26
|
+
# If a user with this email already exists in your Stytch project, this endpoint will return a `duplicate_email` error. To add a password to an existing passwordless user, you'll need to either call the [Migrate password endpoint](https://stytch.com/docs/api/password-migrate) or prompt the user to complete one of our password reset flows.
|
27
27
|
#
|
28
|
-
# This endpoint will return an error if the password provided does not meet our strength requirements, which you can check beforehand
|
28
|
+
# This endpoint will return an error if the password provided does not meet our strength requirements, which you can check beforehand via the [Password strength check endpoint](https://stytch.com/docs/api/password-strength-check).
|
29
|
+
#
|
30
|
+
# When creating new Passwords users, it's good practice to enforce an email verification flow. We'd recommend checking out our [Email verification guide](https://stytch.com/docs/guides/passwords/email-verification/overview) for more information.
|
29
31
|
#
|
30
32
|
# == Parameters:
|
31
33
|
# email::
|
data/lib/stytch/users.rb
CHANGED
@@ -29,7 +29,7 @@ module Stytch
|
|
29
29
|
# Provided attributes help with fraud detection.
|
30
30
|
# The type of this field is nilable +Attributes+ (+object+).
|
31
31
|
# phone_number::
|
32
|
-
# The phone number to use for one-time passcodes. The phone number should be in E.164 format
|
32
|
+
# The phone number to use for one-time passcodes. 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.
|
33
33
|
# The type of this field is nilable +String+.
|
34
34
|
# create_user_as_pending::
|
35
35
|
# Flag for whether or not to save a user as pending vs active in Stytch. Defaults to false.
|
@@ -196,7 +196,7 @@ module Stytch
|
|
196
196
|
|
197
197
|
# Update a User's attributes.
|
198
198
|
#
|
199
|
-
# **Note:** In order to add a new email address or phone number to an existing User object, pass the new email address or phone number into the respective `/send` endpoint for the authentication method of your choice. If you specify the existing User's `user_id` while calling the `/send` endpoint, the new email address or phone number will be added to the existing User object
|
199
|
+
# **Note:** In order to add a new email address or phone number to an existing User object, pass the new email address or phone number into the respective `/send` endpoint for the authentication method of your choice. If you specify the existing User's `user_id` while calling the `/send` endpoint, the new, unverified email address or phone number will be added to the existing User object. Upon successful authentication, the email address or phone number will be marked as verified. We require this process to guard against an account takeover vulnerability.
|
200
200
|
#
|
201
201
|
# == Parameters:
|
202
202
|
# user_id::
|
@@ -254,6 +254,39 @@ module Stytch
|
|
254
254
|
put_request("/v1/users/#{user_id}", request)
|
255
255
|
end
|
256
256
|
|
257
|
+
# Exchange a user's email address or phone number for another.
|
258
|
+
#
|
259
|
+
# Must pass either an `email_address` or a `phone_number`.
|
260
|
+
#
|
261
|
+
# This endpoint only works if the user has exactly one factor. You are able to exchange the type of factor for another as well, i.e. exchange an `email_address` for a `phone_number`.
|
262
|
+
#
|
263
|
+
# Use this endpoint with caution as it performs an admin level action.
|
264
|
+
#
|
265
|
+
# == Parameters:
|
266
|
+
# user_id::
|
267
|
+
# The unique ID of a specific User.
|
268
|
+
# The type of this field is +String+.
|
269
|
+
# email_address::
|
270
|
+
# The email address to exchange to.
|
271
|
+
# The type of this field is nilable +String+.
|
272
|
+
# phone_number::
|
273
|
+
# The phone number to exchange to. The phone number should be in E.164 format (i.e. +1XXXXXXXXXX).
|
274
|
+
# The type of this field is nilable +String+.
|
275
|
+
#
|
276
|
+
# == Returns:
|
277
|
+
# An object with the following fields:
|
278
|
+
# request_id::
|
279
|
+
# 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.
|
280
|
+
# The type of this field is +String+.
|
281
|
+
# user_id::
|
282
|
+
# The unique ID of the affected User.
|
283
|
+
# The type of this field is +String+.
|
284
|
+
# user::
|
285
|
+
# 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.
|
286
|
+
# The type of this field is +User+ (+object+).
|
287
|
+
# status_code::
|
288
|
+
# 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.
|
289
|
+
# The type of this field is +Integer+.
|
257
290
|
def exchange_primary_factor(
|
258
291
|
user_id:,
|
259
292
|
email_address: nil,
|
data/lib/stytch/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stytch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- stytch
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|