Sign in with Apple (identity pools)
Amazon Cognito integrates with Sign in with Apple to provide federated authentication for your mobile application and web application users. This section explains how to register and set up your application using Sign in with Apple as an identity provider (IdP).
To add Sign in with Apple as an authentication provider to an identity pool, you must complete two procedures. First, integrate Sign in with Apple in an application, and then configure Sign in with Apple in identity pools.
Set up Sign in with Apple
To configure Sign in with Apple as an IdP, register your application with the Apple to receive client ID.
-
Create a developer account with Apple
. -
Sign in
with your Apple credentials. -
In the left navigation pane, choose Certificates, IDs & Profiles.
-
In the left navigation pane, choose Identifiers.
-
On the Identifiers page, choose the +icon.
-
On the Register a New Identifier page, choose App IDs, and then choose Continue.
-
On the Register an App ID page, do the following:
-
Under Description, type a description.
-
Under Bundle ID, type an identifier. Make a note of this Bundle ID as you need this value to configure Apple as a provider in the identity pool.
-
Under Capabilities, choose Sign In with Apple, and then choose Edit.
-
On the Sign in with Apple: App ID Configuration page, select the appropriate setting for your app. Then choose Save.
-
Choose Continue.
-
-
On the Confirm your App ID page, choose Register.
-
Proceed to step 10 if you want to integrate Sign in with Apple with a native iOS application. Step 11 is for applications that you want to integrate with Sign in with Apple JS.
-
On the Identifiers page, choose the App IDs menu, then Services IDs. Choose the + icon.
-
On the Register a New Identifier page, choose Services IDs, and then choose Continue.
-
On the Register a Services ID page, do the following:
-
Under Description, type a description.
-
Under Identifier, type an identifier. Make a note of the services ID as you need this value to configure Apple as a provider in your identity pool.
-
Select Sign In with Apple and then choose Configure.
-
On the Web Authentication Configuration page, choose a Primary App ID. Under Website URLs, choose the + icon. For Domains and Subdomains, enter the domain name of your app. In Return URLs, enter the callback URL where the authorization redirects the user after they authenticate through Sign in with Apple.
-
Choose Next.
-
Choose Continue, and then choose Register.
-
-
In the left navigation pane, choose Keys.
-
On the Keys page, choose the + icon.
-
On the Register a New Key page, do the following:
-
Under Key Name, type a key name.
-
Choose Sign In with Apple, and then choose Configure.
-
On the Configure Key page, choose a Primary App ID and then choose Save.
-
Choose Continue, and then choose Register.
-
Note
To integrate Sign in with Apple with a native iOS application, see Implementing User Authentication with Sign in with Apple.
To integrate Sign in with Apple in a platform other than native iOS, see Sign in with Apple JS.
Configure the external provider in the Amazon Cognito federated identities console
Use the following procedure to configure your external provider.
Sign in with Apple as a provider in the Amazon Cognito federated identities CLI examples
This example creates an identity pool named MyIdentityPool
with Sign in
with Apple as an IdP.
aws cognito-identity create-identity-pool --identity-pool-name MyIdentityPool
--supported-login-providers appleid.apple.com="sameple.apple.clientid"
For more information, see Create identity pool
Generate an Amazon Cognito identity ID
This example generates (or retrieves) an Amazon Cognito ID. This is a public API so you don't need any credentials to call this API.
aws cognito-identity get-id --identity-pool-id SampleIdentityPoolId --logins
appleid.apple.com="SignInWithAppleIdToken"
For more information, see get-id.
Get credentials for an Amazon Cognito identity ID
This example returns credentials for the provided identity ID and Sign in with Apple login. This is a public API so you don't need any credentials to call this API.
aws cognito-identity get-credentials-for-identity --identity-id SampleIdentityId
--logins appleid.apple.com="SignInWithAppleIdToken"
For more information, see get-credentials-for-identity
Use Sign in with Apple: Android
Apple doesn't provide an SDK that supports Sign in with Apple for Android. You can use the web flow in a web view instead.
-
To configure Sign in with Apple in your application, follow Configuring Your Web page for Sign In with Apple
in the Apple documentation. -
To add a Sign in with Apple button to your Android user interface, follow Displaying and Configuring Sign In with Apple Buttons
in the Apple documentation. -
To securely authenticate users with Sign in with Apple, follow Authenticating Users with Sign in with Apple
in the Apple documentation.
Sign in with Apple uses a session object to track its state. Amazon Cognito uses the ID token from this session object to authenticate the user, generate the unique identifier, and, if needed, grant the user access to other AWS resources.
@Override public void onSuccess(Bundle response) { String token = response.getString("id_token"); Map<String, String> logins = new HashMap<String, String>(); logins.put("appleid.apple.com", token); credentialsProvider.setLogins(logins); }
Use Sign in with Apple: iOS - Objective-C
Apple provided SDK support for Sign in with Apple in native iOS applications. To
implement user authentication with Sign in with Apple in native iOS devices, follow Implementing User Authentication with Sign in with Apple
Amazon Cognito uses the ID token to authenticate the user, generate the unique identifier, and, if needed, grant the user access to other AWS resources.
(void)finishedWithAuth: (ASAuthorizationAppleIDCredential *)auth error: (NSError *) error { NSString *idToken = [ASAuthorizationAppleIDCredential objectForKey:@"identityToken"]; credentialsProvider.logins = @{ "appleid.apple.com": idToken }; }
Use Sign in with Apple: iOS - Swift
Apple provided SDK support for Sign in with Apple in native iOS applications. To
implement user authentication with Sign in with Apple in native iOS devices, follow Implementing User Authentication with Sign in with Apple
Amazon Cognito uses the ID token to authenticate the user, generate the unique identifier, and, if needed, grant the user access to other AWS resources.
For more information about how to set up Sign in with Apple in iOS, see Set up Sign in with Apple
func finishedWithAuth(auth: ASAuthorizationAppleIDCredential!, error: NSError!) { if error != nil { print(error.localizedDescription) } else { let idToken = auth.identityToken, credentialsProvider.logins = ["appleid.apple.com": idToken!] } }
Use Sign in with Apple: JavaScript
Apple doesn’t provide an SDK that supports Sign in with Apple for JavaScript. You can use the web flow in a web view instead.
-
To configure Sign in with Apple in your application, follow Configuring Your Web page for Sign In with Apple
in the Apple documentation. -
To add a Sign in with Apple button to your JavaScript user interface, follow Displaying and Configuring Sign In with Apple Buttons
in the Apple documentation. -
To securely authenticate users through Sign in with Apple, follow Configuring Your Web page for Sign In with Apple
in the Apple documentation.
Sign in with Apple uses a session object to track its state. Amazon Cognito uses the ID token from this session object to authenticate the user, generate the unique identifier, and, if needed, grant the user access to other AWS resources.
function signinCallback(authResult) { // Add the apple's id token to the Amazon Cognito credentials login map. AWS.config.credentials = new AWS.CognitoIdentityCredentials({ IdentityPoolId: 'IDENTITY_POOL_ID', Logins: { 'appleid.apple.com': authResult['id_token'] } }); // Obtain AWS credentials AWS.config.credentials.get(function(){ // Access AWS resources here. }); }
Use Sign in with Apple: Xamarin
We don’t have an SDK that supports Sign in with Apple for Xamarin. You can use the web flow in a web view instead.
-
To configure Sign in with Apple in your application, follow Configuring Your Web page for Sign In with Apple
in the Apple documentation. -
To add a Sign in with Apple button to your Xamarin user interface, follow Displaying and Configuring Sign In with Apple Buttons
in the Apple documentation. -
To securely authenticate users through Sign in with Apple, follow Configuring Your Web page for Sign In with Apple
in the Apple documentation.
Sign in with Apple uses a session object to track its state. Amazon Cognito uses the ID token from this session object to authenticate the user, generate the unique identifier, and, if needed, grant the user access to other AWS resources.
After you have the token, you can set it in your
CognitoAWSCredentials
:
credentials.AddLogin("appleid.apple.com", token);