Firebase.Auth.GoogleAuthProvider.GetCredential的第一个参数是什么? [英] What is the first parameter for Firebase.Auth.GoogleAuthProvider.GetCredential?

查看:630
本文介绍了Firebase.Auth.GoogleAuthProvider.GetCredential的第一个参数是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新的Firebase for Unity支持刚刚发布到Beta版中,我试图用它来实现Auth。我已经有一个Google登录,它使用来自 GooglePlayGames.PlayGamesPlatform.Instance.GetServerAuthCode 的授权码实现oauth2流,并将其发送到交换访问权限的服务器令牌使用 https://www.googleapis.com/oauth2/v4/token 端点。



我假设此访问令牌是 Firebase.Auth.GoogleAuthProvider.GetCredential 方法的第二个参数,但第一个参数要求的ID令牌是什么?是从 GooglePlayGames.PlayGamesPlatform.Instance.GetIdToken (与 GoogleAuthUtil.GetToken 相同,如果我阅读docs / code是正确的)?

如果是这样的话,为什么都需要?我认为访问令牌是用谷歌云服务验证用户所需要的,并且ID令牌正在被淘汰。



编辑:经过一些测试,我发现传递从 GooglePlayGames.PlayGamesPlatform.Instance.GetIdToken 获取的ID令牌确实允许Firebase进行身份验证。问题是,它每次都要求用户的电子邮件地址。

GetToken , GetAccessToken 和 GetIdToken ,除了 GetIdToken 需要回调吗?解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆