Unity中的Firebase身份验证拒绝“使用Apple登录”令牌

时间:2020-01-17 10:42:35

标签: ios firebase unity3d firebase-authentication

我正在使用Firebase Unity。我的应用程序需要支持“使用Apple登录”才能批准进入App Store。

firebase官方说明要求深入了解本机代码。对我而言,实现这一点并编写代码以与Unity进行交流对我而言并非难事。 https://firebase.google.com/docs/auth/ios/apple

Unity实施了易于使用的“使用Apple登录”插件 https://blogs.unity3d.com/2019/09/19/support-for-apple-sign-in/

直到我尝试将OAuth与Firebase结合使用,Apple Sign In才能在Unity级别运行。使用该凭据登录会被拒绝:

db.collection.aggregate([
    { '$match': { '_id': "xyz" } },
    { '$addFields': {
        'fields': {
            '$filter': {
                'input': '$fields',
                'cond': {
                    '$and': [
                        { '$ne':  [ { '$type' : "$$this.v.B" }, 'missing'] },
                        { '$gt': [ "$$this.v.B", 10 ] }
                    ]
                }
            }
        }
    } },
    { '$addFields': {
        'start_times': '$fields.v.start' 
    } }
])

我很好地知道idToken是什么(Unity的db.collection.aggregate([ # convert root dynamic fields to key/value pair array { '$addFields': { 'fields': { '$objectToArray': '$$ROOT' } } }, # filter all documents where size of array of Bs >= 1 { '$match': { '$expr': { '$gte': [ { '$size': '$fields.v.B' }, 1 ] } } }, # get array of _ids { '$addFields': { 'ids': { '$filter': { 'input': '$fields', 'cond': { '$eq': [ '$$this.k', '_id' ] } } } } }, # reshape field { '$addFields': { 'ids': '$ids.v' } } ]) ),但是accessToken尚不清楚。我觉得我很亲近。如果我可以就下一步的搜索要求获得建议,我将不胜感激!

2 个答案:

答案 0 :(得分:0)

您正在阅读错误的页面!

带有本机代码的是您直接为iOS实现的。那不是你在做什么。您正在为Unity实现c#,因此必须阅读Unity SDK的Get StartedAPI


但是,通过Apple提供登录所需的应用实际上是通过Apple商店直接 ! Unity为此专门设置了Asset

答案 1 :(得分:0)

2020年1月30日发布的Firebase 6.10.0使我能够解决此问题!

OAuthProvider.GetCredential()现在具有方法重载,需要“立即执行”,这是完成Apple登录验证服务器所必需的。

我修改了流行的Apple Sign In Unity项目,以生成一个“ nonce”值并将其公开给Unity代码。在撰写本文时,有一个active pull request及其(快速而肮脏的)实现。看起来,在将代码合并到主项目之前,将对其进行大量重构。

实施修改后的Apple Sign In Unity项目后,获得证书非常简单:

_appleAuthManager.LoginWithAppleId(
        LoginOptions.IncludeEmail | LoginOptions.IncludeFullName,
        (credential) =>
        {
            // success
            var appleIDCredential = credential as IAppleIDCredential;
            string authCode = System.Text.Encoding.UTF8.GetString(appleIDCredential.AuthorizationCode);
            string idToken = System.Text.Encoding.UTF8.GetString(appleIDCredential.IdentityToken);
            string rawNonce = _appleAuthManager.RawNonce;
            Credential credential = OAuthProvider.GetCredential("apple.com", idToken, rawNonce, authCode);
        },
        (error) =>
        {
            Debug.LogWarning("Sign in with Apple failed: " + error.ToString());
        });