Class: Stytch::Sessions

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

Instance Method Summary collapse

Methods included from RequestHelper

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

Constructor Details

#initialize(connection, project_id, jwks_cache, policy_cache) ⇒ Sessions



18
19
20
21
22
23
24
# File 'lib/stytch/sessions.rb', line 18

def initialize(connection, project_id, jwks_cache, policy_cache)
  @connection = connection

  @policy_cache = policy_cache
  @project_id = project_id
  @jwks_cache = jwks_cache
end

Instance Method Details

#attest(profile_id:, token:, session_duration_minutes: nil, session_custom_claims: nil, session_token: nil, session_jwt: nil, telemetry_id: nil) ⇒ Object

Exchange an auth token issued by a trusted identity provider for a Stytch session. You must first register a Trusted Auth Token profile in the Stytch dashboard [here](stytch.com/dashboard/trusted-auth-tokens). If a session token or session JWT is provided, it will add the trusted auth token as an authentication factor to the existing session.

Parameters:

profile_id

The ID of the trusted auth token profile to use for attestation. The type of this field is String.

token

The trusted auth token to authenticate. The type of this field is String.

session_duration_minutes

Set the session lifetime to be this many minutes from now. This will start a new session if one doesn’t already exist, returning both an opaque ‘session_token` and `session_jwt` for this session. Remember that the `session_jwt` will have a fixed lifetime of five minutes regardless of the underlying session duration, and will need to be refreshed over time.

This value must be a minimum of 5 and a maximum of 527040 minutes (366 days).

If a ‘session_token` or `session_jwt` is provided then a successful authentication will continue to extend the session this many minutes.

If the ‘session_duration_minutes` parameter is not specified, a Stytch session will not be created. The type of this field is nilable Integer.

session_custom_claims

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.

Custom claims made with reserved claims (“iss”, “sub”, “aud”, “exp”, “nbf”, “iat”, “jti”) will be ignored. Total custom claims size cannot exceed four kilobytes. The type of this field is nilable object.

session_token

The ‘session_token` for the session that you wish to add the trusted auth token authentication factor to. The type of this field is nilable String.

session_jwt

The ‘session_jwt` for the session that you wish to add the trusted auth token authentication factor to. The type of this field is nilable String.

telemetry_id

If the ‘telemetry_id` is passed, as part of this request, Stytch will call the [Fingerprint Lookup API](stytch.com/docs/fraud/api/fingerprint-lookup) and store the associated fingerprints and IPGEO information for the User. Your workspace must be enabled for Device Fingerprinting to use this feature. 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.

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.

user

The ‘user` object affected by this API call. See the [Get user endpoint](stytch.com/docs/api/get-user) for complete response field details. The type of this field is User (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.

session

If you initiate a Session, by including ‘session_duration_minutes` in your authenticate call, you’ll receive a full Session object in the response.

See [Session object](stytch.com/docs/api/session-object) for complete response fields.

The type of this field is nilable Session (object).

user_device

If a valid ‘telemetry_id` was passed in the request and the [Fingerprint Lookup API](stytch.com/docs/fraud/api/fingerprint-lookup) returned results, the `user_device` response field will contain information about the user’s device attributes. The type of this field is nilable DeviceInfo (object).



412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'lib/stytch/sessions.rb', line 412

def attest(
  profile_id:,
  token:,
  session_duration_minutes: nil,
  session_custom_claims: nil,
  session_token: nil,
  session_jwt: nil,
  telemetry_id: nil
)
  headers = {}
  request = {
    profile_id: profile_id,
    token: token
  }
  request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
  request[:session_token] = session_token unless session_token.nil?
  request[:session_jwt] = session_jwt unless session_jwt.nil?
  request[:telemetry_id] = telemetry_id unless telemetry_id.nil?

  post_request('/v1/sessions/attest', request, headers)
end

#authenticate(session_token: nil, session_duration_minutes: nil, session_jwt: nil, session_custom_claims: nil, authorization_check: nil) ⇒ Object

Authenticate a session token or session JWT and retrieve associated session data. If ‘session_duration_minutes` is included, update the lifetime of the session to be that many minutes from now. All timestamps are formatted according to the RFC 3339 standard and are expressed in UTC, e.g. `2021-12-29T12:33:09Z`. This endpoint requires exactly one `session_jwt` or `session_token` as part of the request. If both are included, you will receive a `too_many_session_arguments` error.

You may provide a JWT that needs to be refreshed and is expired according to its ‘exp` claim. A new JWT will be returned if both the signature and the underlying Session are still valid. See our [How to use Stytch Session JWTs](stytch.com/docs/guides/sessions/using-jwts) guide for more information.

Parameters:

session_token

The session token to authenticate. The type of this field is nilable String.

session_duration_minutes

Set the session lifetime to be this many minutes from now; minimum of 5 and a maximum of 527040 minutes (366 days). Note that a successful authentication will continue to extend the session this many minutes. The type of this field is nilable Integer.

session_jwt

The JWT to authenticate. You may provide a JWT that has expired according to its ‘exp` claim and needs to be refreshed. If the signature is valid and the underlying session is still active then Stytch will return a new JWT. The type of this field is nilable String.

session_custom_claims

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.

Custom claims made with reserved claims (“iss”, “sub”, “aud”, “exp”, “nbf”, “iat”, “jti”) will be ignored. Total custom claims size cannot exceed four kilobytes. The type of this field is nilable object.

authorization_check

If an ‘authorization_check` object is passed in, this endpoint will also check if the User is authorized to perform the given action on the given Resource. A User is authorized if they are assigned a Role with adequate permissions.

If the User is not authorized to perform the specified action on the specified Resource, a 403 error will be thrown. Otherwise, the response will contain a list of Roles that satisfied the authorization check. The type of this field is nilable AuthorizationCheck (object).

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.

session

If you initiate a Session, by including ‘session_duration_minutes` in your authenticate call, you’ll receive a full Session object in the response.

See [Session object](stytch.com/docs/api/session-object) for complete response fields.

The type of this field is Session (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.

user

The ‘user` object affected by this API call. See the [Get user endpoint](stytch.com/docs/api/get-user) for complete response field details. The type of this field is User (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.

verdict

If an ‘authorization_check` is provided in the request and the check succeeds, this field will return information about why the User was granted permission. The type of this field is nilable AuthorizationVerdict (object).



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/stytch/sessions.rb', line 109

def authenticate(
  session_token: nil,
  session_duration_minutes: nil,
  session_jwt: nil,
  session_custom_claims: nil,
  authorization_check: nil
)
  headers = {}
  request = {}
  request[:session_token] = session_token unless session_token.nil?
  request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
  request[:session_jwt] = session_jwt unless session_jwt.nil?
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
  request[:authorization_check] = authorization_check unless authorization_check.nil?

  post_request('/v1/sessions/authenticate', request, headers)
end

#authenticate_jwt(session_jwt, max_token_age_seconds: nil, session_duration_minutes: nil, session_custom_claims: nil, clock_tolerance_seconds: nil, authorization_check: nil) ⇒ Object

Parse a JWT and verify the signature. If max_token_age_seconds is unset, call the API directly If max_token_age_seconds is set and the JWT was issued (based on the “iat” claim) less than max_token_age_seconds seconds ago, then just verify locally and don’t call the API To force remote validation for all tokens, set max_token_age_seconds to 0 or call authenticate() If max_token_age_seconds is not supplied 300 seconds will be used as the default. If clock_tolerance_seconds is not supplied 0 seconds will be used as the default.



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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'lib/stytch/sessions.rb', line 446

def authenticate_jwt(
  session_jwt,
  max_token_age_seconds: nil,
  session_duration_minutes: nil,
  session_custom_claims: nil,
  clock_tolerance_seconds: nil,
  authorization_check: nil
)
  max_token_age_seconds = 300 if max_token_age_seconds.nil?
  clock_tolerance_seconds = 0 if clock_tolerance_seconds.nil?

  if max_token_age_seconds == 0
    return authenticate(
      session_jwt: session_jwt,
      session_duration_minutes: session_duration_minutes,
      session_custom_claims: session_custom_claims,
      authorization_check: authorization_check
    )
  end

  session = authenticate_jwt_local(
    session_jwt,
    max_token_age_seconds: max_token_age_seconds,
    clock_tolerance_seconds: clock_tolerance_seconds,
    authorization_check: authorization_check
  )
  return session unless session.nil?

  authenticate(
    session_jwt: session_jwt,
    session_duration_minutes: session_duration_minutes,
    session_custom_claims: session_custom_claims,
    authorization_check: authorization_check
  )
rescue StandardError
  # JWT could not be verified locally. Check with the Stytch API.
  authenticate(
    session_jwt: session_jwt,
    session_duration_minutes: session_duration_minutes,
    session_custom_claims: session_custom_claims,
    authorization_check: authorization_check
  )
end

#authenticate_jwt_local(session_jwt, max_token_age_seconds: nil, clock_tolerance_seconds: nil, authorization_check: nil) ⇒ Object

Parse a JWT and verify the signature locally (without calling /authenticate in the API) Uses the cached value to get the JWK but if it is unavailable, it calls the get_jwks() function to get the JWK This method never authenticates a JWT directly with the API If max_token_age_seconds is not supplied 300 seconds will be used as the default. If clock_tolerance_seconds is not supplied 0 seconds will be used as the default.



496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
# File 'lib/stytch/sessions.rb', line 496

def authenticate_jwt_local(session_jwt, max_token_age_seconds: nil, clock_tolerance_seconds: nil, authorization_check: nil)
  max_token_age_seconds = 300 if max_token_age_seconds.nil?
  clock_tolerance_seconds = 0 if clock_tolerance_seconds.nil?

  default_issuer = 'stytch.com/' + @project_id
  base_url_issuer = @connection.url_prefix
  valid_issuers = [default_issuer, base_url_issuer]

  begin
    decoded_token = JWT.decode session_jwt, nil, true,
                               { jwks: @jwks_cache.loader, iss: valid_issuers, verify_iss: true, aud: @project_id, verify_aud: true, algorithms: ['RS256'], nbf_leeway: clock_tolerance_seconds }

    session = decoded_token[0]
    iat_time = Time.at(session['iat']).to_datetime
    return nil unless iat_time + max_token_age_seconds >= Time.now

    session = marshal_jwt_into_session(session)
  rescue JWT::InvalidIssuerError
    raise JWTInvalidIssuerError
  rescue JWT::InvalidAudError
    raise JWTInvalidAudienceError
  rescue JWT::ExpiredSignature
    raise JWTExpiredSignatureError
  rescue JWT::IncorrectAlgorithm
    raise JWTIncorrectAlgorithmError
  end

  # Do the auth check - intentionally don't rescue errors from here
  if authorization_check
    @policy_cache.perform_consumer_authorization_check(
      subject_roles: session['roles'],
      authorization_check: authorization_check
    )
  end

  session
end

#exchange_access_token(access_token:, session_duration_minutes: nil, session_custom_claims: nil, telemetry_id: nil) ⇒ Object

Use this endpoint to exchange a Connected Apps Access Token back into a Stytch Session for the underlying User. This session can be used with the Stytch SDKs and APIs.

The Session returned will be the same Session that was active in your application (the authorizing party) during the initial authorization flow.

The Access Token must contain the ‘full_access` scope (only available to First Party clients) and must not be more than 5 minutes old. Access Tokens may only be exchanged a single time.

Parameters:

access_token

The access token to exchange for a Stytch Session. Must be granted the ‘full_access` scope. The type of this field is String.

session_duration_minutes

Set the session lifetime to be this many minutes from now. This will start a new session if one doesn’t already exist, returning both an opaque ‘session_token` and `session_jwt` for this session. Remember that the `session_jwt` will have a fixed lifetime of five minutes regardless of the underlying session duration, and will need to be refreshed over time.

This value must be a minimum of 5 and a maximum of 527040 minutes (366 days).

If a ‘session_token` or `session_jwt` is provided then a successful authentication will continue to extend the session this many minutes.

If the ‘session_duration_minutes` parameter is not specified, a Stytch session will not be created. The type of this field is nilable Integer.

session_custom_claims

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.

Custom claims made with reserved claims (“iss”, “sub”, “aud”, “exp”, “nbf”, “iat”, “jti”) will be ignored. Total custom claims size cannot exceed four kilobytes. The type of this field is nilable object.

telemetry_id

If the ‘telemetry_id` is passed, as part of this request, Stytch will call the [Fingerprint Lookup API](stytch.com/docs/fraud/api/fingerprint-lookup) and store the associated fingerprints and IPGEO information for the User. Your workspace must be enabled for Device Fingerprinting to use this feature. 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.

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.

user

The ‘user` object affected by this API call. See the [Get user endpoint](stytch.com/docs/api/get-user) for complete response field details. The type of this field is User (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.

session

If you initiate a Session, by including ‘session_duration_minutes` in your authenticate call, you’ll receive a full Session object in the response.

See [Session object](stytch.com/docs/api/session-object) for complete response fields.

The type of this field is nilable Session (object).

user_device

If a valid ‘telemetry_id` was passed in the request and the [Fingerprint Lookup API](stytch.com/docs/fraud/api/fingerprint-lookup) returned results, the `user_device` response field will contain information about the user’s device attributes. The type of this field is nilable DeviceInfo (object).



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/stytch/sessions.rb', line 294

def exchange_access_token(
  access_token:,
  session_duration_minutes: nil,
  session_custom_claims: nil,
  telemetry_id: nil
)
  headers = {}
  request = {
    access_token: access_token
  }
  request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
  request[:telemetry_id] = telemetry_id unless telemetry_id.nil?

  post_request('/v1/sessions/exchange_access_token', request, headers)
end

#get(user_id:) ⇒ Object

List all active Sessions for a given ‘user_id`. All timestamps are formatted according to the RFC 3339 standard and are expressed in UTC, e.g. `2021-12-29T12:33:09Z`.

Parameters:

user_id

The ‘user_id` to get active Sessions for. You may use an `external_id` here if one is set for 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.

sessions

An array of [Session objects](stytch.com/docs/api/session-object). The type of this field is list of Session (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.



44
45
46
47
48
49
50
51
52
53
# File 'lib/stytch/sessions.rb', line 44

def get(
  user_id:
)
  headers = {}
  query_params = {
    user_id: user_id
  }
  request = request_with_query_params('/v1/sessions', query_params)
  get_request(request, headers)
end

#get_jwks(project_id:) ⇒ Object

Get the JSON Web Key Set (JWKS) for a project.

Within the JWKS, the JSON Web Keys are rotated every ~6 months. Upon rotation, new JWTs will be signed using the new key, and both keys will be returned by this endpoint for a period of 1 month.

JWTs have a set lifetime of 5 minutes, so there will be a 5 minute period where some JWTs will be signed by the old keys, and some JWTs will be signed by the new keys. The correct key to use for validation is determined by matching the ‘kid` value of the JWT and key.

If you’re using one of our [backend SDKs](stytch.com/docs/b2b/sdks), the JSON Web Key (JWK) rotation will be handled for you.

If you’re using your own JWT validation library, many have built-in support for JWK rotation, and you’ll just need to supply this API endpoint. If not, your application should decide which JWK to use for validation by inspecting the ‘kid` value.

See our [How to use Stytch Session JWTs](stytch.com/docs/guides/sessions/using-jwts) guide for more information.

Parameters:

project_id

The ‘project_id` to get the JWKS for. The type of this field is String.

Returns:

An object with the following fields:

keys

The list of JWKs associated with the project. The type of this field is list of JWK (object).

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.



339
340
341
342
343
344
345
346
# File 'lib/stytch/sessions.rb', line 339

def get_jwks(
  project_id:
)
  headers = {}
  query_params = {}
  request = request_with_query_params("/v1/sessions/jwks/#{project_id}", query_params)
  get_request(request, headers)
end

#marshal_jwt_into_session(jwt) ⇒ Object



534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
# File 'lib/stytch/sessions.rb', line 534

def marshal_jwt_into_session(jwt)
  stytch_claim = 'https://stytch.com/session'
  expires_at = jwt[stytch_claim]['expires_at'] || Time.at(jwt['exp']).to_datetime.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
  # The custom claim set is all the claims in the payload except for the standard claims and
  # the Stytch session claim. The cleanest way to collect those seems to be naming what we want
  # to omit and filtering the rest to collect the custom claims.
  reserved_claims = ['aud', 'exp', 'iat', 'iss', 'jti', 'nbf', 'sub', stytch_claim]
  custom_claims = jwt.reject { |key, _| reserved_claims.include?(key) }
  {
    'session' => {
      'session_id' => jwt[stytch_claim]['id'],
      'user_id' => jwt['sub'],
      'started_at' => jwt[stytch_claim]['started_at'],
      'last_accessed_at' => jwt[stytch_claim]['last_accessed_at'],
      # For JWTs that include it, prefer the inner expires_at claim.
      'expires_at' => expires_at,
      'attributes' => jwt[stytch_claim]['attributes'],
      'authentication_factors' => jwt[stytch_claim]['authentication_factors'],
      'custom_claims' => custom_claims,
      'roles' => jwt[stytch_claim]['roles']
    }
  }
end

#migrate(session_token:, session_duration_minutes: nil, session_custom_claims: nil, telemetry_id: nil) ⇒ Object

Migrate a session from an external OIDC compliant endpoint. Stytch will call the external UserInfo endpoint defined in your Stytch Project settings in the [Dashboard](stytch.com/dashboard), and then perform a lookup using the ‘session_token`. If the response contains a valid email address, Stytch will attempt to match that email address with an existing User and create a Stytch Session. You will need to create the user before using this endpoint.

Parameters:

session_token

The authorization token Stytch will pass in to the external userinfo endpoint. The type of this field is String.

session_duration_minutes

Set the session lifetime to be this many minutes from now. This will start a new session if one doesn’t already exist, returning both an opaque ‘session_token` and `session_jwt` for this session. Remember that the `session_jwt` will have a fixed lifetime of five minutes regardless of the underlying session duration, and will need to be refreshed over time.

This value must be a minimum of 5 and a maximum of 527040 minutes (366 days).

If a ‘session_token` or `session_jwt` is provided then a successful authentication will continue to extend the session this many minutes.

If the ‘session_duration_minutes` parameter is not specified, a Stytch session will not be created. The type of this field is nilable Integer.

session_custom_claims

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.

Custom claims made with reserved claims (“iss”, “sub”, “aud”, “exp”, “nbf”, “iat”, “jti”) will be ignored. Total custom claims size cannot exceed four kilobytes. The type of this field is nilable object.

telemetry_id

If the ‘telemetry_id` is passed, as part of this request, Stytch will call the [Fingerprint Lookup API](stytch.com/docs/fraud/api/fingerprint-lookup) and store the associated fingerprints and IPGEO information for the User. Your workspace must be enabled for Device Fingerprinting to use this feature. 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.

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.

user

The ‘user` object affected by this API call. See the [Get user endpoint](stytch.com/docs/api/get-user) for complete response field details. The type of this field is User (object).

status_code

(no documentation yet) The type of this field is Integer.

session

If you initiate a Session, by including ‘session_duration_minutes` in your authenticate call, you’ll receive a full Session object in the response.

See [Session object](stytch.com/docs/api/session-object) for complete response fields.

The type of this field is nilable Session (object).

user_device

If a valid ‘telemetry_id` was passed in the request and the [Fingerprint Lookup API](stytch.com/docs/fraud/api/fingerprint-lookup) returned results, the `user_device` response field will contain information about the user’s device attributes. The type of this field is nilable DeviceInfo (object).



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/stytch/sessions.rb', line 217

def migrate(
  session_token:,
  session_duration_minutes: nil,
  session_custom_claims: nil,
  telemetry_id: nil
)
  headers = {}
  request = {
    session_token: session_token
  }
  request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
  request[:telemetry_id] = telemetry_id unless telemetry_id.nil?

  post_request('/v1/sessions/migrate', request, headers)
end

#revoke(session_id: nil, session_token: nil, session_jwt: nil) ⇒ Object

Revoke a Session, immediately invalidating all of its session tokens. You can revoke a session in three ways: using its ID, or using one of its session tokens, or one of its JWTs. This endpoint requires exactly one of those to be included in the request. It will return an error if multiple are present.

Parameters:

session_id

The ‘session_id` to revoke. The type of this field is nilable String.

session_token

The session token to revoke. The type of this field is nilable String.

session_jwt

A JWT for the session to revoke. 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.

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.



148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/stytch/sessions.rb', line 148

def revoke(
  session_id: nil,
  session_token: nil,
  session_jwt: nil
)
  headers = {}
  request = {}
  request[:session_id] = session_id unless session_id.nil?
  request[:session_token] = session_token unless session_token.nil?
  request[:session_jwt] = session_jwt unless session_jwt.nil?

  post_request('/v1/sessions/revoke', request, headers)
end