Hey.
For authentication in unity using gamesparks, it is recommended to use "access token"
But in the latest version of the plugin "Google Play Games plugin for Unity" removed the method
"PlayGamesPlatform.Instance.GetAccessToken ()"
Please, tell me, how I can get "AccessToken" by other methods.
cause PlayGamesPlatform.Instance.GetIdToken(); and PlayGamesPlatform.Instance.GetServerAuthCode();
always return null whyyyyyy plz help
and here is my code to sign in new player
public void GooglePlaySignIn()
{
Social.localUser.Authenticate((bool success) =>
{
if (success)
{
string token = PlayGamesPlatform.Instance.GetIdToken();
new GameSparks.Api.Requests.GooglePlusConnectRequest()
.SetAccessToken(token)
.SetRedirectUri("http://www.gamesparks.com/oauth2callback")
.SetDoNotLinkToCurrentPlayer(false)
.SetSwitchIfPossible(true)
.Send((Google_response) =>
{
if (!Google_response.HasErrors)
{
OnAuthentication(Google_response);
}
else
{
Debug.LogWarning(Google_response.Errors.JSON);//if we have errors, print them out
}
});
}
else
Debug.Log("no");
});
Thanks
AccessToken was removed from Google Sign-In because it is vulnerable to man-in-the-middle attacks. You need to use either the ID token, or request a server auth code, and then exchange that for an access token.
i got it thank you for reply
how did u get it? didnt they return null?
hi
fisrt in Start Function i did that
` void Start () {
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.RequestServerAuthCode(false)
.RequestIdToken()
.RequestEmail()
.Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.Activate();
}
the once the player auth with google i called GetServerAuthCode() function like that
public void GoogleSignIn()
{
Social.localUser.Authenticate((bool success) =>
{
if (success)
{
PlayGamesPlatform.Instance.GetServerAuthCode();
Debug.Log("yes");
Debug.Log("Local user's email is " + ((PlayGamesLocalUser)Social.localUser).Email);
}
else
Debug.Log("no");
});
}`
and its will not return null you can debug the email or idToken or serverCode
now i didnt use setAccessToken() to make the authentication with gamesparks (my server ) i used setCode() and the server will get the access token from google's servers
Hello @bibooo,
I'm having difficulty authenticating through GameSparks with Google Play. I did what you showed above and still received an error from GameSparks. Is this the correct way to sign in to GameSparks after authenticating successfully from Google Play? I get an error saying "accessToken|code":"REQUIRED".
`Social.localUser.Authenticate((bool success) =>
{
if (success)
{
new GooglePlayConnectRequest()
.SetCode(PlayGamesPlatform.Instance.GetServerAuthCode())
.SetRedirectUri("http://www.gamesparks.com/oauth2callback")
.Send((response) => {
if (!response.HasErrors)
{
Debug.Log("yes");
}
else
{
Debug.LogWarning(response.Errors.JSON);//if we have errors, print them out
}
});
}
});
}`
hey @bibooo ,
I am doing same as you did but if I uncomment the code "PlayGamesPlatform.Activate ();" then it show login failed. But if I comment this line of code then login became successful but I am not getting servauthcode and not even IdToken.
Here is my code for this :
`void Start(){
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder ()
.RequestServerAuthCode (false)
.RequestIdToken ()
.RequestEmail ()
.Build ();
PlayGamesPlatform.InitializeInstance (config);
// PlayGamesPlatform.DebugLogEnabled = true;
// PlayGamesPlatform.Activate ();
GS.GameSparksAvailable += OnGameSparksConnected;
}
public void GooglePlusLogin()
{
Social.localUser.Authenticate((bool success) => {
if(success) { //this works just fine.
Debug.Log("Successfully Logged in!");
DebugText.text += "success";
googleIdToken = PlayGamesPlatform.Instance.GetServerAuthCode();
googleAccessToken = PlayGamesPlatform.Instance.GetIdToken();
DebugText.text = googleIdToken;
} else{
Debug.Log("Login Failed!");
DebugText.text += "failed";
}
});
}`
GetServerAuthCode and GetIdToken return Null or Empty string.
Any idea?
I cant believe how confusing is this procedure.
I wasted a week reading too much and I still cant get an email.
@Spirit30 @ChinchillaReactor here was my process which ended up working:
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
// Google Play Request
.RequestServerAuthCode(false)
.Build();
// Initiate Configuration
PlayGamesPlatform.InitializeInstance(config);
// Recommended for debugging:
PlayGamesPlatform.DebugLogEnabled = true;
// Select the Google Play Games platform as our social platform implementation
PlayGamesPlatform.Activate();
// Authenticate
Social.localUser.Authenticate((bool success) =>
{
if(success)
{
string code = PlayGamesPlatform.Instance.GetServerAuthCode();
new GooglePlayConnectRequest()
.SetCode(code)
.SetRedirectUri("http://www.gamesparks.com/oauth2callback")
.Send((response) => {
if (!response.HasErrors)
{
}
});
}
});
Most helpful comment
hi
fisrt in Start Function i did that
` void Start () {
if (UNITY_IPHONE || UNITY_ANDROID)
endif
}
the once the player auth with google i called GetServerAuthCode() function like thatpublic void GoogleSignIn(){
and its will not return null you can debug the email or idToken or serverCode
now i didnt use setAccessToken() to make the authentication with gamesparks (my server ) i used setCode() and the server will get the access token from google's servers