Class: Stytch::MagicLinks::Email
- Inherits:
-
Object
- Object
- Stytch::MagicLinks::Email
- Includes:
- RequestHelper
- Defined in:
- lib/stytch/magic_links.rb
Instance Method Summary collapse
-
#initialize(connection) ⇒ Email
constructor
A new instance of Email.
-
#invite(email:, invite_template_id: nil, attributes: nil, name: nil, invite_magic_link_url: nil, invite_expiration_minutes: nil, locale: nil, trusted_metadata: nil, untrusted_metadata: nil) ⇒ Object
Create a User and send an invite Magic Link to the provided
email. -
#login_or_create(email:, login_magic_link_url: nil, signup_magic_link_url: nil, login_expiration_minutes: nil, signup_expiration_minutes: nil, login_template_id: nil, signup_template_id: nil, attributes: nil, create_user_as_pending: nil, code_challenge: nil, locale: nil) ⇒ Object
Send either a login or signup Magic Link to the User based on if the email is associated with a User already.
-
#revoke_invite(email:) ⇒ Object
Revoke a pending invite based on the
emailprovided. -
#send(email:, login_template_id: nil, attributes: nil, login_magic_link_url: nil, signup_magic_link_url: nil, login_expiration_minutes: nil, signup_expiration_minutes: nil, code_challenge: nil, user_id: nil, session_token: nil, session_jwt: nil, locale: nil, signup_template_id: nil) ⇒ Object
Send a magic link to an existing Stytch user using their email address.
Methods included from RequestHelper
#delete_request, #get_request, #post_request, #put_request, #request_with_query_params
Constructor Details
#initialize(connection) ⇒ Email
Returns a new instance of Email.
189 190 191 |
# File 'lib/stytch/magic_links.rb', line 189 def initialize(connection) @connection = connection end |
Instance Method Details
#invite(email:, invite_template_id: nil, attributes: nil, name: nil, invite_magic_link_url: nil, invite_expiration_minutes: nil, locale: nil, trusted_metadata: nil, untrusted_metadata: nil) ⇒ Object
Create a User and send an invite Magic Link to the provided email. The User will be created with a pending status until they click the Magic Link in the invite email.
Next steps
The User is emailed a Magic Link which redirects them to the provided redirect URL. Collect the token from the URL query parameters and call Authenticate Magic Link to complete authentication.
Parameters:
The email address of the User to send the invite Magic Link to. The type of this field is
String.- invite_template_id
Use a custom template for invite emails. By default, it will use your default email template. Templates can be added in the Stytch dashboard using our built-in customization options or custom HTML templates with type “Magic links - Invite”. The type of this field is nilable
String.- attributes
Provided attributes to help with fraud detection. These values are pulled and passed into Stytch endpoints by your application. The type of this field is nilable
Attributes(+object+).- name
The name of the user. Each field in the name object is optional. The type of this field is nilable
Name(+object+).- invite_magic_link_url
The URL the end user clicks from the Email Magic Link. This should be a URL that your app receives and parses and subsequently sends an API request to authenticate the Magic Link and log in the User. If this value is not passed, the default invite redirect URL that you set in your Dashboard is used. If you have not set a default sign-up redirect URL, an error is returned. The type of this field is nilable
String.- invite_expiration_minutes
Set the expiration for the email magic link, in minutes. By default, it expires in 1 hour. The minimum expiration is 5 minutes and the maximum is 7 days (10080 mins). The type of this field is nilable
Integer.- locale
Used to determine which language to use when sending the user this delivery method. Parameter is an IETF BCP 47 language tag, e.g.
"en".
Currently supported languages are English ("en"), Spanish ("es"), French ("fr") and Brazilian Portuguese ("pt-br"); if no value is provided, the copy defaults to English.
Request support for additional languages here!
The type of this field is nilable +InviteRequestLocale+ (string enum).
- trusted_metadata
The
trusted_metadatafield contains an arbitrary JSON object of application-specific data. See the Metadata reference for complete field behavior details. The type of this field is nilableobject.- untrusted_metadata
The
untrusted_metadatafield contains an arbitrary JSON object of application-specific data. Untrusted metadata can be edited by end users directly via the SDK, and cannot be used to store critical information. See the Metadata reference for complete field behavior details. The type of this field is nilableobject.
Returns:
An object with the following fields:
- request_id
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. The type of this field is
String.- user_id
The unique ID of the affected User. The type of this field is
String.- email_id
The unique ID of a specific email address. The type of this field is
String.- status_code
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. The type of this field is
Integer.
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
# File 'lib/stytch/magic_links.rb', line 446 def invite( email:, invite_template_id: nil, attributes: nil, name: nil, invite_magic_link_url: nil, invite_expiration_minutes: nil, locale: nil, trusted_metadata: nil, untrusted_metadata: nil ) headers = {} request = { email: email } request[:invite_template_id] = invite_template_id unless invite_template_id.nil? request[:attributes] = attributes unless attributes.nil? request[:name] = name unless name.nil? request[:invite_magic_link_url] = invite_magic_link_url unless invite_magic_link_url.nil? request[:invite_expiration_minutes] = invite_expiration_minutes unless invite_expiration_minutes.nil? request[:locale] = locale unless locale.nil? request[:trusted_metadata] = unless .nil? request[:untrusted_metadata] = unless .nil? post_request('/v1/magic_links/email/invite', request, headers) end |
#login_or_create(email:, login_magic_link_url: nil, signup_magic_link_url: nil, login_expiration_minutes: nil, signup_expiration_minutes: nil, login_template_id: nil, signup_template_id: nil, attributes: nil, create_user_as_pending: nil, code_challenge: nil, locale: nil) ⇒ Object
Send either a login or signup Magic Link to the User based on if the email is associated with a User already. A new or pending User will receive a signup Magic Link. An active User will receive a login Magic Link. For more information on how to control the status your Users are created in see the create_user_as_pending flag.
Next steps
The User is emailed a Magic Link which redirects them to the provided redirect URL. Collect the token from the URL query parameters and call Authenticate Magic Link to complete authentication.
Parameters:
The email address of the end user. The type of this field is
String.- login_magic_link_url
The URL the end user clicks from the login Email Magic Link. This should be a URL that your app receives and parses and subsequently send an API request to authenticate the Magic Link and log in the User. If this value is not passed, the default login redirect URL that you set in your Dashboard is used. If you have not set a default login redirect URL, an error is returned. The type of this field is nilable
String.- signup_magic_link_url
The URL the end user clicks from the sign-up Email Magic Link. This should be a URL that your app receives and parses and subsequently send an API request to authenticate the Magic Link and sign-up the User. If this value is not passed, the default sign-up redirect URL that you set in your Dashboard is used. If you have not set a default sign-up redirect URL, an error is returned. The type of this field is nilable
String.- login_expiration_minutes
Set the expiration for the login email magic link, in minutes. By default, it expires in 1 hour. The minimum expiration is 5 minutes and the maximum is 7 days (10080 mins). The type of this field is nilable
Integer.- signup_expiration_minutes
Set the expiration for the sign-up email magic link, in minutes. By default, it expires in 1 week. The minimum expiration is 5 minutes and the maximum is 7 days (10080 mins). The type of this field is nilable
Integer.- login_template_id
Use a custom template for login emails. By default, it will use your default email template. Templates can be added in the Stytch dashboard using our built-in customization options or custom HTML templates with type “Magic links - Login”. The type of this field is nilable
String.- signup_template_id
Use a custom template for sign-up emails. By default, it will use your default email template. Templates can be added in the Stytch dashboard using our built-in customization options or custom HTML templates with type “Magic links - Sign-up”. The type of this field is nilable
String.- attributes
Provided attributes to help with fraud detection. These values are pulled and passed into Stytch endpoints by your application. The type of this field is nilable
Attributes(+object+).- create_user_as_pending
Flag for whether or not to save a user as pending vs active in Stytch. Defaults to false. If true, users will be saved with status pending in Stytch's backend until authenticated. If false, users will be created as active. An example usage of a true flag would be to require users to verify their phone by entering the OTP code before creating an account for them. The type of this field is nilable
Boolean.- code_challenge
A base64url encoded SHA256 hash of a one time secret used to validate that the request starts and ends on the same device. The type of this field is nilable
String.- locale
Used to determine which language to use when sending the user this delivery method. Parameter is an IETF BCP 47 language tag, e.g.
"en".
Currently supported languages are English ("en"), Spanish ("es"), French ("fr") and Brazilian Portuguese ("pt-br"); if no value is provided, the copy defaults to English.
Request support for additional languages here!
The type of this field is nilable +LoginOrCreateRequestLocale+ (string enum).
Returns:
An object with the following fields:
- request_id
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. The type of this field is
String.- user_id
The unique ID of the affected User. The type of this field is
String.- email_id
The unique ID of a specific email address. The type of this field is
String.- user_created
In
login_or_createendpoints, this field indicates whether or not a User was just created. The type of this field isBoolean.- status_code
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. The type of this field is
Integer.
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/stytch/magic_links.rb', line 362 def login_or_create( email:, login_magic_link_url: nil, signup_magic_link_url: nil, login_expiration_minutes: nil, signup_expiration_minutes: nil, login_template_id: nil, signup_template_id: nil, attributes: nil, create_user_as_pending: nil, code_challenge: nil, locale: nil ) headers = {} request = { email: email } request[:login_magic_link_url] = login_magic_link_url unless login_magic_link_url.nil? request[:signup_magic_link_url] = signup_magic_link_url unless signup_magic_link_url.nil? request[:login_expiration_minutes] = login_expiration_minutes unless login_expiration_minutes.nil? request[:signup_expiration_minutes] = signup_expiration_minutes unless signup_expiration_minutes.nil? request[:login_template_id] = login_template_id unless login_template_id.nil? request[:signup_template_id] = signup_template_id unless signup_template_id.nil? request[:attributes] = attributes unless attributes.nil? request[:create_user_as_pending] = create_user_as_pending unless create_user_as_pending.nil? request[:code_challenge] = code_challenge unless code_challenge.nil? request[:locale] = locale unless locale.nil? post_request('/v1/magic_links/email/login_or_create', request, headers) end |
#revoke_invite(email:) ⇒ Object
Revoke a pending invite based on the email provided.
Parameters:
The email of the user. The type of this field is
String.
Returns:
An object with the following fields:
- request_id
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. The type of this field is
String.- status_code
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. The type of this field is
Integer.
488 489 490 491 492 493 494 495 496 497 |
# File 'lib/stytch/magic_links.rb', line 488 def revoke_invite( email: ) headers = {} request = { email: email } post_request('/v1/magic_links/email/revoke_invite', request, headers) end |
#send(email:, login_template_id: nil, attributes: nil, login_magic_link_url: nil, signup_magic_link_url: nil, login_expiration_minutes: nil, signup_expiration_minutes: nil, code_challenge: nil, user_id: nil, session_token: nil, session_jwt: nil, locale: nil, signup_template_id: nil) ⇒ Object
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.
Add an email to an existing user
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. If the user successfully authenticates within 5 minutes, the new email address will be marked as verified and remain permanently on the existing Stytch User. Otherwise, it will be removed from the User object, and any subsequent login requests using that email address will create a new User.
Next steps
The user is emailed a magic link which redirects them to the provided redirect URL. Collect the token from the URL query parameters, and call Authenticate magic link to complete authentication.
Parameters:
The email address of the User to send the Magic Link to. The type of this field is
String.- login_template_id
Use a custom template for login emails. By default, it will use your default email template. Templates can be added in the Stytch dashboard using our built-in customization options or custom HTML templates with type “Magic links - Login”. The type of this field is nilable
String.- attributes
Provided attributes to help with fraud detection. These values are pulled and passed into Stytch endpoints by your application. The type of this field is nilable
Attributes(+object+).- login_magic_link_url
The URL the end user clicks from the login Email Magic Link. This should be a URL that your app receives and parses and subsequently send an API request to authenticate the Magic Link and log in the User. If this value is not passed, the default login redirect URL that you set in your Dashboard is used. If you have not set a default login redirect URL, an error is returned. The type of this field is nilable
String.- signup_magic_link_url
The URL the end user clicks from the sign-up Email Magic Link. This should be a URL that your app receives and parses and subsequently send an API request to authenticate the Magic Link and sign-up the User. If this value is not passed, the default sign-up redirect URL that you set in your Dashboard is used. If you have not set a default sign-up redirect URL, an error is returned. The type of this field is nilable
String.- login_expiration_minutes
Set the expiration for the login email magic link, in minutes. By default, it expires in 1 hour. The minimum expiration is 5 minutes and the maximum is 7 days (10080 mins). The type of this field is nilable
Integer.- signup_expiration_minutes
Set the expiration for the sign-up email magic link, in minutes. By default, it expires in 1 week. The minimum expiration is 5 minutes and the maximum is 7 days (10080 mins). The type of this field is nilable
Integer.- code_challenge
A base64url encoded SHA256 hash of a one time secret used to validate that the request starts and ends on the same device. The type of this field is nilable
String.- user_id
The unique ID of a specific User. You may use an
external_idhere if one is set for the user. The type of this field is nilableString.- session_token
The
session_tokenof the user to associate the email with. The type of this field is nilableString.- session_jwt
The
session_jwtof the user to associate the email with. The type of this field is nilableString.- locale
Used to determine which language to use when sending the user this delivery method. Parameter is an IETF BCP 47 language tag, e.g.
"en".
Currently supported languages are English ("en"), Spanish ("es"), French ("fr") and Brazilian Portuguese ("pt-br"); if no value is provided, the copy defaults to English.
Request support for additional languages here!
The type of this field is nilable +SendRequestLocale+ (string enum).
- signup_template_id
Use a custom template for sign-up emails. By default, it will use your default email template. Templates can be added in the Stytch dashboard using our built-in customization options or custom HTML templates with type “Magic links - Sign-up”. The type of this field is nilable
String.
Returns:
An object with the following fields:
- request_id
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. The type of this field is
String.- user_id
The unique ID of the affected User. The type of this field is
String.- email_id
The unique ID of a specific email address. The type of this field is
String.- status_code
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. The type of this field is
Integer.
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/stytch/magic_links.rb', line 261 def send( email:, login_template_id: nil, attributes: nil, login_magic_link_url: nil, signup_magic_link_url: nil, login_expiration_minutes: nil, signup_expiration_minutes: nil, code_challenge: nil, user_id: nil, session_token: nil, session_jwt: nil, locale: nil, signup_template_id: nil ) headers = {} request = { email: email } request[:login_template_id] = login_template_id unless login_template_id.nil? request[:attributes] = attributes unless attributes.nil? request[:login_magic_link_url] = login_magic_link_url unless login_magic_link_url.nil? request[:signup_magic_link_url] = signup_magic_link_url unless signup_magic_link_url.nil? request[:login_expiration_minutes] = login_expiration_minutes unless login_expiration_minutes.nil? request[:signup_expiration_minutes] = signup_expiration_minutes unless signup_expiration_minutes.nil? request[:code_challenge] = code_challenge unless code_challenge.nil? request[:user_id] = user_id unless user_id.nil? request[:session_token] = session_token unless session_token.nil? request[:session_jwt] = session_jwt unless session_jwt.nil? request[:locale] = locale unless locale.nil? request[:signup_template_id] = signup_template_id unless signup_template_id.nil? post_request('/v1/magic_links/email/send', request, headers) end |