Amazon Developer

as

Settings
Sign out
Notifications
Alexa
Amazon Appstore
Ring
AWS
Documentation
Support
Contact Us
My Cases
Develop
Test
Publish
Monetize
Engage users
Device specifications
Resources
Skip to main content
Use this guide to integrate your app with the A3L Authentication SDK.

Setup A3L Authentication sign-in

To integrate A3L Authentication into your Android app, you must configure A3L Authentication and add a button to start the sign-in flow.

Initialize A3L Authentication

In your sign-in activity’s onCreate() method, initialize A3L Authentication, providing the Android client ID you got from the Google API Console, as shown in the following code.
The default solution for devices with Google Play services is Google Sign-In. Devices without Google Play services default to AppAuth. If you prefer to provide a similar experience to users and use AppAuth as the solution on all devices, initialize your app as shown in the following code.

Configure A3LSignIn and A3LSignInClient objects

Next, configure the A3LSignIn and A3LSignInClient objects by following these steps.
  1. In the onCreate() method, configure A3L Authentication to request the user data that your app requires through an A3LSignInOptions object. For example, to configure A3L Authentication to request a user’s ID and basic profile information, build an A3LSignInOptions object using the DEFAULT_SIGN_IN parameter. If you want to also request a user’s email address, include the requestEmail() option when you create the A3LSignInOptions object, as shown here.
  2. In the onCreate() method, create an A3LSignInClient object using the options you specified in the A3LSignInOptions object that you created in the previous step, as shown in the following code.

Check for a signed-in user

Before displaying the sign-in flow, check if the user is already signed in to the app by using the getLastSignedInAccount() method. In your activity’s onStart() method, check if the user is already signed in, as shown in this example.
If a non-null A3LSignInAccount object is returned, it means the user is already signed in to the app and you don’t have to prompt them again. You can progress the user to your app’s post sign-in experience. If null is received, that means the user is not signed in to the app. Provide the sign-in button for the user to sign in to the app.

Add a sign-in button to your app

You can create a custom sign-in button for your app, but if you want to use the default sign-in button provided by Google, follow the steps listed below.
  1. Add the sign-in button in your app layout.
  2. In the Android activity, add an OnClickListener to the button. For example, you can add the following code in the onCreate() method.
    When a user clicks this button, your app start the sign-in flow, described in the next section.

Handle sign-in

Sign in the user with these steps.
  1. In the activity’s onClick() method, handle the case when a user presses the sign-in button.
    In the signIn() method, create a sign-in intent using the getSignInIntent() method. Start the intent with the startActivityForResult() method as shown here.
    Starting the intent has different behavior depending on the device the app is run on. For an Android device that supports Google Play services, the user is prompted, within the app, to select an account to sign in with. For devices without Google Play services, the app opens a Custom Tab and redirects the user to Google’s authentication webpage. In both cases, the user is prompted to select a Google account to sign in with, or to enter the email address that they want to sign in with.
  2. In the onActivityResult() method, use the A3LSignIn.getSignedInAccountFromIntent() method to get a task that will return a A3LSignInAccount object when successful, as shown here.
    The implementation of the handleSignInResult() method follows. The resulting A3LSignInAccount object contains information about the signed-in user, such as their name.
    To access user data from the A3LSignInAccount object, use the following methods:
    • getEmail() to get the user’s email address
    • getId() to get the user’s Google ID for client-side use
    • getIdToken() to get an ID token for the user
    To pass the currently signed-in user to a back-end server, send the ID token to your back-end server and validate the token on the server.

Access user profile information

How you configured the A3LSignInOptions object in Configure A3LSignIn and A3LSignInClient objects determines which information you can access from the signed-in user. If you configured A3LSignInOptions with the DEFAULT_SIGN_IN parameter or the requestProfile() method, you can access the user’s basic profile information after they sign in. If you configured A3LSignInOptions with the requestEmail() method, you can also access the user’s email address. To request profile information for the currently signed-in user, use the A3LSignIn.getLastSignedInAccount() method, as shown in the following example.
To see all potential fields that you can access from an A3LSignInAccount object, see the A3L Authentication API Reference.

Sign out users

Provide a way for users to sign out of your app by adding a sign-out button. After you create a sign-out button, attach an OnClickListener to the button and configure the onClick() method to call the signOut() method, as shown in the following code.
When your app runs this code, the user’s Google account is signed out of your app. The user can choose to sign in again with their Google account without any prompts for permissions, such as requesting access to specified scopes.

Disconnect accounts

Provide users with the ability to disconnect their Google account from your app. If a user chooses to disconnect their account from your app, you must delete the information that your app obtained from Google’s APIs. When you revoke access, it removes the permissions that the user has given to your app to access their data through the scopes. To disconnect a user’s account, call the revokeAccess() method, as shown in the following example.
In the OnCompleteListener, your app can respond to the event and run any additional required code.

Authenticate with a back-end server

If you’re using A3L Authentication and your app communicates with a back-end server, you might need to identify the currently signed-in user on the server. To securely identify the currently signed-in user, use HTTPS to send the user’s ID token to your server. On the server, verify the integrity of the ID token. Use the user data from the token to establish a session with a known user or to create a new account record for a new user.

Fetch the ID token

First, you must fetch the user’s ID token when they sign in. Configure A3L Authentication with the requestIdToken() method and pass your server’s web client ID to this method, as shown here.
When the user signs in, get the A3LSignInAccount object from the activity result of the sign-in intent:
After the user signs in, get the ID token from the A3LSignInAccount object, as shown here.

Send the ID token to your server

Use an HTTPS POST request to send the ID token to your server, as shown here.
After you fetch the ID token, validate it by following the instructions in Google’s developer documentation, Verify the integrity of the ID token.
Last modified on December 5, 2023