Skip to content

get_o_auth_token

get_o_auth_token(
    credential_provider_arn: CredentialProviderArn,
    grant_type: GrantType,
    *,
    config_overrides: Optional[CredentialBrokerClientConfig] = None,
    scopes: Optional[Scopes] = None,
    resources: Optional[Resources] = None,
    audiences: Optional[Audiences] = None,
    custom_parameters: Optional[CustomParameters] = None,
    force_authentication: Optional[bool] = None,
    session_uri: Optional[SessionUri] = None,
) -> GetOAuthTokenResponse

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.

Parameters:

  • credential_provider_arn (CredentialProviderArn) –

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

  • grant_type (GrantType) –

    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 (Optional[Scopes], default: None ) –

    The OAuth scopes to request from the authorization server.

  • resources (Optional[Resources], default: None ) –

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

  • audiences (Optional[Audiences], default: None ) –

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

  • custom_parameters (Optional[CustomParameters], default: None ) –

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

  • force_authentication (Optional[bool], default: None ) –

    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.

  • session_uri (Optional[SessionUri], default: None ) –

    Return the token obtained for a consent session that a user has already completed. Supply the handle returned when the session was started.

Raises:

  • AccessDeniedException –

    The caller is not authorized to perform the request, or a resource the request depends on refused access. reason distinguishes a denial by this service from a denial reported by a dependency the caller configured, such as a customer-owned secret, KMS key, or external identity provider, which usually points at a permission or configuration fix outside this API.

  • InternalServerException –

    The request failed because of an unexpected error in the service. Whether the request took effect is undefined, so for a create or update, read the resource back before retrying. Retryable: the same request may succeed later.

  • ResourceNotFoundException –

    The requested resource does not exist, or the caller is not permitted to know that it exists. A resource that was deleted, or that is still being created, can also be reported this way.

  • ServiceQuotaExceededException –

    The request would exceed a service quota, so it was rejected and nothing was created or changed. Delete resources that are no longer needed, or request a quota increase in Service Quotas using serviceCode and quotaCode, then retry.

  • ServiceUnavailableException –

    A downstream dependency the broker relies on is temporarily unavailable, notably the customer's external IdP token/discovery endpoint (upstream 5xx, server_error, or temporarily_unavailable). Retryable: the same request may succeed later.

  • ThrottlingException –

    The request was denied because the caller exceeded a request rate limit. Nothing was changed. Retry with exponential backoff, honoring retryAfterSeconds when it is present.

  • ValidationException –

    The request is not valid. The request was rejected before any change was made, so it is safe to correct the input and retry. Use reason to branch in code and message for the human-readable detail of which field or combination of fields was at fault.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_credentialbroker/_services/credential_broker.py
def get_o_auth_token(
    self,
    credential_provider_arn: "capo_credentialbroker.types.credential_provider_arn.CredentialProviderArn",
    grant_type: "capo_credentialbroker.types.grant_type.GrantType",
    *,
    config_overrides: Optional[CredentialBrokerClientConfig] = None,
    scopes: Optional["capo_credentialbroker.types.scopes.Scopes"] = None,
    resources: Optional["capo_credentialbroker.types.resources.Resources"] = None,
    audiences: Optional["capo_credentialbroker.types.audiences.Audiences"] = None,
    custom_parameters: Optional[
        "capo_credentialbroker.types.custom_parameters.CustomParameters"
    ] = None,
    force_authentication: Optional[bool] = None,
    session_uri: Optional[
        "capo_credentialbroker.types.session_uri.SessionUri"
    ] = None,
) -> "capo_credentialbroker.types.get_o_auth_token_response.GetOAuthTokenResponse":
    """<p>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.</p> <p>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 <code>forceAuthentication</code> to bypass the cache and force a fresh request to the authorization server.</p> <p>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 <code>sessionUri</code>; 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 (<code>urn:ietf:params:oauth:grant-type:jwt-bearer</code>), where other authorization servers use RFC 8693 token exchange.</p>

    Args:
        credential_provider_arn: <p>Amazon Resource Name of the credential provider to obtain the token from. The provider must be an OAuth provider and must be READY.</p>
        grant_type: <p>How the token is obtained. Must be one of the grant types the provider allows; a grant the provider does not allow is rejected.</p>
        scopes: <p>The OAuth scopes to request from the authorization server.</p>
        resources: <p>Resource indicators (RFC 8707) naming the APIs this token is for. Omit unless the authorization server requires them.</p>
        audiences: <p>Audience values (RFC 8693) naming the intended recipients of this token. Omit unless the authorization server requires them.</p>
        custom_parameters: <p>Extra parameters to include in the request to the authorization server, for vendor extensions. Added to the standard OAuth parameters; they never override them.</p>
        force_authentication: <p>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.</p>
        session_uri: <p>Return the token obtained for a consent session that a user has already completed. Supply the handle returned when the session was started.</p>

    Raises:
        capo_credentialbroker.errors.access_denied_exception.AccessDeniedException: <p>The caller is not authorized to perform the request, or a resource the request depends on refused access. <code>reason</code> distinguishes a denial by this service from a denial reported by a dependency the caller configured, such as a customer-owned secret, KMS key, or external identity provider, which usually points at a permission or configuration fix outside this API.</p>
        capo_credentialbroker.errors.internal_server_exception.InternalServerException: <p>The request failed because of an unexpected error in the service. Whether the request took effect is undefined, so for a create or update, read the resource back before retrying. Retryable: the same request may succeed later.</p>
        capo_credentialbroker.errors.resource_not_found_exception.ResourceNotFoundException: <p>The requested resource does not exist, or the caller is not permitted to know that it exists. A resource that was deleted, or that is still being created, can also be reported this way.</p>
        capo_credentialbroker.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The request would exceed a service quota, so it was rejected and nothing was created or changed. Delete resources that are no longer needed, or request a quota increase in Service Quotas using <code>serviceCode</code> and <code>quotaCode</code>, then retry.</p>
        capo_credentialbroker.errors.service_unavailable_exception.ServiceUnavailableException: <p>A downstream dependency the broker relies on is temporarily unavailable, notably the customer's external IdP token/discovery endpoint (upstream 5xx, <code>server_error</code>, or <code>temporarily_unavailable</code>). Retryable: the same request may succeed later.</p>
        capo_credentialbroker.errors.throttling_exception.ThrottlingException: <p>The request was denied because the caller exceeded a request rate limit. Nothing was changed. Retry with exponential backoff, honoring <code>retryAfterSeconds</code> when it is present.</p>
        capo_credentialbroker.errors.validation_exception.ValidationException: <p>The request is not valid. The request was rejected before any change was made, so it is safe to correct the input and retry. Use <code>reason</code> to branch in code and <code>message</code> for the human-readable detail of which field or combination of fields was at fault.</p>
        capo_credentialbroker.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_credentialbroker.types.get_o_auth_token_request.GetOAuthTokenRequest]",
    ) -> OperationResponse[
        "capo_credentialbroker.types.get_o_auth_token_response.GetOAuthTokenResponse"
    ]:
        import capo_credentialbroker._operations.aws_tessera_data_plane.get_o_auth_token

        output, http_response = (
            capo_credentialbroker._operations.aws_tessera_data_plane.get_o_auth_token.get_o_auth_token(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_credentialbroker.types.get_o_auth_token_request.GetOAuthTokenRequest",
    ) -> dict[str, Any]:
        import capo_credentialbroker.types.get_o_auth_token_request

        return (
            capo_credentialbroker.types.get_o_auth_token_request.redact_sensitive(
                input_
            )
        )

    def _redact_output(
        output: "capo_credentialbroker.types.get_o_auth_token_response.GetOAuthTokenResponse",
    ) -> dict[str, Any]:
        import capo_credentialbroker.types.get_o_auth_token_response

        return (
            capo_credentialbroker.types.get_o_auth_token_response.redact_sensitive(
                output
            )
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "GetOAuthToken",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_credentialbroker.types.get_o_auth_token_request.GetOAuthTokenRequest = {
        "credential_provider_arn": credential_provider_arn,
        "grant_type": grant_type,
    }
    if scopes is not None:
        input_["scopes"] = scopes
    if resources is not None:
        input_["resources"] = resources
    if audiences is not None:
        input_["audiences"] = audiences
    if custom_parameters is not None:
        input_["custom_parameters"] = custom_parameters
    if force_authentication is not None:
        input_["force_authentication"] = force_authentication
    if session_uri is not None:
        input_["session_uri"] = session_uri

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output