get_derived_token
async
¶
get_derived_token(
client_id: ClientIdType,
subject_token: GetDerivedTokenTokenModelType,
subject_token_type: TokenTypeIdentifierType,
*,
config_overrides: Optional[AsyncCognitoIdentityProviderClientConfig] = None,
client_secret: Optional[ClientSecretType] = None,
subject_token_provider_name: Optional[ProviderNameType] = None,
actor_token: Optional[GetDerivedTokenTokenModelType] = None,
actor_token_type: Optional[TokenTypeIdentifierType] = None,
actor_token_provider_name: Optional[ProviderNameType] = None,
scopes: Optional[ScopeListType] = None,
audiences: Optional[AudienceListType] = None,
resources: Optional[ResourceListType] = None,
requested_token_type: Optional[IssuedTokenTypeIdentifierType] = None,
) -> GetDerivedTokenResponse
Exchanges an existing token for a new token that is scoped and audience-bound for a specific downstream service, following the OAuth 2.0 Token Exchange grant type. For more information about the OAuth 2.0 Token Exchange grant type, see RFC 8693 - OAuth 2.0 Token Exchange on the IETF website. Present a SubjectToken, the credential that you already hold, to receive a new token appropriate for calling a specific resource server or audience.
If you also present an ActorToken that identifies an intermediary service, the issued token carries an act claim that identifies the intermediary, and downstream services can distinguish a user acting directly from an intermediary acting on the user's behalf. If you don't present an ActorToken, the issued token appears as if the user acted directly.
To use this operation, you must have IAM credentials, or you must present the requesting app client's ClientId and, if the client has a secret, ClientSecret, in the request.
The requesting app client must have ALLOW_TOKEN_EXCHANGE_IMPERSONATION or ALLOW_TOKEN_EXCHANGE_DELEGATION in its ExplicitAuthFlows (depending on whether you include an ActorToken), or the request fails.
Parameters:
-
client_id(ClientIdType) –The ID of the app client that requests the token exchange.
-
client_secret(Optional[ClientSecretType], default:None) –The client secret of the requested app client, if the client has a secret.
-
subject_token(GetDerivedTokenTokenModelType) –The token that you want to exchange for a new token. This is the credential that represents the identity of the party on behalf of whom the request is being made.
-
subject_token_type(TokenTypeIdentifierType) –The type of the
SubjectTokenthat you want to exchange. Valid values:-
ACCESS_TOKEN– The subject token is an access token. -
ID_TOKEN– The subject token is an ID token. -
SAML2– The subject token is a SAML 2.0 assertion.
-
-
subject_token_provider_name(Optional[ProviderNameType], default:None) –The name of the third-party identity provider that issued the
SubjectToken, if the subject token isn't a Amazon Cognito token. Provide this value when yourSubjectTokencame from a SAML or OIDC provider that you registered with your user pool, so that Amazon Cognito can validate it against that provider's configuration. Omit this parameter for a Amazon Cognito ID or access token. -
actor_token(Optional[GetDerivedTokenTokenModelType], default:None) –A token that identifies the intermediary service that is exchanging the token on behalf of the user. When you provide an
ActorToken, the token that Amazon Cognito issues carries anactclaim that identifies the intermediary, so that downstream services can distinguish a user acting directly from an intermediary acting on the user's behalf. -
actor_token_type(Optional[TokenTypeIdentifierType], default:None) –The type of the
ActorTokenthat you provide. Required when you provide anActorToken. Valid values:-
ACCESS_TOKEN– The actor token is an access token. -
ID_TOKEN– The actor token is an ID token. -
SAML2– The actor token is a SAML 2.0 assertion.
-
-
actor_token_provider_name(Optional[ProviderNameType], default:None) –The name of the third-party identity provider that issued the
ActorToken, if the actor token isn't a Amazon Cognito token. -
scopes(Optional[ScopeListType], default:None) –The scopes that you want the new token to have. Amazon Cognito issues a token with the intersection of these requested scopes, the scopes of your
SubjectToken, and the scopes that are allowed for the requesting app client. If you don't specify any scopes, Amazon Cognito issues a token with the same scopes as yourSubjectToken. -
audiences(Optional[AudienceListType], default:None) –The logical name of the target service where you intend to use the issued token. You can't request both
AudiencesandResourcesin the same request. -
resources(Optional[ResourceListType], default:None) –The identifier of a resource server in your user pool where you intend to use the issued token. You can't request both
ResourcesandAudiencesin the same request. -
requested_token_type(Optional[IssuedTokenTypeIdentifierType], default:None) –The type of token that you want Amazon Cognito to issue. Valid values:
-
ACCESS_TOKEN– Issues an access token. -
ID_TOKEN– Issues an ID token.
Amazon Cognito can't issue a SAML assertion, so
SAML2isn't a valid value for this parameter. -
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.
-
InvalidLambdaResponseException–This exception is thrown when Amazon Cognito encounters an invalid Lambda response.
-
InvalidParameterException–This exception is thrown when the Amazon Cognito service encounters an invalid parameter.
-
NotAuthorizedException–This exception is thrown when a user isn't authorized.
-
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.
-
ResourceNotFoundException–This exception is thrown when the Amazon Cognito service can't find the requested resource.
-
TooManyRequestsException–This exception is thrown when the user has made too many requests for a given operation.
-
UnexpectedLambdaException–This exception is thrown when Amazon Cognito encounters an unexpected exception with Lambda.
-
UserLambdaValidationException–This exception is thrown when the Amazon Cognito service encounters a user validation exception with the Lambda service.
-
UserNotFoundException–This exception is thrown when a user isn't found.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
Example exchange a subject token for an audience-bound access token The following example exchanges an access token for a new access token that is scoped and audience-bound for the solar-system-data resource server.
>>> await client.get_derived_token(client_id='1example23456789', client_secret='13ka4h7u28d9oo44tqpq9djqsfvhvu8rk4d2ighvpu0k8fj1c2r9', subject_token='eyJra456defEXAMPLE', subject_token_type='ACCESS_TOKEN', audiences=['solar-system-data'], scopes=['solar-system-data/asteroids.read'])
Source code in docs_src/capo_cognito_identity_provider/_services/async_cognito_identity_provider.py
6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 | |