Class: StytchB2B::MagicLinks::Email

Inherits:
Object
  • Object
show all
Includes:
Stytch::RequestHelper
Defined in:
lib/stytch/b2b_magic_links.rb

Defined Under Namespace

Classes: Discovery, InviteRequestOptions

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Stytch::RequestHelper

#delete_request, #get_request, #post_request, #put_request, #request_with_query_params

Constructor Details

#initialize(connection) ⇒ Email

Returns a new instance of Email.



186
187
188
189
190
# File 'lib/stytch/b2b_magic_links.rb', line 186

def initialize(connection)
  @connection = connection

  @discovery = StytchB2B::MagicLinks::Email::Discovery.new(@connection)
end

Instance Attribute Details

#discoveryObject (readonly)

Returns the value of attribute discovery.



184
185
186
# File 'lib/stytch/b2b_magic_links.rb', line 184

def discovery
  @discovery
end

Instance Method Details

#invite(organization_id:, email_address:, invite_redirect_url: nil, invited_by_member_id: nil, name: nil, trusted_metadata: nil, untrusted_metadata: nil, invite_template_id: nil, locale: nil, roles: nil, invite_expiration_minutes: nil, method_options: nil) ⇒ Object

Send an invite email to a new Member to join an Organization. The Member will be created with an ‘invited` status until they successfully authenticate. Sending invites to `pending` Members will update their status to `invited`. Sending invites to already `active` Members will return an error.

The magic link invite will be valid for 1 week.

## Revoke an invite

To revoke an existing invite, use the [Delete Member](stytch.com/docs/b2b/api/delete-member) endpoint. This will both delete the invited Member from the target Organization and revoke all existing invite emails.

Parameters:

organization_id

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. You may also use the organization_slug or organization_external_id here as a convenience. The type of this field is String.

email_address

The email address of the Member. The type of this field is String.

invite_redirect_url

The URL that the Member clicks from the invite Email Magic Link. This URL should be an endpoint in the backend server that verifies the request by querying Stytch’s authenticate endpoint and finishes the invite flow. 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 `invite_redirect_url`, an error is returned. The type of this field is nilable String.

invited_by_member_id

The ‘member_id` of the Member who sends the invite. The type of this field is nilable String.

name

The name of the Member. The type of this field is nilable String.

trusted_metadata

An arbitrary JSON object for storing application-specific data or identity-provider-specific data. The type of this field is nilable object.

untrusted_metadata

An arbitrary JSON object of application-specific data. These fields can be edited directly by the frontend SDK, and should not be used to store critical information. See the [Metadata resource](stytch.com/docs/b2b/api/metadata) for complete field behavior details. The type of this field is nilable object.

invite_template_id

Use a custom template for invite 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 - Invite. 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 a [IETF BCP 47 language tag](www.w3.org/International/articles/language-tags/), 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](docs.google.com/forms/d/e/1FAIpQLScZSpAu_m2AmLXRT3F3kap-s_mcV6UTBitYn6CdyWP0-o7YjQ/viewform?usp=sf_link“)!

The type of this field is nilable +InviteRequestLocale+ (string enum).
roles

Roles to explicitly assign to this Member. See the [RBAC guide](stytch.com/docs/b2b/guides/rbac/role-assignment)

for more information about role assignment.

The type of this field is nilable list of String.

invite_expiration_minutes

The expiration time, in minutes, for an invite email. If not accepted within this time frame, the invite will need to be resent. Defaults to 10080 (1 week) with a minimum of 5 and a maximum of 10080. The type of this field is nilable Integer.

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.

member_id

Globally unique UUID that identifies a specific Member. The type of this field is String.

member

The [Member object](stytch.com/docs/b2b/api/member-object) The type of this field is Member (object).

organization

The [Organization object](stytch.com/docs/b2b/api/organization-object). The type of this field is Organization (object).

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.

Method Options:

This method supports an optional StytchB2B::MagicLinks::Email::InviteRequestOptions object which will modify the headers sent in the HTTP request.



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
392
393
# File 'lib/stytch/b2b_magic_links.rb', line 362

def invite(
  organization_id:,
  email_address:,
  invite_redirect_url: nil,
  invited_by_member_id: nil,
  name: nil,
  trusted_metadata: nil,
  untrusted_metadata: nil,
  invite_template_id: nil,
  locale: nil,
  roles: nil,
  invite_expiration_minutes: nil,
  method_options: nil
)
  headers = {}
  headers = headers.merge(method_options.to_headers) unless method_options.nil?
  request = {
    organization_id: organization_id,
    email_address: email_address
  }
  request[:invite_redirect_url] = invite_redirect_url unless invite_redirect_url.nil?
  request[:invited_by_member_id] = invited_by_member_id unless invited_by_member_id.nil?
  request[:name] = name unless name.nil?
  request[:trusted_metadata] =  unless .nil?
  request[:untrusted_metadata] =  unless .nil?
  request[:invite_template_id] = invite_template_id unless invite_template_id.nil?
  request[:locale] = locale unless locale.nil?
  request[:roles] = roles unless roles.nil?
  request[:invite_expiration_minutes] = invite_expiration_minutes unless invite_expiration_minutes.nil?

  post_request('/v1/b2b/magic_links/email/invite', request, headers)
end

#login_or_signup(organization_id:, email_address:, login_redirect_url: nil, signup_redirect_url: nil, pkce_code_challenge: nil, login_template_id: nil, signup_template_id: nil, locale: nil, login_expiration_minutes: nil, signup_expiration_minutes: nil) ⇒ Object

Send either a login or signup magic link to a Member. A new, pending, or invited Member will receive a signup Email Magic Link. Members will have a ‘pending` status until they successfully authenticate. An active Member will receive a login Email Magic Link.

The magic link is valid for 60 minutes.

Parameters:

organization_id

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. You may also use the organization_slug or organization_external_id here as a convenience. The type of this field is String.

email_address

The email address of the Member. The type of this field is String.

login_redirect_url

The URL that the Member clicks from the login Email Magic Link. This URL should be an endpoint in the backend server that verifies the request by querying Stytch’s authenticate endpoint and finishes the login. 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_redirect_url

The URL the Member clicks from the signup Email Magic Link. This URL should be an endpoint in the backend server that verifies the request by querying Stytch’s authenticate endpoint and finishes the login. 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.

pkce_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.

login_template_id

Use a custom template for login emails. By default, it will use your default email template. The template must be from Stytch’s

built-in customizations or a custom HTML email for Magic Links - Login.

The type of this field is nilable +String+.
signup_template_id

Use a custom template for signup emails. By default, it will use your default email template. The template must be from Stytch’s

built-in customizations or a custom HTML email for Magic Links - Signup.

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 a [IETF BCP 47 language tag](www.w3.org/International/articles/language-tags/), 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](docs.google.com/forms/d/e/1FAIpQLScZSpAu_m2AmLXRT3F3kap-s_mcV6UTBitYn6CdyWP0-o7YjQ/viewform?usp=sf_link“)!

The type of this field is nilable +LoginOrSignupRequestLocale+ (string enum).
login_expiration_minutes

The expiration time, in minutes, for a login Email Magic Link. If not authenticated within this time frame, the email will need to be resent. Defaults to 60 (1 hour) with a minimum of 5 and a maximum of 10080 (1 week). The type of this field is nilable Integer.

signup_expiration_minutes

The expiration time, in minutes, for a signup Email Magic Link. If not authenticated within this time frame, the email will need to be resent. Defaults to 60 (1 hour) with a minimum of 5 and a maximum of 10080 (1 week). The type of this field is nilable Integer.

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.

member_id

Globally unique UUID that identifies a specific Member. The type of this field is String.

member_created

A flag indicating ‘true` if a new Member object was created and `false` if the Member object already existed. The type of this field is Boolean.

member

The [Member object](stytch.com/docs/b2b/api/member-object) The type of this field is Member (object).

organization

The [Organization object](stytch.com/docs/b2b/api/organization-object). The type of this field is Organization (object).

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.



259
260
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
# File 'lib/stytch/b2b_magic_links.rb', line 259

def (
  organization_id:,
  email_address:,
  login_redirect_url: nil,
  signup_redirect_url: nil,
  pkce_code_challenge: nil,
  login_template_id: nil,
  signup_template_id: nil,
  locale: nil,
  login_expiration_minutes: nil,
  signup_expiration_minutes: nil
)
  headers = {}
  request = {
    organization_id: organization_id,
    email_address: email_address
  }
  request[:login_redirect_url] =  unless .nil?
  request[:signup_redirect_url] =  unless .nil?
  request[:pkce_code_challenge] = pkce_code_challenge unless pkce_code_challenge.nil?
  request[:login_template_id] =  unless .nil?
  request[:signup_template_id] =  unless .nil?
  request[:locale] = locale unless locale.nil?
  request[:login_expiration_minutes] =  unless .nil?
  request[:signup_expiration_minutes] =  unless .nil?

  post_request('/v1/b2b/magic_links/email/login_or_signup', request, headers)
end