Skip to content

Google Signin with AWS Cognito

0

Our games built using Unity, use Google Play Games Services v1 to support Google Signin. Once the player is signed in, token is obtained using: token = PlayGamesPlatform.Instance.GetIdToken(); and then it is passed to CognitoAWSCredentials: Credentials.AddLogin("accounts.google.com", token); This has been working fine. But now, Google Play Games Services v1 is deprecated and we must migrate to v2. However, v2 does provide the method PlayGamesPlatform.Instance.GetIdToken() anymore. How to obtain the necessary token when using Play Games Services v2?

asked a year ago155 views

1 Answer
0

When migrating from Google Play Games Services v1 to v2 for use with Amazon Cognito, you'll need to adapt your token retrieval approach since the PlayGamesPlatform.Instance.GetIdToken() method is no longer available in v2.

In Play Games Services v2, you'll need to use the new authentication flow to obtain an OpenID Connect authentication token that can be used with Amazon Cognito. After authenticating the user with Google Play services, you should request the authentication token directly from Google's authentication services.

The general approach would be:

  1. Authenticate the user using Play Games Services v2
  2. Use the Google Auth utility to retrieve the token with the appropriate scope
  3. Add this token to your Cognito credentials provider

Your code would look something like:

// After authenticating with Play Games Services v2
string token = GoogleAuthUtil.getToken(context, accountName, "audience:server:client_id:YOUR_GOOGLE_CLIENT_ID");

// Then use this token with Cognito
Credentials.AddLogin("accounts.google.com", token);

Make sure to replace YOUR_GOOGLE_CLIENT_ID with the client ID from your Google Developers console project. This token will allow Amazon Cognito to authenticate the user and generate a unique identifier, maintaining the same functionality you had with v1 but using the updated API methods from v2.

Remember that when working with the new API, you'll need to handle the authentication flow according to Google's updated documentation for Play Games Services v2, as the implementation details have changed from v1.
Sources
Setting up Google as an identity pool IdP - Amazon Cognito
Integration between Google sign in and Amazon Cognito | AWS re:Post
Getting credentials - Amazon Cognito

answered a year ago

  • Tried with the following code:

      GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(con);
      AccountManager am = AccountManager.get(con);
      Account[] accounts = am.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
      token = GoogleAuthUtil.getToken(con, accounts[0].name,
    

    However, accounts array is empty. Possibly because GoogleAuthUtil is deprecated ?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.