Class: StytchB2B::Impersonation

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

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) ⇒ Impersonation

Returns a new instance of Impersonation.



15
16
17
# File 'lib/stytch/b2b_impersonation.rb', line 15

def initialize(connection)
  @connection = connection
end

Instance Method Details

#authenticate(impersonation_token:) ⇒ Object

Authenticate an impersonation token to impersonate a Member. This endpoint requires an impersonation token that is not expired or previously used. A Stytch session will be created for the impersonated member with a 60 minute duration. Impersonated sessions cannot be extended.

Prior to this step, you can generate an impersonation token by visiting the Stytch Dashboard, viewing a member, and clicking the ‘Impersonate Member` button.

Parameters:

impersonation_token

The Member Impersonation token to authenticate. Expires in 5 minutes by default. 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.

member_id

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

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

session_token

A secret token for a given Stytch Session. The type of this field is String.

session_jwt

The JSON Web Token (JWT) for a given Stytch Session. The type of this field is String.

organization

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

intermediate_session_token

Successfully authenticating an impersonation token will never result in an intermediate session. If the token is valid, a full session will be created. The type of this field is String.

member_authenticated

The member will always be fully authenticated if an impersonation token is successfully authenticated. The type of this field is Boolean.

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.

member_session

The [Session object](stytch.com/docs/b2b/api/session-object) for the impersonated Member. The type of this field is nilable MemberSession (object).

mfa_required

MFA will not be required when authenticating impersonation tokens. The type of this field is nilable MfaRequired (object).



67
68
69
70
71
72
73
74
75
76
# File 'lib/stytch/b2b_impersonation.rb', line 67

def authenticate(
  impersonation_token:
)
  headers = {}
  request = {
    impersonation_token: impersonation_token
  }

  post_request('/v1/b2b/impersonation/authenticate', request, headers)
end