o ckF[}`@sXddlZddlmZddlmZddlmZddlmZddl m Z GdddeZ dS) N)json)AWSQueryConnection) RegionInfo)JSONResponseError) exceptionsc seZdZdZdZdZdZdZdZe Z e j e j e je je je je je jdZfdd Zd d Z d)d dZddZddZd*ddZd*ddZ d+ddZd*ddZd*ddZ d,ddZdd Z d!d"Z!d#d$Z" d)d%d&Z#d'd(Z$Z%S)-CognitoIdentityConnectiona Amazon Cognito Amazon Cognito is a web service that delivers scoped temporary credentials to mobile devices and other untrusted environments. Amazon Cognito uniquely identifies a device and supplies the user with a consistent identity over the lifetime of an application. Using Amazon Cognito, you can enable authentication with one or more third-party identity providers (Facebook, Google, or Login with Amazon), and you can also choose to support unauthenticated access from your app. Cognito delivers a unique identifier for each user and acts as an OpenID token provider trusted by AWS Security Token Service (STS) to access temporary, limited- privilege AWS credentials. To provide end-user credentials, first make an unsigned call to GetId. If the end user is authenticated with one of the supported identity providers, set the `Logins` map with the identity provider token. `GetId` returns a unique identifier for the user. Next, make an unsigned call to GetOpenIdToken, which returns the OpenID token necessary to call STS and retrieve AWS credentials. This call expects the same `Logins` map as the `GetId` call, as well as the `IdentityID` originally returned by `GetId`. The token returned by `GetOpenIdToken` can be passed to the STS operation `AssumeRoleWithWebIdentity`_ to retrieve AWS credentials. z 2014-06-30z us-east-1z(cognito-identity.us-east-1.amazonaws.comCognitoIdentityAWSCognitoIdentityService)LimitExceededExceptionResourceConflictException'DeveloperUserAlreadyRegisteredExceptionTooManyRequestsExceptionInvalidParameterExceptionResourceNotFoundExceptionInternalErrorExceptionNotAuthorizedExceptionc s^|dd}|st||j|j}d|vs|ddur|j|d<tt|jdi|||_dS)Nregionhost) poprDefaultRegionNameDefaultRegionEndpointendpointsuperr__init__r)selfkwargsr __class__r>/usr/lib/python3/dist-packages/boto/cognito/identity/layer1.pyrNs   z"CognitoIdentityConnection.__init__cCsdgS)Nzhmac-v4r)rrrr_required_auth_capabilityZsz3CognitoIdentityConnection._required_auth_capabilityNcCsN||d}|dur ||d<|dur||d<|dur||d<|jdt|dS)a2 Creates a new identity pool. The identity pool is a store of user identity information that is specific to your AWS account. The limit on identity pools is 60 per account. :type identity_pool_name: string :param identity_pool_name: A string that you provide. :type allow_unauthenticated_identities: boolean :param allow_unauthenticated_identities: TRUE if the identity pool supports unauthenticated logins. :type supported_login_providers: map :param supported_login_providers: Optional key:value pairs mapping provider names to provider app IDs. :type developer_provider_name: string :param developer_provider_name: The "domain" by which Cognito will refer to your users. This name acts as a placeholder that allows your backend and the Cognito service to communicate about the developer provider. For the `DeveloperProviderName`, you can use letters as well as period ( `.`), underscore ( `_`), and dash ( `-`). Once you have set a developer provider name, you cannot change it. Please take care in setting this parameter. :type open_id_connect_provider_ar_ns: list :param open_id_connect_provider_ar_ns: )IdentityPoolNameAllowUnauthenticatedIdentitiesNSupportedLoginProvidersDeveloperProviderNameOpenIdConnectProviderARNsCreateIdentityPoolactionbody make_requestrdumps)ridentity_pool_name allow_unauthenticated_identitiessupported_login_providersdeveloper_provider_nameopen_id_connect_provider_ar_nsparamsrrrcreate_identity_pool]s$z.CognitoIdentityConnection.create_identity_poolcCd|i}|jdt|dS)z Deletes a user pool. Once a pool is deleted, users will not be able to authenticate with the pool. :type identity_pool_id: string :param identity_pool_id: An identity pool ID in the format REGION:GUID. IdentityPoolIdDeleteIdentityPoolr'r*ridentity_pool_idr2rrrdelete_identity_pools z.CognitoIdentityConnection.delete_identity_poolcCr4)a Gets details about a particular identity pool, including the pool name, ID description, creation date, and current number of users. :type identity_pool_id: string :param identity_pool_id: An identity pool ID in the format REGION:GUID. r5DescribeIdentityPoolr'r*r7rrrdescribe_identity_pools z0CognitoIdentityConnection.describe_identity_poolcC.||d}|dur ||d<|jdt|dS)a Generates (or retrieves) a Cognito ID. Supplying multiple logins will create an implicit linked account. :type account_id: string :param account_id: A standard AWS account ID (9+ digits). :type identity_pool_id: string :param identity_pool_id: An identity pool ID in the format REGION:GUID. :type logins: map :param logins: A set of optional name-value pairs that map provider names to provider tokens. The available provider names for `Logins` are as follows: + Facebook: `graph.facebook.com` + Google: `accounts.google.com` + Amazon: `www.amazon.com` ) AccountIdr5NLoginsGetIdr'r*)r account_idr8loginsr2rrrget_idsz CognitoIdentityConnection.get_idcC,d|i}|dur ||d<|jdt|dS)a# Gets an OpenID token, using a known Cognito ID. This known Cognito ID is returned by GetId. You can optionally add additional logins for the identity. Supplying multiple logins creates an implicit link. The OpenId token is valid for 15 minutes. :type identity_id: string :param identity_id: A unique identifier in the format REGION:GUID. :type logins: map :param logins: A set of optional name-value pairs that map provider names to provider tokens. IdentityIdNr>GetOpenIdTokenr'r*)r identity_idrAr2rrrget_open_id_tokens z+CognitoIdentityConnection.get_open_id_tokencCs>||d}|dur ||d<|dur||d<|jdt|dS)a Registers (or retrieves) a Cognito `IdentityId` and an OpenID Connect token for a user authenticated by your backend authentication process. Supplying multiple logins will create an implicit linked account. You can only specify one developer provider as part of the `Logins` map, which is linked to the identity pool. The developer provider is the "domain" by which Cognito will refer to your users. You can use `GetOpenIdTokenForDeveloperIdentity` to create a new identity and to link new logins (that is, user credentials issued by a public provider or developer provider) to an existing identity. When you want to create a new identity, the `IdentityId` should be null. When you want to associate a new login with an existing authenticated/unauthenticated identity, you can do so by providing the existing `IdentityId`. This API will create the identity in the specified `IdentityPoolId`. :type identity_pool_id: string :param identity_pool_id: An identity pool ID in the format REGION:GUID. :type identity_id: string :param identity_id: A unique identifier in the format REGION:GUID. :type logins: map :param logins: A set of optional name-value pairs that map provider names to provider tokens. Each name-value pair represents a user from a public provider or developer provider. If the user is from a developer provider, the name-value pair will follow the syntax `"developer_provider_name": "developer_user_identifier"`. The developer provider is the "domain" by which Cognito will refer to your users; you provided this domain while creating/updating the identity pool. The developer user identifier is an identifier from your backend that uniquely identifies a user. When you create an identity pool, you can specify the supported logins. :type token_duration: long :param token_duration: The expiration time of the token, in seconds. You can specify a custom expiration time for the token so that you can cache it. If you don't provide an expiration time, the token is valid for 15 minutes. You can exchange the token with Amazon STS for temporary AWS credentials, which are valid for a maximum of one hour. The maximum token duration you can set is 24 hours. You should take care in setting the expiration time for a token, as there are significant security implications: an attacker could use a leaked token to access your AWS resources for the token's duration. )r5r>NrD TokenDuration"GetOpenIdTokenForDeveloperIdentityr'r*)rr8rArFtoken_durationr2rrr(get_open_id_token_for_developer_identitys5zBCognitoIdentityConnection.get_open_id_token_for_developer_identitycCr<)ag Lists the identities in a pool. :type identity_pool_id: string :param identity_pool_id: An identity pool ID in the format REGION:GUID. :type max_results: integer :param max_results: The maximum number of identities to return. :type next_token: string :param next_token: A pagination token. )r5 MaxResultsN NextTokenListIdentitiesr'r*)rr8 max_results next_tokenr2rrrlist_identitiessz)CognitoIdentityConnection.list_identitiescCrC)a Lists all of the Cognito identity pools registered for your account. :type max_results: integer :param max_results: The maximum number of identities to return. :type next_token: string :param next_token: A pagination token. rLNrMListIdentityPoolsr'r*)rrOrPr2rrrlist_identity_pools3s  z-CognitoIdentityConnection.list_identity_poolscCs\d|i}|dur ||d<|dur||d<|dur||d<|dur$||d<|jdt|dS) a Retrieves the `IdentityID` associated with a `DeveloperUserIdentifier` or the list of `DeveloperUserIdentifier`s associated with an `IdentityId` for an existing identity. Either `IdentityID` or `DeveloperUserIdentifier` must not be null. If you supply only one of these values, the other value will be searched in the database and returned as a part of the response. If you supply both, `DeveloperUserIdentifier` will be matched against `IdentityID`. If the values are verified against the database, the response returns both values and is the same as the request. Otherwise a `ResourceConflictException` is thrown. :type identity_pool_id: string :param identity_pool_id: An identity pool ID in the format REGION:GUID. :type identity_id: string :param identity_id: A unique identifier in the format REGION:GUID. :type developer_user_identifier: string :param developer_user_identifier: A unique ID used by your backend authentication process to identify a user. Typically, a developer identity provider would issue many developer user identifiers, in keeping with the number of users. :type max_results: integer :param max_results: The maximum number of identities to return. :type next_token: string :param next_token: A pagination token. The first call you make will have `NextToken` set to null. After that the service will return `NextToken` values as needed. For example, let's say you make a request with `MaxResults` set to 10, and there are 20 matches in the database. The service will return a pagination token as a part of the response. This token can be used to call the API again and get results starting from the 11th match. r5NrDDeveloperUserIdentifierrLrMLookupDeveloperIdentityr'r*)rr8rFdeveloper_user_identifierrOrPr2rrrlookup_developer_identityEs)z3CognitoIdentityConnection.lookup_developer_identitycC"||||d}|jdt|dS)a Merges two users having different `IdentityId`s, existing in the same identity pool, and identified by the same developer provider. You can use this action to request that discrete users be merged and identified as a single user in the Cognito environment. Cognito associates the given source user ( `SourceUserIdentifier`) with the `IdentityId` of the `DestinationUserIdentifier`. Only developer-authenticated users can be merged. If the users to be merged are associated with the same public provider, but as two different users, an exception will be thrown. :type source_user_identifier: string :param source_user_identifier: User identifier for the source user. The value should be a `DeveloperUserIdentifier`. :type destination_user_identifier: string :param destination_user_identifier: User identifier for the destination user. The value should be a `DeveloperUserIdentifier`. :type developer_provider_name: string :param developer_provider_name: The "domain" by which Cognito will refer to your users. This is a (pseudo) domain name that you provide while creating an identity pool. This name acts as a placeholder that allows your backend and the Cognito service to communicate about the developer provider. For the `DeveloperProviderName`, you can use letters as well as period (.), underscore (_), and dash (-). :type identity_pool_id: string :param identity_pool_id: An identity pool ID in the format REGION:GUID. )SourceUserIdentifierDestinationUserIdentifierr$r5MergeDeveloperIdentitiesr'r*)rsource_user_identifierdestination_user_identifierr0r8r2rrrmerge_developer_identitieszs%z4CognitoIdentityConnection.merge_developer_identitiescCrX)a Unlinks a `DeveloperUserIdentifier` from an existing identity. Unlinked developer users will be considered new identities next time they are seen. If, for a given Cognito identity, you remove all federated identities as well as the developer user identifier, the Cognito identity becomes inaccessible. :type identity_id: string :param identity_id: A unique identifier in the format REGION:GUID. :type identity_pool_id: string :param identity_pool_id: An identity pool ID in the format REGION:GUID. :type developer_provider_name: string :param developer_provider_name: The "domain" by which Cognito will refer to your users. :type developer_user_identifier: string :param developer_user_identifier: A unique ID used by your backend authentication process to identify a user. )rDr5r$rTUnlinkDeveloperIdentityr'r*)rrFr8r0rVr2rrrunlink_developer_identitysz3CognitoIdentityConnection.unlink_developer_identitycCs |||d}|jdt|dS)a` Unlinks a federated identity from an existing account. Unlinked logins will be considered new identities next time they are seen. Removing the last linked login will make this identity inaccessible. :type identity_id: string :param identity_id: A unique identifier in the format REGION:GUID. :type logins: map :param logins: A set of optional name-value pairs that map provider names to provider tokens. :type logins_to_remove: list :param logins_to_remove: Provider names to unlink from this identity. )rDr>LoginsToRemoveUnlinkIdentityr'r*)rrFrAlogins_to_remover2rrrunlink_identitysz)CognitoIdentityConnection.unlink_identitycCsP|||d}|dur||d<|dur||d<|dur||d<|jdt|dS)a_ Updates a user pool. :type identity_pool_id: string :param identity_pool_id: An identity pool ID in the format REGION:GUID. :type identity_pool_name: string :param identity_pool_name: A string that you provide. :type allow_unauthenticated_identities: boolean :param allow_unauthenticated_identities: TRUE if the identity pool supports unauthenticated logins. :type supported_login_providers: map :param supported_login_providers: Optional key:value pairs mapping provider names to provider app IDs. :type developer_provider_name: string :param developer_provider_name: The "domain" by which Cognito will refer to your users. :type open_id_connect_provider_ar_ns: list :param open_id_connect_provider_ar_ns: )r5r!r"Nr#r$r%UpdateIdentityPoolr'r*)rr8r-r.r/r0r1r2rrrupdate_identity_poolsz.CognitoIdentityConnection.update_identity_poolc Csd|j|f|jjdtt|d}|jdddi||d}|j|ddd}|d }t j ||j d kr@|r>t |SdSt |}|d d}|j||j} | |j |j|d ) Nz%s.%szapplication/x-amz-json-1.1)z X-Amz-TargetHostz Content-TypezContent-LengthPOST/)methodpath auth_pathr2headersdata )senderoverride_num_retrieszutf-8__type)r)) TargetPrefixrrstrlenbuild_base_http_request_mexereaddecodebotologdebugstatusrloadsget_faults ResponseErrorreason) rr(r)rm http_requestresponse response_body json_body fault_nameexception_classrrrr+s0        z&CognitoIdentityConnection.make_request)NNN)N)NN)NNNN)&__name__ __module__ __qualname____doc__ APIVersionrr ServiceNamertrrrr r r r rrrrrrr r3r9r;rBrGrKrQrSrWr^r`rdrfr+ __classcell__rrrrrsX   0   ?  5-" ,r) r{ boto.compatrboto.connectionrboto.regioninforboto.exceptionrboto.cognito.identityrrrrrrs