Skip to content

start_o_auth_session async

start_o_auth_session(
    credential_provider_arn: CredentialProviderArn,
    session_binding_url: SessionBindingUrl,
    *,
    config_overrides: Optional[AsyncCredentialBrokerClientConfig] = None,
    scopes: Optional[Scopes] = None,
    resources: Optional[Resources] = None,
    audiences: Optional[Audiences] = None,
    custom_parameters: Optional[CustomParameters] = None,
    custom_state: Optional[CustomState] = None,
) -> StartOAuthSessionResponse

Starts a consent session so an end user can authorize the broker to obtain tokens on their behalf. Returns a URL to send the user's browser to, and a handle identifying the session.

Call this when GetOAuthToken returns no token for a provider that requires user consent. When a valid token is already available, this returns it directly and no consent is needed.

The operation is not idempotent and takes no idempotency token: it is an OAuth consent-flow step rather than durable resource creation. A replayed session is rejected by CompleteOAuthSessionBinding with SESSION_STATE_CONFLICT.

Parameters:

  • credential_provider_arn (CredentialProviderArn) –

    Amazon Resource Name of the credential provider the user is granting consent for.

  • scopes (Optional[Scopes], default: None ) –

    The OAuth scopes to request from the authorization server.

  • session_binding_url (SessionBindingUrl) –

    The URL the end user's browser is returned to once they have responded to the consent prompt. Must match one of the session-binding URLs allowed on the provider.

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

  • custom_state (Optional[CustomState], default: None ) –

    An opaque string of your own that is sent back to your session-binding URL unchanged. Use it to tie the response to the request you issued, so your handler can reject a response it did not initiate.

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.

  • 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/async_credential_broker.py
async def start_o_auth_session(
    self,
    credential_provider_arn: "capo_credentialbroker.types.credential_provider_arn.CredentialProviderArn",
    session_binding_url: "capo_credentialbroker.types.session_binding_url.SessionBindingUrl",
    *,
    config_overrides: Optional[AsyncCredentialBrokerClientConfig] = 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,
    custom_state: Optional[
        "capo_credentialbroker.types.custom_state.CustomState"
    ] = None,
) -> "capo_credentialbroker.types.start_o_auth_session_response.StartOAuthSessionResponse":
    """<p>Starts a consent session so an end user can authorize the broker to obtain tokens on their behalf. Returns a URL to send the user's browser to, and a handle identifying the session.</p> <p>Call this when GetOAuthToken returns no token for a provider that requires user consent. When a valid token is already available, this returns it directly and no consent is needed.</p> <p>The operation is not idempotent and takes no idempotency token: it is an OAuth consent-flow step rather than durable resource creation. A replayed session is rejected by <code>CompleteOAuthSessionBinding</code> with <code>SESSION_STATE_CONFLICT</code>.</p>

    Args:
        credential_provider_arn: <p>Amazon Resource Name of the credential provider the user is granting consent for.</p>
        scopes: <p>The OAuth scopes to request from the authorization server.</p>
        session_binding_url: <p>The URL the end user's browser is returned to once they have responded to the consent prompt. Must match one of the session-binding URLs allowed on the provider.</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>
        custom_state: <p>An opaque string of your own that is sent back to your session-binding URL unchanged. Use it to tie the response to the request you issued, so your handler can reject a response it did not initiate.</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_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.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_credentialbroker.types.start_o_auth_session_request.StartOAuthSessionRequest]",
    ) -> AsyncOperationResponse[
        "capo_credentialbroker.types.start_o_auth_session_response.StartOAuthSessionResponse"
    ]:
        import capo_credentialbroker._operations.aws_tessera_data_plane.start_o_auth_session

        (
            output,
            http_response,
        ) = await capo_credentialbroker._operations.aws_tessera_data_plane.start_o_auth_session.async_start_o_auth_session(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

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

        return capo_credentialbroker.types.start_o_auth_session_request.redact_sensitive(
            input_
        )

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

        return capo_credentialbroker.types.start_o_auth_session_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "StartOAuthSession",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_credentialbroker.types.start_o_auth_session_request.StartOAuthSessionRequest = {
        "credential_provider_arn": credential_provider_arn,
        "session_binding_url": session_binding_url,
    }
    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 custom_state is not None:
        input_["custom_state"] = custom_state

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output