GetServerAuthCode,但我不能让它工作。
第一次获取idToken和AccessToken的正常过程,当您登录到firebase时获取用户的电子邮件和存储它在玩家偏好。然后第二次,如果你已经有这样的电子邮件:
AndroidJavaClass authUtil = new AndroidJavaClass(com.google.android .gms.auth.GoogleAuthUtil);
AndroidJavaClass unity = new AndroidJavaClass(com.unity3d.player.UnityPlayer);
AndroidJavaObject currentActivity = unity.GetStatic< AndroidJavaObject>(currentActivity);
string idToken = authUtil.CallStatic< string>(getToken,currentActivity,PlayerData.Email,audience:server:client_id:XXXXXXXXXX-xxxxxxxxxxxxxx.apps.googleusercontent.com); //你的客户端ID,应该是一个破折号,然后是一串数字和字母
string accessToken = authUtil.CallStatic< string>(getToken,currentActivity,PlayerData.Email,oauth2:https:/ /www.googleapis.com/auth/plus.me);
希望它有帮助,尽管这样可能会使用GetServerAuthCode发出解决方案, / p>
The new Firebase for Unity support has just been released into Beta and I am trying to implement Auth with it. I already have a Google sign-in that implements the oauth2 flow using an auth code from GooglePlayGames.PlayGamesPlatform.Instance.GetServerAuthCode
and sending it to a server that exchanges it for an access token using the https://www.googleapis.com/oauth2/v4/token
endpoint.
I assume this access token is the second parameter of the Firebase.Auth.GoogleAuthProvider.GetCredential
method, but what is the ID Token that the first parameter is asking for? Is that the token obtained from GooglePlayGames.PlayGamesPlatform.Instance.GetIdToken
(same as GoogleAuthUtil.GetToken
, if my reading of the docs/code is correct)?
If this is the case, why are both required? I thought the access token was all that was needed to authenticate a user with google cloud services and that the ID Token was being phased out.
Edit: After some testing, I found that passing the ID Token obtained from GooglePlayGames.PlayGamesPlatform.Instance.GetIdToken
does allow Firebase to authenticate. Problem is, it asks for the user's email address every time. I'd like to avoid this if possible.
What is the difference between GetToken
, GetAccessToken
and GetIdToken
, aside from the fact that GetIdToken
requires a callback?
解决方案
I managed to "hack" this in order to get it working... But still i think the correct method should only be using GetServerAuthCode but I cannot make it work with that.
Do your normal process of getting idToken and AccessToken the first time, when you log in to firebase get the user's email and store it in playerprefs. Then the second time if you already have the email you do this:
AndroidJavaClass authUtil = new AndroidJavaClass("com.google.android.gms.auth.GoogleAuthUtil");
AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
string idToken = authUtil.CallStatic<string>("getToken", currentActivity, PlayerData.Email, "audience:server:client_id:XXXXXXXXXX-xxxxxxxxxxxxxx.apps.googleusercontent.com"); // your client id, should be a number a dash and then a bunch of numbers and letters
string accessToken = authUtil.CallStatic<string>("getToken", currentActivity, PlayerData.Email, "oauth2:https://www.googleapis.com/auth/plus.me");
Hope it helps although it would be greatif someone posts a solution with GetServerAuthCode cause that is the correct way
这篇关于Firebase.Auth.GoogleAuthProvider.GetCredential的第一个参数是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!