Class: StytchB2B::Organizations::Members::OAuthProviders

Inherits:
Object
  • Object
show all
Includes:
Stytch::RequestHelper
Defined in:
lib/stytch/b2b_organizations.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) ⇒ OAuthProviders

Returns a new instance of OAuthProviders.



1253
1254
1255
# File 'lib/stytch/b2b_organizations.rb', line 1253

def initialize(connection)
  @connection = connection
end

Instance Method Details

#google(organization_id:, member_id:, include_refresh_token: nil) ⇒ Object

Retrieve the saved Google access token and ID token for a member. After a successful OAuth login, Stytch will save the issued access token and ID token from the identity provider. If a refresh token has been issued, Stytch will refresh the access token automatically.

Google One Tap does not return access tokens. If the member has only authenticated through Google One Tap and not through a regular Google OAuth flow, this endpoint will not return any tokens.

Note: Google does not issue a refresh token on every login, and refresh tokens may expire if unused. To force a refresh token to be issued, pass the ‘?provider_prompt=consent` query param into the [Start Google OAuth flow](stytch.com/docs/b2b/api/oauth-google-start) endpoint.

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

member_id

Globally unique UUID that identifies a specific Member. The ‘member_id` is critical to perform operations on a Member, so be sure to preserve this value. The type of this field is String.

include_refresh_token

Whether to return the refresh token Stytch has stored for the OAuth Provider. Defaults to false. Important: If your application exchanges the refresh token, Stytch may not be able to automatically refresh access tokens in the future. The type of this field is nilable Boolean.

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.

provider_type

Denotes the OAuth identity provider that the user has authenticated with, e.g. Google, Microsoft, GitHub etc. The type of this field is String.

provider_subject

The unique identifier for the User within a given OAuth provider. Also commonly called the ‘sub` or “Subject field” in OAuth protocols. The type of this field is String.

id_token

The ‘id_token` returned by the OAuth provider. ID Tokens are JWTs that contain structured information about a user. The exact content of each ID Token varies from provider to provider. ID Tokens are returned from OAuth providers that conform to the [OpenID Connect](openid.net/foundation/) specification, which is based on OAuth. The type of this field is String.

scopes

The OAuth scopes included for a given provider. See each provider’s section above to see which scopes are included by default and how to add custom scopes. The type of this field is list of 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.

access_token

The ‘access_token` that you may use to access the User’s data in the provider’s API. The type of this field is nilable String.

access_token_expires_in

The number of seconds until the access token expires. The type of this field is nilable Integer.

refresh_token

The ‘refresh_token` that you may use to obtain a new `access_token` for the User within the provider’s API. The type of this field is nilable String.



1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
# File 'lib/stytch/b2b_organizations.rb', line 1307

def google(
  organization_id:,
  member_id:,
  include_refresh_token: nil
)
  headers = {}
  query_params = {
    include_refresh_token: include_refresh_token
  }
  request = request_with_query_params("/v1/b2b/organizations/#{organization_id}/members/#{member_id}/oauth_providers/google", query_params)
  get_request(request, headers)
end

#microsoft(organization_id:, member_id:, include_refresh_token: nil) ⇒ Object

Retrieve the saved Microsoft access token and ID token for a member. After a successful OAuth login, Stytch will save the issued access token and ID token from the identity provider. If a refresh token has been issued, Stytch will refresh the access token automatically.

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

member_id

Globally unique UUID that identifies a specific Member. The ‘member_id` is critical to perform operations on a Member, so be sure to preserve this value. The type of this field is String.

include_refresh_token

Whether to return the refresh token Stytch has stored for the OAuth Provider. Defaults to false. Important: If your application exchanges the refresh token, Stytch may not be able to automatically refresh access tokens in the future. The type of this field is nilable Boolean.

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.

provider_type

Denotes the OAuth identity provider that the user has authenticated with, e.g. Google, Microsoft, GitHub etc. The type of this field is String.

provider_subject

The unique identifier for the User within a given OAuth provider. Also commonly called the ‘sub` or “Subject field” in OAuth protocols. The type of this field is String.

access_token

The ‘access_token` that you may use to access the User’s data in the provider’s API. The type of this field is String.

access_token_expires_in

The number of seconds until the access token expires. The type of this field is Integer.

id_token

The ‘id_token` returned by the OAuth provider. ID Tokens are JWTs that contain structured information about a user. The exact content of each ID Token varies from provider to provider. ID Tokens are returned from OAuth providers that conform to the [OpenID Connect](openid.net/foundation/) specification, which is based on OAuth. The type of this field is String.

scopes

The OAuth scopes included for a given provider. See each provider’s section above to see which scopes are included by default and how to add custom scopes. The type of this field is list of 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.

refresh_token

The ‘refresh_token` that you may use to obtain a new `access_token` for the User within the provider’s API. The type of this field is nilable String.



1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
# File 'lib/stytch/b2b_organizations.rb', line 1364

def microsoft(
  organization_id:,
  member_id:,
  include_refresh_token: nil
)
  headers = {}
  query_params = {
    include_refresh_token: include_refresh_token
  }
  request = request_with_query_params("/v1/b2b/organizations/#{organization_id}/members/#{member_id}/oauth_providers/microsoft", query_params)
  get_request(request, headers)
end