Google Play Game Services Sign-In¶
The purpose of this guide is for game makers to use Google Play Games Services with the Beamable Accounts feature.
Beamable integrates with Google Play Games Services to make it easy for users to sign in to your apps using their ID. Instead of filling out forms, verifying email addresses, and choosing new passwords, they can use a simple sign-in method to set up an account and start using your app right away. It makes it easy to use Beamable across different devices using one credential. A user always has the option to revoke access to an application at any time.
This document describes how to complete a basic Google Play Games Services integration.
Prerequisites
Before Google Sign-In will work properly, the Unity project must be configured to support GPGS as a third-party authentication provider. Make sure that GPGS is working correctly and the user can login to GPGS in-game before using it as third-party provider.
Getting Started¶
This guide provides step-by-step instructions to set up Google Play Game Services Sign-In with Beamable's Accounts feature in a Unity project.
Prerequisites¶
This guide assumes the following prerequisites have been completed:
| Steps | Details |
|---|---|
| 1. Unity: Set up the Beamable SDK for Unity | • See Beamable's Getting Started for more info |
| 2. Unity: Switch platform to Android | • Unity → File → Build Settings • Select Android then press Switch Platform |
| 3. Unity: Establish Keystore for Signing | • Unity → File → Build Settings • Press Player Settings... • In Inspector, go to Publishing Settings and create the keystore (or unlock an existing one). |
| 4. Android: Set up the corresponding Google Cloud Platform application with OAuth 2.0 credentials | • See Google's start-integrating#configure_a_project for more info Note: You will need both Web application credentials AND platform specific credentials for Android or iOS or both. |
Configure Beamable Platform¶
In orther to setup the Unity Project you need to Set the GPS Secret to Beamable Platform
- See Google's tutorial for how get client_secret.json and obtain Web client values.
- Go to Portal → Operate → Config and press Add Config and add config with namespace auth, key gps_secret and value that is encoded to base64 content of client_secret.json.
Additional iOS Setup¶
Make sure that your game flow takes into account the fact that iOS is not a supported platform by Google Play Game Services.
Google Play Game Services Integration¶
The Beamable SDK contains a wrapper for GPGS behavior on Android (iOS is not supported). The provided class is called SignInWithGPG, which can be initialized after following steps from Google documentation. It does contain two Actions that developer can subscribe to: OnLoginResult and OnRequestServerSideAccessResult. In order to perform login as third party to Beamable both of them must return successfully. The first returns info about local login, and the second about getting the server side access token that is required for the Beamable backend.
1 2 3 4 5 6 7 8 9 10 11 12 | |
After the Login process is started, the callback functions (HandleLoginResult and HandleRequestServerSideAccessResult) will be invoked with results:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
Handle Various Flow Scenarios¶
Now that we have the Google credential (token), we need to account for 3 different scenarios:
- New Player
- Returning Player already linked to Google
- Returning Player linking their account with Google
We can account for this by determining if we need to:
- Switch Player - Player wants to switch credentials to a new Player
- Create New Player - Player wants to Create a new Player account
- Attach To Current Player - Player wants to Attach this 3rd Party Login to an already authenticated Player.
Beamable SDK Initialization
The following assumes that you have initialized the Beamable SDK and it is stored in _beamContext variable.
1 2 | |
The following code will establish conditions for various flow scenarios.
1 2 3 4 5 6 7 8 9 10 11 12 | |
Next Steps¶
- Players can edit account details (name, avatar).
- Players can switch accounts or sign in with various methods. See the Identity feature page for more info.
