CredentialBroker / Client / get_o_auth_token

get_o_auth_token

CredentialBroker.Client.get_o_auth_token(**kwargs)

Retrieves an OAuth access token from a credential provider. The broker authenticates to the provider’s authorization server with the client credentials configured on the provider, obtains a token, and returns it — so your workload never handles the provider’s client secret.

The broker caches the access token it obtains until that token expires, or for up to one hour when the token’s own lifetime is longer than an hour. A call made while a cached token is still valid returns that token instead of requesting a new one; set forceAuthentication to bypass the cache and force a fresh request to the authorization server.

The grant type you name must be one the provider allows. CLIENT_CREDENTIALS returns a token representing the workload itself; TOKEN_EXCHANGE returns a token that preserves the identity of the caller the workload is acting for; AUTHORIZATION_CODE returns a token representing an end user who granted consent, and requires a consent session that user has already completed, named in sessionUri; JWT_AUTHORIZATION_GRANT presents a signed JWT as the grant, so no client secret is sent on the token request. Of the supported vendors, only Microsoft Entra ID accepts this grant today: Entra implements on-behalf-of delegation with the RFC 7523 JWT bearer grant ( urn:ietf:params:oauth:grant-type:jwt-bearer), where other authorization servers use RFC 8693 token exchange.

See also: AWS API Documentation

Request Syntax

response = client.get_o_auth_token(
    credentialProviderArn='string',
    grantType='CLIENT_CREDENTIALS'|'TOKEN_EXCHANGE'|'JWT_AUTHORIZATION_GRANT'|'AUTHORIZATION_CODE',
    scopes=[
        'string',
    ],
    resources=[
        'string',
    ],
    audiences=[
        'string',
    ],
    customParameters={
        'string': 'string'
    },
    forceAuthentication=True|False,
    sessionUri='string'
)
Parameters:
  • credentialProviderArn (string) –

    [REQUIRED]

    Amazon Resource Name of the credential provider to obtain the token from. The provider must be an OAuth provider and must be READY.

  • grantType (string) –

    [REQUIRED]

    How the token is obtained. Must be one of the grant types the provider allows; a grant the provider does not allow is rejected.

  • scopes (list) –

    The OAuth scopes to request from the authorization server.

    • (string) –

  • resources (list) –

    Resource indicators (RFC 8707) naming the APIs this token is for. Omit unless the authorization server requires them.

    • (string) –

  • audiences (list) –

    Audience values (RFC 8693) naming the intended recipients of this token. Omit unless the authorization server requires them.

    • (string) –

  • customParameters (dict) –

    Extra parameters to include in the request to the authorization server, for vendor extensions. Added to the standard OAuth parameters; they never override them.

    • (string) –

      • (string) –

  • forceAuthentication (boolean) – Request a new token from the authorization server even when the broker already holds a valid one for this provider. Defaults to false, which returns the held token when one is available.

  • sessionUri (string) – Return the token obtained for a consent session that a user has already completed. Supply the handle returned when the session was started.

Return type:

dict

Returns:

Response Syntax

{
    'accessToken': 'string',
    'expiresAt': datetime(2015, 1, 1),
    'sessionStatus': 'IN_PROGRESS'|'COMPLETED'|'FAILED'
}

Response Structure

  • (dict) –

    • accessToken (string) –

      The access token. Present it to the third-party API as a bearer credential.

    • expiresAt (datetime) –

      When the access token expires. Absent when the authorization server does not report an expiry, in which case the token’s lifetime is whatever that server applies.

    • sessionStatus (string) –

      Status of the consent session named in the request, so a repeated call can tell whether the user has finished granting consent.

Exceptions