Skip to content

revoke_token async

revoke_token(
    token: TokenModelType,
    client_id: ClientIdType,
    *,
    config_overrides: Optional[AsyncCognitoIdentityProviderClientConfig] = None,
    client_secret: Optional[ClientSecretType] = None,
) -> RevokeTokenResponse

Revokes all of the access tokens generated by, and at the same time as, the specified refresh token. After a token is revoked, you can't use the revoked token to access Amazon Cognito user APIs, or to authorize access to your resource server.

Amazon Cognito doesn't evaluate Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you can't use IAM credentials to authorize requests, and you can't grant IAM permissions in policies. For more information about authorization models in Amazon Cognito, see Using the Amazon Cognito user pools API and user pool endpoints.

Parameters:

  • token (TokenModelType) –

    The refresh token that you want to revoke.

  • client_id (ClientIdType) –

    The ID of the app client where the token that you want to revoke was issued.

  • client_secret (Optional[ClientSecretType], default: None ) –

    The client secret of the requested app client, if the client has a secret.

Raises:

  • ForbiddenException –

    This exception is thrown when WAF doesn't allow your request based on a web ACL that's associated with your user pool.

  • InternalErrorException –

    This exception is thrown when Amazon Cognito encounters an internal error.

  • InvalidParameterException –

    This exception is thrown when the Amazon Cognito service encounters an invalid parameter.

  • OperationNotEnabledException –

    This exception is thrown when an operation is not available in the current region or for the current user pool configuration. This can occur when attempting to perform operations that are not supported in secondary replica regions.

  • TooManyRequestsException –

    This exception is thrown when the user has made too many requests for a given operation.

  • UnauthorizedException –

    Exception that is thrown when the request isn't authorized. This can happen due to an invalid access token in the request.

  • UnsupportedOperationException –

    Exception that is thrown when you attempt to perform an operation that isn't enabled for the user pool client.

  • UnsupportedTokenTypeException –

    Exception that is thrown when an unsupported token is passed to an operation.

  • UnknownServiceError –

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

Source code in docs_src/capo_cognito_identity_provider/_services/async_cognito_identity_provider.py
async def revoke_token(
    self,
    token: "capo_cognito_identity_provider.types.token_model_type.TokenModelType",
    client_id: "capo_cognito_identity_provider.types.client_id_type.ClientIdType",
    *,
    config_overrides: Optional[AsyncCognitoIdentityProviderClientConfig] = None,
    client_secret: Optional[
        "capo_cognito_identity_provider.types.client_secret_type.ClientSecretType"
    ] = None,
) -> (
    "capo_cognito_identity_provider.types.revoke_token_response.RevokeTokenResponse"
):
    """<p>Revokes all of the access tokens generated by, and at the same time as, the specified refresh token. After a token is revoked, you can't use the revoked token to access Amazon Cognito user APIs, or to authorize access to your resource server.</p> <note> <p>Amazon Cognito doesn't evaluate Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you can't use IAM credentials to authorize requests, and you can't grant IAM permissions in policies. For more information about authorization models in Amazon Cognito, see <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/user-pools-API-operations.html">Using the Amazon Cognito user pools API and user pool endpoints</a>.</p> </note>

    Args:
        token: <p>The refresh token that you want to revoke.</p>
        client_id: <p>The ID of the app client where the token that you want to revoke was issued.</p>
        client_secret: <p>The client secret of the requested app client, if the client has a secret.</p>

    Raises:
        capo_cognito_identity_provider.errors.forbidden_exception.ForbiddenException: <p>This exception is thrown when WAF doesn't allow your request based on a web ACL that's associated with your user pool.</p>
        capo_cognito_identity_provider.errors.internal_error_exception.InternalErrorException: <p>This exception is thrown when Amazon Cognito encounters an internal error.</p>
        capo_cognito_identity_provider.errors.invalid_parameter_exception.InvalidParameterException: <p>This exception is thrown when the Amazon Cognito service encounters an invalid parameter.</p>
        capo_cognito_identity_provider.errors.operation_not_enabled_exception.OperationNotEnabledException: <p>This exception is thrown when an operation is not available in the current region or for the current user pool configuration. This can occur when attempting to perform operations that are not supported in secondary replica regions.</p>
        capo_cognito_identity_provider.errors.too_many_requests_exception.TooManyRequestsException: <p>This exception is thrown when the user has made too many requests for a given operation.</p>
        capo_cognito_identity_provider.errors.unauthorized_exception.UnauthorizedException: <p>Exception that is thrown when the request isn't authorized. This can happen due to an invalid access token in the request.</p>
        capo_cognito_identity_provider.errors.unsupported_operation_exception.UnsupportedOperationException: <p>Exception that is thrown when you attempt to perform an operation that isn't enabled for the user pool client.</p>
        capo_cognito_identity_provider.errors.unsupported_token_type_exception.UnsupportedTokenTypeException: <p>Exception that is thrown when an unsupported token is passed to an operation.</p>
        capo_cognito_identity_provider.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_cognito_identity_provider.types.revoke_token_request.RevokeTokenRequest]",
    ) -> AsyncOperationResponse[
        "capo_cognito_identity_provider.types.revoke_token_response.RevokeTokenResponse"
    ]:
        import capo_cognito_identity_provider._operations.aws_cognito_identity_provider_service.revoke_token

        (
            output,
            http_response,
        ) = await capo_cognito_identity_provider._operations.aws_cognito_identity_provider_service.revoke_token.async_revoke_token(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_cognito_identity_provider.types.revoke_token_request.RevokeTokenRequest",
    ) -> dict[str, Any]:
        import capo_cognito_identity_provider.types.revoke_token_request

        return capo_cognito_identity_provider.types.revoke_token_request.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("RevokeToken", redact_input=_redact_input),
    )
    input_: capo_cognito_identity_provider.types.revoke_token_request.RevokeTokenRequest = {
        "token": token,
        "client_id": client_id,
    }
    if client_secret is not None:
        input_["client_secret"] = client_secret

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