New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I do server authentication with Google Play Services #222
Comments
|
Actually, I get it working with just some changes in c# plugin code. First, you need to obtain accountName - thats not a PlayGamesPlatform.Instance.GetUserDisplayName() will return. I have added this code into GooglePlayGames.Android.AndroidClient (since it holds GameHelperManager internal class instance) and call it in AndroidClient.RetrieveUserInfo method private void RetrieveUserEmail() {
using (AndroidJavaClass jc_plus = new AndroidJavaClass("com.google.android.gms.plus.Plus")) {
using (AndroidJavaObject jo_plusAccountApi = jc_plus.GetStatic<AndroidJavaObject>("AccountApi")) {
mUserEmail = jo_plusAccountApi.Call<string>("getAccountName", mGHManager.GetApiClient());
Logger.d("Player email: " + mUserEmail);
}
}
}Next, get a token string getToken() {
string token = null;
string email = "email you get in some way from AndroidClient.mUserEmail ";
string scope = "audience:server:client_id:" + CLIENT_ID;
using (AndroidJavaClass jc_unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"),
jc_gau = new AndroidJavaClass("com.google.android.gms.auth.GoogleAuthUtil")) {
using(AndroidJavaObject jo_Activity = jc_unityPlayer.GetStatic<AndroidJavaObject>("currentActivity")) {
token = jc_gau.CallStatic<string>("getToken", jo_Activity, email, scope);
}
}
Debug.Log("Token " + token);
return token;
}The important part here is scope (see link above for details) and CLIENT_ID; you need to get OAuth2 Client ID for your web app in Google Developer Console, so android app can get tokens for your web app. Ah, dont forget to incluide Then you can POST token with other info to your server and verify; Keep in mind, this is correct for plugin version before doge release (which seems to use c++ sdk). |
|
I've managed to get this successfully working pre-Doge release, but would be great if there was some way to get it working out of the box and especially with the new version. |
|
Will there be any support for this in the next version? |
|
Consolidating the issues, so closing this as a duplicate of #181 |
|
Just curious, will this be added into an upcoming version of the unity plugin? The plugin works great for Android and IOS, so it would be wonderful to be able to use the leaderboards, saved games, and achievements without having to rewrite my games for the Unity Web Player. Thanks in advance for any information... |
|
whats the update anyone ? |
I'm trying to implement server authentication through Google Play Services. I need to log in a client and pass a token to a server so our server can verify the user is who they say they are. Currently I am able to get the user authenticated, but all I receive back is the full name and a userID.
This plugin doesn't seem to respond with a session token. How am I supposed to authenticate the user? Ideally, I would like to receive a token that I can pass to our server, and have our server confirm the session is valid with Google. Am I missing something?
The text was updated successfully, but these errors were encountered: