Skip to content

create_o_auth2_token_with_iam async

create_o_auth2_token_with_iam(
    grant_type: ClientCredentialsGrantType,
    resource: Resource,
    *,
    config_overrides: Optional[AsyncSigninClientConfig] = None,
) -> CreateOAuth2TokenWithIAMResponse

Exchanges client credentials for an OAuth 2.0 access token scoped to a resource, which you can use to access AWS services from applications.

Parameters:

  • grant_type (ClientCredentialsGrantType) –

    The OAuth 2.0 grant type. Must be "client_credentials".

  • resource (Resource) –

    The OAuth resource for which the access token is requested. Example: "aws-mcp.amazonaws.com".

Raises:

Source code in docs_src/capo_signin/_services/async_signin.py
async def create_o_auth2_token_with_iam(
    self,
    grant_type: "capo_signin.types.client_credentials_grant_type.ClientCredentialsGrantType",
    resource: "capo_signin.types.resource.Resource",
    *,
    config_overrides: Optional[AsyncSigninClientConfig] = None,
) -> "capo_signin.types.create_o_auth2_token_with_iam_response.CreateOAuth2TokenWithIAMResponse":
    """Exchanges client credentials for an OAuth 2.0 access token scoped to a resource, which you can use to access AWS services from applications.

    Args:
        grant_type: The OAuth 2.0 grant type. Must be "client_credentials".
        resource: The OAuth resource for which the access token is requested. Example: "aws-mcp.amazonaws.com".

    Raises:
        capo_signin.errors.access_denied_exception.AccessDeniedException: You do not have sufficient access to perform this action.
        capo_signin.errors.internal_server_exception.InternalServerException: The request failed because of an internal server error.
        capo_signin.errors.too_many_requests_error.TooManyRequestsError: The request failed because you exceeded the request rate limit for this operation.
        capo_signin.errors.validation_exception.ValidationException: The request failed because it contains a malformed, missing, or invalid parameter.
        capo_signin.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_signin.types.create_o_auth2_token_with_iam_request.CreateOAuth2TokenWithIAMRequest]",
    ) -> AsyncOperationResponse[
        "capo_signin.types.create_o_auth2_token_with_iam_response.CreateOAuth2TokenWithIAMResponse"
    ]:
        import capo_signin._operations.signin.create_o_auth2_token_with_iam

        (
            output,
            http_response,
        ) = await capo_signin._operations.signin.create_o_auth2_token_with_iam.async_create_o_auth2_token_with_iam(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_output(
        output: "capo_signin.types.create_o_auth2_token_with_iam_response.CreateOAuth2TokenWithIAMResponse",
    ) -> dict[str, Any]:
        import capo_signin.types.create_o_auth2_token_with_iam_response

        return capo_signin.types.create_o_auth2_token_with_iam_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("CreateOAuth2TokenWithIAM", redact_output=_redact_output),
    )
    input_: capo_signin.types.create_o_auth2_token_with_iam_request.CreateOAuth2TokenWithIAMRequest = {
        "grant_type": grant_type,
        "resource": resource,
    }

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