stytch 5.0.2 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/stytch/b2b_client.rb +7 -1
- data/lib/stytch/b2b_discovery.rb +243 -3
- data/lib/stytch/b2b_magic_links.rb +276 -1
- data/lib/stytch/b2b_oauth.rb +202 -0
- data/lib/stytch/b2b_organizations.rb +513 -48
- data/lib/stytch/b2b_otp.rb +72 -0
- data/lib/stytch/b2b_passwords.rb +453 -3
- data/lib/stytch/b2b_sessions.rb +192 -5
- data/lib/stytch/b2b_sso.rb +302 -8
- data/lib/stytch/client.rb +9 -9
- data/lib/stytch/crypto_wallets.rb +112 -13
- data/lib/stytch/errors.rb +16 -16
- data/lib/stytch/magic_links.rb +350 -56
- data/lib/stytch/oauth.rb +129 -22
- data/lib/stytch/otps.rb +454 -71
- data/lib/stytch/passwords.rb +513 -67
- data/lib/stytch/sessions.rb +152 -40
- data/lib/stytch/totps.rb +193 -13
- data/lib/stytch/users.rb +427 -96
- data/lib/stytch/version.rb +1 -1
- data/lib/stytch/webauthn.rb +156 -10
- data/lib/stytch.rb +1 -0
- metadata +4 -2
data/lib/stytch/otps.rb
CHANGED
@@ -1,209 +1,592 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# !!!
|
4
|
+
# WARNING: This file is autogenerated
|
5
|
+
# Only modify code within MANUAL() sections
|
6
|
+
# or your changes may be overwritten later!
|
7
|
+
# !!!
|
8
|
+
|
3
9
|
require_relative 'request_helper'
|
4
10
|
|
5
11
|
module Stytch
|
6
12
|
class OTPs
|
7
13
|
include Stytch::RequestHelper
|
8
|
-
|
9
14
|
attr_reader :sms, :whatsapp, :email
|
10
15
|
|
11
|
-
PATH = '/v1/otps'
|
12
|
-
|
13
16
|
def initialize(connection)
|
14
17
|
@connection = connection
|
15
18
|
|
16
|
-
@sms = Stytch::OTPs::
|
17
|
-
@whatsapp = Stytch::OTPs::
|
19
|
+
@sms = Stytch::OTPs::Sms.new(@connection)
|
20
|
+
@whatsapp = Stytch::OTPs::Whatsapp.new(@connection)
|
18
21
|
@email = Stytch::OTPs::Email.new(@connection)
|
19
22
|
end
|
20
23
|
|
24
|
+
# Authenticate a User given a `method_id` (the associated `email_id` or `phone_id`) and a `code`. This endpoint verifies that the code is valid, hasn't expired or been previously used, and any optional security settings such as IP match or user agent match are satisfied. A given `method_id` may only have a single active OTP code at any given time, if a User requests another OTP code before the first one has expired, the first one will be invalidated.
|
25
|
+
#
|
26
|
+
# == Parameters:
|
27
|
+
# method_id::
|
28
|
+
# The `email_id` or `phone_id` involved in the given authentication.
|
29
|
+
# The type of this field is +String+.
|
30
|
+
# code::
|
31
|
+
# The code to authenticate.
|
32
|
+
# The type of this field is +String+.
|
33
|
+
# attributes::
|
34
|
+
# Provided attributes help with fraud detection.
|
35
|
+
# The type of this field is nilable +Attributes+ (+object+).
|
36
|
+
# options::
|
37
|
+
# Specify optional security settings.
|
38
|
+
# The type of this field is nilable +Options+ (+object+).
|
39
|
+
# session_token::
|
40
|
+
# The `session_token` associated with a User's existing Session.
|
41
|
+
# The type of this field is nilable +String+.
|
42
|
+
# session_duration_minutes::
|
43
|
+
# Set the session lifetime to be this many minutes from now. This will start a new session if one doesn't already exist,
|
44
|
+
# returning both an opaque `session_token` and `session_jwt` for this session. Remember that the `session_jwt` will have a fixed lifetime of
|
45
|
+
# five minutes regardless of the underlying session duration, and will need to be refreshed over time.
|
46
|
+
#
|
47
|
+
# This value must be a minimum of 5 and a maximum of 527040 minutes (366 days).
|
48
|
+
#
|
49
|
+
# If a `session_token` or `session_jwt` is provided then a successful authentication will continue to extend the session this many minutes.
|
50
|
+
#
|
51
|
+
# If the `session_duration_minutes` parameter is not specified, a Stytch session will not be created.
|
52
|
+
# The type of this field is nilable +Integer+.
|
53
|
+
# session_jwt::
|
54
|
+
# The `session_jwt` associated with a User's existing Session.
|
55
|
+
# The type of this field is nilable +String+.
|
56
|
+
# session_custom_claims::
|
57
|
+
# Add a custom claims map to the Session being authenticated. Claims are only created if a Session is initialized by providing a value in `session_duration_minutes`. Claims will be included on the Session object and in the JWT. To update a key in an existing Session, supply a new value. To delete a key, supply a null value.
|
58
|
+
#
|
59
|
+
# Custom claims made with reserved claims ("iss", "sub", "aud", "exp", "nbf", "iat", "jti") will be ignored. Total custom claims size cannot exceed four kilobytes.
|
60
|
+
# The type of this field is nilable +object+.
|
61
|
+
#
|
62
|
+
# == Returns:
|
63
|
+
# An object with the following fields:
|
64
|
+
# request_id::
|
65
|
+
# 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.
|
66
|
+
# The type of this field is +String+.
|
67
|
+
# user_id::
|
68
|
+
# The unique ID of the affected User.
|
69
|
+
# The type of this field is +String+.
|
70
|
+
# method_id::
|
71
|
+
# The `email_id` or `phone_id` involved in the given authentication.
|
72
|
+
# The type of this field is +String+.
|
73
|
+
# session_token::
|
74
|
+
# A secret token for a given Stytch Session.
|
75
|
+
# The type of this field is +String+.
|
76
|
+
# session_jwt::
|
77
|
+
# The JSON Web Token (JWT) for a given Stytch Session.
|
78
|
+
# The type of this field is +String+.
|
79
|
+
# user::
|
80
|
+
# 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.
|
81
|
+
# The type of this field is +User+ (+object+).
|
82
|
+
# reset_sessions::
|
83
|
+
# Indicates if all other of the User's Sessions need to be reset. You should check this field if you aren't using Stytch's Session product. If you are using Stytch's Session product, we revoke the User's other sessions for you.
|
84
|
+
# The type of this field is +Boolean+.
|
85
|
+
# status_code::
|
86
|
+
# 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.
|
87
|
+
# The type of this field is +Integer+.
|
88
|
+
# session::
|
89
|
+
# If you initiate a Session, by including `session_duration_minutes` in your authenticate call, you'll receive a full Session object in the response.
|
90
|
+
#
|
91
|
+
# See [GET sessions](https://stytch.com/docs/api/session-get) for complete response fields.
|
92
|
+
#
|
93
|
+
# The type of this field is nilable +Session+ (+object+).
|
21
94
|
def authenticate(
|
22
95
|
method_id:,
|
23
96
|
code:,
|
24
|
-
attributes:
|
25
|
-
options:
|
97
|
+
attributes: nil,
|
98
|
+
options: nil,
|
26
99
|
session_token: nil,
|
27
|
-
session_jwt: nil,
|
28
100
|
session_duration_minutes: nil,
|
101
|
+
session_jwt: nil,
|
29
102
|
session_custom_claims: nil
|
30
103
|
)
|
31
104
|
request = {
|
32
105
|
method_id: method_id,
|
33
106
|
code: code
|
34
107
|
}
|
35
|
-
|
36
|
-
request[:
|
37
|
-
request[:options] = options if options != {}
|
108
|
+
request[:attributes] = attributes unless attributes.nil?
|
109
|
+
request[:options] = options unless options.nil?
|
38
110
|
request[:session_token] = session_token unless session_token.nil?
|
39
|
-
request[:session_jwt] = session_jwt unless session_jwt.nil?
|
40
111
|
request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
|
112
|
+
request[:session_jwt] = session_jwt unless session_jwt.nil?
|
41
113
|
request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
|
42
114
|
|
43
|
-
post_request(
|
115
|
+
post_request('/v1/otps/authenticate', request)
|
44
116
|
end
|
45
117
|
|
46
|
-
class
|
118
|
+
class Sms
|
47
119
|
include Stytch::RequestHelper
|
48
120
|
|
49
|
-
PATH = "#{Stytch::OTPs::PATH}/sms"
|
50
|
-
|
51
121
|
def initialize(connection)
|
52
122
|
@connection = connection
|
53
123
|
end
|
54
124
|
|
125
|
+
# Send a one-time passcode (OTP) to a user's phone number. 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/log-in-or-create-user-by-sms) endpoint.
|
126
|
+
#
|
127
|
+
# Note that sending another OTP code before the first has expired will invalidate the first code.
|
128
|
+
#
|
129
|
+
# ### Add a phone number to an existing user
|
130
|
+
#
|
131
|
+
# 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 the request will add the phone number to the pre-existing Stytch User upon successful authentication.
|
132
|
+
#
|
133
|
+
# Adding a new phone number to an existing Stytch User requires the user to be present and validate the phone number via OTP. This requirement is in place to prevent account takeover attacks.
|
134
|
+
#
|
135
|
+
# ### Next steps
|
136
|
+
#
|
137
|
+
# 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`.
|
138
|
+
#
|
139
|
+
# == Parameters:
|
140
|
+
# phone_number::
|
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
|
+
# The type of this field is +String+.
|
143
|
+
# expiration_minutes::
|
144
|
+
# Set the expiration for the Magic Link `token` in minutes. By default, it expires in 1 hour. The minimum expiration is 5 minutes and the maximum is 7 days (10080 mins).
|
145
|
+
# The type of this field is nilable +Integer+.
|
146
|
+
# attributes::
|
147
|
+
# Provided attributes help with fraud detection.
|
148
|
+
# The type of this field is nilable +Attributes+ (+object+).
|
149
|
+
# locale::
|
150
|
+
# 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"`.
|
151
|
+
#
|
152
|
+
# Currently supported languages are English (`"en"`), Spanish (`"es"`), and Brazilian Portuguese (`"pt-br"`); if no value is provided, the copy defaults to English.
|
153
|
+
#
|
154
|
+
# Request support for additional languages [here](https://docs.google.com/forms/d/e/1FAIpQLScZSpAu_m2AmLXRT3F3kap-s_mcV6UTBitYn6CdyWP0-o7YjQ/viewform?usp=sf_link")!
|
155
|
+
#
|
156
|
+
# The type of this field is nilable +SendRequestLocale+ (string enum).
|
157
|
+
# user_id::
|
158
|
+
# The unique ID of a specific User.
|
159
|
+
# The type of this field is nilable +String+.
|
160
|
+
# session_token::
|
161
|
+
# The `session_token` associated with a User's existing Session.
|
162
|
+
# The type of this field is nilable +String+.
|
163
|
+
# session_jwt::
|
164
|
+
# The `session_jwt` associated with a User's existing Session.
|
165
|
+
# The type of this field is nilable +String+.
|
166
|
+
#
|
167
|
+
# == Returns:
|
168
|
+
# An object with the following fields:
|
169
|
+
# request_id::
|
170
|
+
# 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.
|
171
|
+
# The type of this field is +String+.
|
172
|
+
# user_id::
|
173
|
+
# The unique ID of the affected User.
|
174
|
+
# The type of this field is +String+.
|
175
|
+
# phone_id::
|
176
|
+
# The unique ID for the phone number.
|
177
|
+
# The type of this field is +String+.
|
178
|
+
# status_code::
|
179
|
+
# 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.
|
180
|
+
# The type of this field is +Integer+.
|
55
181
|
def send(
|
56
182
|
phone_number:,
|
57
183
|
expiration_minutes: nil,
|
58
|
-
attributes:
|
184
|
+
attributes: nil,
|
185
|
+
locale: nil,
|
59
186
|
user_id: nil,
|
60
187
|
session_token: nil,
|
61
|
-
session_jwt: nil
|
62
|
-
locale: nil
|
188
|
+
session_jwt: nil
|
63
189
|
)
|
64
190
|
request = {
|
65
|
-
phone_number: phone_number
|
66
|
-
expiration_minutes: expiration_minutes
|
191
|
+
phone_number: phone_number
|
67
192
|
}
|
68
|
-
|
69
|
-
request[:attributes] = attributes
|
193
|
+
request[:expiration_minutes] = expiration_minutes unless expiration_minutes.nil?
|
194
|
+
request[:attributes] = attributes unless attributes.nil?
|
195
|
+
request[:locale] = locale unless locale.nil?
|
70
196
|
request[:user_id] = user_id unless user_id.nil?
|
71
197
|
request[:session_token] = session_token unless session_token.nil?
|
72
198
|
request[:session_jwt] = session_jwt unless session_jwt.nil?
|
73
|
-
request[:locale] = locale unless locale.nil?
|
74
199
|
|
75
|
-
post_request(
|
200
|
+
post_request('/v1/otps/sms/send', request)
|
76
201
|
end
|
77
202
|
|
203
|
+
# 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
|
+
# ### Next steps
|
206
|
+
#
|
207
|
+
# 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
|
+
#
|
209
|
+
# == Parameters:
|
210
|
+
# phone_number::
|
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
|
+
# The type of this field is +String+.
|
213
|
+
# expiration_minutes::
|
214
|
+
# Set the expiration for the Magic Link `token` in minutes. By default, it expires in 1 hour. The minimum expiration is 5 minutes and the maximum is 7 days (10080 mins).
|
215
|
+
# The type of this field is nilable +Integer+.
|
216
|
+
# attributes::
|
217
|
+
# Provided attributes help with fraud detection.
|
218
|
+
# The type of this field is nilable +Attributes+ (+object+).
|
219
|
+
# create_user_as_pending::
|
220
|
+
# Flag for whether or not to save a user as pending vs active in Stytch. Defaults to false.
|
221
|
+
# If true, users will be saved with status pending in Stytch's backend until authenticated.
|
222
|
+
# If false, users will be created as active. An example usage of
|
223
|
+
# a true flag would be to require users to verify their phone by entering the OTP code before creating
|
224
|
+
# an account for them.
|
225
|
+
# The type of this field is nilable +Boolean+.
|
226
|
+
# locale::
|
227
|
+
# 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"`.
|
228
|
+
#
|
229
|
+
# Currently supported languages are English (`"en"`), Spanish (`"es"`), and Brazilian Portuguese (`"pt-br"`); if no value is provided, the copy defaults to English.
|
230
|
+
#
|
231
|
+
# Request support for additional languages [here](https://docs.google.com/forms/d/e/1FAIpQLScZSpAu_m2AmLXRT3F3kap-s_mcV6UTBitYn6CdyWP0-o7YjQ/viewform?usp=sf_link")!
|
232
|
+
#
|
233
|
+
# The type of this field is nilable +LoginOrCreateRequestLocale+ (string enum).
|
234
|
+
#
|
235
|
+
# == Returns:
|
236
|
+
# An object with the following fields:
|
237
|
+
# request_id::
|
238
|
+
# 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.
|
239
|
+
# The type of this field is +String+.
|
240
|
+
# user_id::
|
241
|
+
# The unique ID of the affected User.
|
242
|
+
# The type of this field is +String+.
|
243
|
+
# phone_id::
|
244
|
+
# The unique ID for the phone number.
|
245
|
+
# The type of this field is +String+.
|
246
|
+
# user_created::
|
247
|
+
# In `login_or_create` endpoints, this field indicates whether or not a User was just created.
|
248
|
+
# The type of this field is +Boolean+.
|
249
|
+
# status_code::
|
250
|
+
# 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.
|
251
|
+
# The type of this field is +Integer+.
|
78
252
|
def login_or_create(
|
79
253
|
phone_number:,
|
80
254
|
expiration_minutes: nil,
|
81
|
-
attributes:
|
82
|
-
create_user_as_pending:
|
255
|
+
attributes: nil,
|
256
|
+
create_user_as_pending: nil,
|
83
257
|
locale: nil
|
84
258
|
)
|
85
259
|
request = {
|
86
|
-
phone_number: phone_number
|
87
|
-
expiration_minutes: expiration_minutes,
|
88
|
-
create_user_as_pending: create_user_as_pending
|
260
|
+
phone_number: phone_number
|
89
261
|
}
|
90
|
-
|
91
|
-
request[:attributes] = attributes
|
262
|
+
request[:expiration_minutes] = expiration_minutes unless expiration_minutes.nil?
|
263
|
+
request[:attributes] = attributes unless attributes.nil?
|
264
|
+
request[:create_user_as_pending] = create_user_as_pending unless create_user_as_pending.nil?
|
92
265
|
request[:locale] = locale unless locale.nil?
|
93
266
|
|
94
|
-
post_request(
|
267
|
+
post_request('/v1/otps/sms/login_or_create', request)
|
95
268
|
end
|
96
269
|
end
|
97
270
|
|
98
|
-
class
|
271
|
+
class Whatsapp
|
99
272
|
include Stytch::RequestHelper
|
100
273
|
|
101
|
-
PATH = "#{Stytch::OTPs::PATH}/whatsapp"
|
102
|
-
|
103
274
|
def initialize(connection)
|
104
275
|
@connection = connection
|
105
276
|
end
|
106
277
|
|
278
|
+
# 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
|
+
#
|
280
|
+
# Note that sending another OTP code before the first has expired will invalidate the first code.
|
281
|
+
#
|
282
|
+
# ### Add a phone number to an existing user
|
283
|
+
#
|
284
|
+
# 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 the request will add the phone number to the pre-existing Stytch User upon successful authentication.
|
285
|
+
#
|
286
|
+
# Adding a new phone number to an existing Stytch User requires the user to be present and validate the phone number via OTP. This requirement is in place to prevent account takeover attacks.
|
287
|
+
#
|
288
|
+
# ### Next steps
|
289
|
+
#
|
290
|
+
# 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`.
|
291
|
+
#
|
292
|
+
# == Parameters:
|
293
|
+
# phone_number::
|
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
|
+
# The type of this field is +String+.
|
296
|
+
# expiration_minutes::
|
297
|
+
# Set the expiration for the Magic Link `token` in minutes. By default, it expires in 1 hour. The minimum expiration is 5 minutes and the maximum is 7 days (10080 mins).
|
298
|
+
# The type of this field is nilable +Integer+.
|
299
|
+
# attributes::
|
300
|
+
# Provided attributes help with fraud detection.
|
301
|
+
# The type of this field is nilable +Attributes+ (+object+).
|
302
|
+
# locale::
|
303
|
+
# 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"`.
|
304
|
+
#
|
305
|
+
# Currently supported languages are English (`"en"`), Spanish (`"es"`), and Brazilian Portuguese (`"pt-br"`); if no value is provided, the copy defaults to English.
|
306
|
+
#
|
307
|
+
# Request support for additional languages [here](https://docs.google.com/forms/d/e/1FAIpQLScZSpAu_m2AmLXRT3F3kap-s_mcV6UTBitYn6CdyWP0-o7YjQ/viewform?usp=sf_link")!
|
308
|
+
#
|
309
|
+
# The type of this field is nilable +SendRequestLocale+ (string enum).
|
310
|
+
# user_id::
|
311
|
+
# The unique ID of a specific User.
|
312
|
+
# The type of this field is nilable +String+.
|
313
|
+
# session_token::
|
314
|
+
# The `session_token` associated with a User's existing Session.
|
315
|
+
# The type of this field is nilable +String+.
|
316
|
+
# session_jwt::
|
317
|
+
# The `session_jwt` associated with a User's existing Session.
|
318
|
+
# The type of this field is nilable +String+.
|
319
|
+
#
|
320
|
+
# == Returns:
|
321
|
+
# An object with the following fields:
|
322
|
+
# request_id::
|
323
|
+
# 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.
|
324
|
+
# The type of this field is +String+.
|
325
|
+
# user_id::
|
326
|
+
# The unique ID of the affected User.
|
327
|
+
# The type of this field is +String+.
|
328
|
+
# phone_id::
|
329
|
+
# The unique ID for the phone number.
|
330
|
+
# The type of this field is +String+.
|
331
|
+
# status_code::
|
332
|
+
# 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.
|
333
|
+
# The type of this field is +Integer+.
|
107
334
|
def send(
|
108
335
|
phone_number:,
|
109
336
|
expiration_minutes: nil,
|
110
|
-
attributes:
|
337
|
+
attributes: nil,
|
338
|
+
locale: nil,
|
111
339
|
user_id: nil,
|
112
340
|
session_token: nil,
|
113
|
-
session_jwt: nil
|
114
|
-
locale: nil
|
341
|
+
session_jwt: nil
|
115
342
|
)
|
116
343
|
request = {
|
117
|
-
phone_number: phone_number
|
118
|
-
expiration_minutes: expiration_minutes
|
344
|
+
phone_number: phone_number
|
119
345
|
}
|
120
|
-
|
121
|
-
request[:attributes] = attributes
|
346
|
+
request[:expiration_minutes] = expiration_minutes unless expiration_minutes.nil?
|
347
|
+
request[:attributes] = attributes unless attributes.nil?
|
348
|
+
request[:locale] = locale unless locale.nil?
|
122
349
|
request[:user_id] = user_id unless user_id.nil?
|
123
350
|
request[:session_token] = session_token unless session_token.nil?
|
124
351
|
request[:session_jwt] = session_jwt unless session_jwt.nil?
|
125
|
-
request[:locale] = locale unless locale.nil?
|
126
352
|
|
127
|
-
post_request(
|
353
|
+
post_request('/v1/otps/whatsapp/send', request)
|
128
354
|
end
|
129
355
|
|
356
|
+
# 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
|
+
#
|
358
|
+
# ### Next steps
|
359
|
+
#
|
360
|
+
# 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
|
+
#
|
362
|
+
# == Parameters:
|
363
|
+
# phone_number::
|
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
|
+
# The type of this field is +String+.
|
366
|
+
# expiration_minutes::
|
367
|
+
# Set the expiration for the Magic Link `token` in minutes. By default, it expires in 1 hour. The minimum expiration is 5 minutes and the maximum is 7 days (10080 mins).
|
368
|
+
# The type of this field is nilable +Integer+.
|
369
|
+
# attributes::
|
370
|
+
# Provided attributes help with fraud detection.
|
371
|
+
# The type of this field is nilable +Attributes+ (+object+).
|
372
|
+
# create_user_as_pending::
|
373
|
+
# Flag for whether or not to save a user as pending vs active in Stytch. Defaults to false.
|
374
|
+
# If true, users will be saved with status pending in Stytch's backend until authenticated.
|
375
|
+
# If false, users will be created as active. An example usage of
|
376
|
+
# a true flag would be to require users to verify their phone by entering the OTP code before creating
|
377
|
+
# an account for them.
|
378
|
+
# The type of this field is nilable +Boolean+.
|
379
|
+
# locale::
|
380
|
+
# Used to determine which language to use when sending the user this delivery method. Parameter is a [IETF BCP 47 language tag](https://www.w3.org/International/articles/language-tags/), e.g. `"en"`.
|
381
|
+
#
|
382
|
+
# Currently supported languages are English (`"en"`), Spanish (`"es"`), and Brazilian Portuguese (`"pt-br"`); if no value is provided, the copy defaults to English.
|
383
|
+
#
|
384
|
+
# Request support for additional languages [here](https://docs.google.com/forms/d/e/1FAIpQLScZSpAu_m2AmLXRT3F3kap-s_mcV6UTBitYn6CdyWP0-o7YjQ/viewform?usp=sf_link")!
|
385
|
+
#
|
386
|
+
# The type of this field is nilable +LoginOrCreateRequestLocale+ (string enum).
|
387
|
+
#
|
388
|
+
# == Returns:
|
389
|
+
# An object with the following fields:
|
390
|
+
# request_id::
|
391
|
+
# 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.
|
392
|
+
# The type of this field is +String+.
|
393
|
+
# user_id::
|
394
|
+
# The unique ID of the affected User.
|
395
|
+
# The type of this field is +String+.
|
396
|
+
# phone_id::
|
397
|
+
# The unique ID for the phone number.
|
398
|
+
# The type of this field is +String+.
|
399
|
+
# user_created::
|
400
|
+
# In `login_or_create` endpoints, this field indicates whether or not a User was just created.
|
401
|
+
# The type of this field is +Boolean+.
|
402
|
+
# status_code::
|
403
|
+
# 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.
|
404
|
+
# The type of this field is +Integer+.
|
130
405
|
def login_or_create(
|
131
406
|
phone_number:,
|
132
407
|
expiration_minutes: nil,
|
133
|
-
attributes:
|
134
|
-
create_user_as_pending:
|
408
|
+
attributes: nil,
|
409
|
+
create_user_as_pending: nil,
|
135
410
|
locale: nil
|
136
411
|
)
|
137
412
|
request = {
|
138
|
-
phone_number: phone_number
|
139
|
-
expiration_minutes: expiration_minutes,
|
140
|
-
create_user_as_pending: create_user_as_pending
|
413
|
+
phone_number: phone_number
|
141
414
|
}
|
142
|
-
|
143
|
-
request[:attributes] = attributes
|
415
|
+
request[:expiration_minutes] = expiration_minutes unless expiration_minutes.nil?
|
416
|
+
request[:attributes] = attributes unless attributes.nil?
|
417
|
+
request[:create_user_as_pending] = create_user_as_pending unless create_user_as_pending.nil?
|
144
418
|
request[:locale] = locale unless locale.nil?
|
145
419
|
|
146
|
-
post_request(
|
420
|
+
post_request('/v1/otps/whatsapp/login_or_create', request)
|
147
421
|
end
|
148
422
|
end
|
149
423
|
|
150
424
|
class Email
|
151
425
|
include Stytch::RequestHelper
|
152
426
|
|
153
|
-
PATH = "#{Stytch::OTPs::PATH}/email"
|
154
|
-
|
155
427
|
def initialize(connection)
|
156
428
|
@connection = connection
|
157
429
|
end
|
158
430
|
|
431
|
+
# 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
|
+
#
|
433
|
+
# ### 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 the request will add the email to the pre-existing Stytch User upon successful authentication.
|
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.
|
437
|
+
#
|
438
|
+
# ### Next steps
|
439
|
+
# 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`.
|
440
|
+
#
|
441
|
+
# == Parameters:
|
442
|
+
# email::
|
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
|
+
# The type of this field is +String+.
|
445
|
+
# expiration_minutes::
|
446
|
+
# Set the expiration for the Magic Link `token` in minutes. By default, it expires in 1 hour. The minimum expiration is 5 minutes and the maximum is 7 days (10080 mins).
|
447
|
+
# The type of this field is nilable +Integer+.
|
448
|
+
# attributes::
|
449
|
+
# Provided attributes help with fraud detection.
|
450
|
+
# The type of this field is nilable +Attributes+ (+object+).
|
451
|
+
# locale::
|
452
|
+
# 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"`.
|
453
|
+
#
|
454
|
+
# Currently supported languages are English (`"en"`), Spanish (`"es"`), and Brazilian Portuguese (`"pt-br"`); if no value is provided, the copy defaults to English.
|
455
|
+
#
|
456
|
+
# Request support for additional languages [here](https://docs.google.com/forms/d/e/1FAIpQLScZSpAu_m2AmLXRT3F3kap-s_mcV6UTBitYn6CdyWP0-o7YjQ/viewform?usp=sf_link")!
|
457
|
+
#
|
458
|
+
# The type of this field is nilable +SendRequestLocale+ (string enum).
|
459
|
+
# user_id::
|
460
|
+
# The unique ID of a specific User.
|
461
|
+
# The type of this field is nilable +String+.
|
462
|
+
# session_token::
|
463
|
+
# The `session_token` associated with a User's existing Session.
|
464
|
+
# The type of this field is nilable +String+.
|
465
|
+
# session_jwt::
|
466
|
+
# The `session_jwt` associated with a User's existing Session.
|
467
|
+
# The type of this field is nilable +String+.
|
468
|
+
# login_template_id::
|
469
|
+
# Use a custom template for login emails. By default, it will use your default email template. The template must be a template using our built-in customizations or a custom HTML email for Magic links - Login.
|
470
|
+
# The type of this field is nilable +String+.
|
471
|
+
# signup_template_id::
|
472
|
+
# Use a custom template for sign-up emails. By default, it will use your default email template. The template must be a template using our built-in customizations or a custom HTML email for Magic links - Sign-up.
|
473
|
+
# The type of this field is nilable +String+.
|
474
|
+
#
|
475
|
+
# == Returns:
|
476
|
+
# An object with the following fields:
|
477
|
+
# request_id::
|
478
|
+
# 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.
|
479
|
+
# The type of this field is +String+.
|
480
|
+
# user_id::
|
481
|
+
# The unique ID of the affected User.
|
482
|
+
# The type of this field is +String+.
|
483
|
+
# email_id::
|
484
|
+
# The unique ID of a specific email address.
|
485
|
+
# The type of this field is +String+.
|
486
|
+
# status_code::
|
487
|
+
# 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.
|
488
|
+
# The type of this field is +Integer+.
|
159
489
|
def send(
|
160
490
|
email:,
|
161
491
|
expiration_minutes: nil,
|
162
|
-
attributes:
|
492
|
+
attributes: nil,
|
493
|
+
locale: nil,
|
163
494
|
user_id: nil,
|
164
495
|
session_token: nil,
|
165
496
|
session_jwt: nil,
|
166
|
-
locale: nil,
|
167
497
|
login_template_id: nil,
|
168
498
|
signup_template_id: nil
|
169
499
|
)
|
170
500
|
request = {
|
171
|
-
email: email
|
172
|
-
expiration_minutes: expiration_minutes
|
501
|
+
email: email
|
173
502
|
}
|
174
|
-
|
175
|
-
request[:attributes] = attributes
|
503
|
+
request[:expiration_minutes] = expiration_minutes unless expiration_minutes.nil?
|
504
|
+
request[:attributes] = attributes unless attributes.nil?
|
505
|
+
request[:locale] = locale unless locale.nil?
|
176
506
|
request[:user_id] = user_id unless user_id.nil?
|
177
507
|
request[:session_token] = session_token unless session_token.nil?
|
178
508
|
request[:session_jwt] = session_jwt unless session_jwt.nil?
|
179
|
-
request[:locale] = locale unless locale.nil?
|
180
509
|
request[:login_template_id] = login_template_id unless login_template_id.nil?
|
181
510
|
request[:signup_template_id] = signup_template_id unless signup_template_id.nil?
|
182
511
|
|
183
|
-
post_request(
|
512
|
+
post_request('/v1/otps/email/send', request)
|
184
513
|
end
|
185
514
|
|
515
|
+
# Send a one-time passcode (OTP) to a User using their email. If the email is not associated with a User already, a User will be created.
|
516
|
+
#
|
517
|
+
# ### Next steps
|
518
|
+
#
|
519
|
+
# 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`.
|
520
|
+
#
|
521
|
+
# == Parameters:
|
522
|
+
# email::
|
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
|
+
# The type of this field is +String+.
|
525
|
+
# expiration_minutes::
|
526
|
+
# Set the expiration for the Magic Link `token` in minutes. By default, it expires in 1 hour. The minimum expiration is 5 minutes and the maximum is 7 days (10080 mins).
|
527
|
+
# The type of this field is nilable +Integer+.
|
528
|
+
# attributes::
|
529
|
+
# Provided attributes help with fraud detection.
|
530
|
+
# The type of this field is nilable +Attributes+ (+object+).
|
531
|
+
# create_user_as_pending::
|
532
|
+
# Flag for whether or not to save a user as pending vs active in Stytch. Defaults to false.
|
533
|
+
# If true, users will be saved with status pending in Stytch's backend until authenticated.
|
534
|
+
# If false, users will be created as active. An example usage of
|
535
|
+
# a true flag would be to require users to verify their phone by entering the OTP code before creating
|
536
|
+
# an account for them.
|
537
|
+
# The type of this field is nilable +Boolean+.
|
538
|
+
# locale::
|
539
|
+
# 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"`.
|
540
|
+
#
|
541
|
+
# Currently supported languages are English (`"en"`), Spanish (`"es"`), and Brazilian Portuguese (`"pt-br"`); if no value is provided, the copy defaults to English.
|
542
|
+
#
|
543
|
+
# Request support for additional languages [here](https://docs.google.com/forms/d/e/1FAIpQLScZSpAu_m2AmLXRT3F3kap-s_mcV6UTBitYn6CdyWP0-o7YjQ/viewform?usp=sf_link")!
|
544
|
+
#
|
545
|
+
# The type of this field is nilable +LoginOrCreateRequestLocale+ (string enum).
|
546
|
+
# login_template_id::
|
547
|
+
# Use a custom template for login emails. By default, it will use your default email template. The template must be a template using our built-in customizations or a custom HTML email for Magic links - Login.
|
548
|
+
# The type of this field is nilable +String+.
|
549
|
+
# signup_template_id::
|
550
|
+
# Use a custom template for sign-up emails. By default, it will use your default email template. The template must be a template using our built-in customizations or a custom HTML email for Magic links - Sign-up.
|
551
|
+
# The type of this field is nilable +String+.
|
552
|
+
#
|
553
|
+
# == Returns:
|
554
|
+
# An object with the following fields:
|
555
|
+
# request_id::
|
556
|
+
# 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.
|
557
|
+
# The type of this field is +String+.
|
558
|
+
# user_id::
|
559
|
+
# The unique ID of the affected User.
|
560
|
+
# The type of this field is +String+.
|
561
|
+
# email_id::
|
562
|
+
# The unique ID of a specific email address.
|
563
|
+
# The type of this field is +String+.
|
564
|
+
# user_created::
|
565
|
+
# In `login_or_create` endpoints, this field indicates whether or not a User was just created.
|
566
|
+
# The type of this field is +Boolean+.
|
567
|
+
# status_code::
|
568
|
+
# 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.
|
569
|
+
# The type of this field is +Integer+.
|
186
570
|
def login_or_create(
|
187
571
|
email:,
|
188
572
|
expiration_minutes: nil,
|
189
|
-
attributes:
|
190
|
-
create_user_as_pending:
|
573
|
+
attributes: nil,
|
574
|
+
create_user_as_pending: nil,
|
191
575
|
locale: nil,
|
192
576
|
login_template_id: nil,
|
193
577
|
signup_template_id: nil
|
194
578
|
)
|
195
579
|
request = {
|
196
|
-
email: email
|
197
|
-
expiration_minutes: expiration_minutes,
|
198
|
-
create_user_as_pending: create_user_as_pending
|
580
|
+
email: email
|
199
581
|
}
|
200
|
-
|
201
|
-
request[:attributes] = attributes
|
582
|
+
request[:expiration_minutes] = expiration_minutes unless expiration_minutes.nil?
|
583
|
+
request[:attributes] = attributes unless attributes.nil?
|
584
|
+
request[:create_user_as_pending] = create_user_as_pending unless create_user_as_pending.nil?
|
202
585
|
request[:locale] = locale unless locale.nil?
|
203
586
|
request[:login_template_id] = login_template_id unless login_template_id.nil?
|
204
587
|
request[:signup_template_id] = signup_template_id unless signup_template_id.nil?
|
205
588
|
|
206
|
-
post_request(
|
589
|
+
post_request('/v1/otps/email/login_or_create', request)
|
207
590
|
end
|
208
591
|
end
|
209
592
|
end
|