我在 iOS 设备上使用 Firebase App Check 时遇到 401 错误,需要帮助识别问题。
我们正在使用 Firebase App Check 来保护我们的后端 API。 Android 上的设置成功,一切都按预期进行。然而,我们在 iOS 设置方面遇到了困难。在 iOS 上使用调试令牌时,App Check 工作正常,但切换到生产会导致 401 错误。
我们已经尝试过:
我们已经在 Xcode 中配置了 App Attest,将环境设置为“生产”。
作为替代方案,我们也尝试使用DeviceCheck,但遇到了同样的问题。
可能的问题:
Apple 开发者帐户端可能存在配置错误,例如缺少功能或配置文件存在问题。
也可能是我们的 Xcode 项目配置有错误,或者我们的 Firebase App Check 集成代码有错误。
有人可以指导我们可能做错了什么吗? Apple Developer 端或 Xcode 中是否有需要我们验证的特定设置或配置?
或者问题是否出在我们在 iOS 上集成 Firebase App Check 的代码设置? 任何建议或指示将不胜感激!
Unity 2022.3.34f1
Firebase 12.0.0
Xcode 15.4
Firebase Cloud Function
verifications: {
app: "MISSING"
auth: "VALID"
}
// Logs
2:Firebase.Functions.FunctionsException: Unauthenticated
at Firebase.Functions.HttpsCallableReference.<CallAsync>b__9_0 (System.Threading.Tasks.Task`1[TResult] task) [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2[TAntecedentResult,TResult].InnerInvoke () [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.Tasks.Task.Execute () [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.Tasks.Task.ExecuteWithThreadLocal (System.Threading.Tasks.Task& currentTaskSlot) [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.Tasks.Task.ExecuteEntry (System.Boolean bPreventDoubleExecution) [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00000] in <00000000000000000000000000000000>:0
--- End of stack trace from previous location where exception was thrown ---
at TestScript.CheckHash () [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
<CheckHash>d__4:MoveNext()
UnityEngine.UnitySynchronizationContext:Exec()
using System;
using System.Collections;
using System.Collections.Generic;
using _Car_Parking.Scripts.Database;
using Cysharp.Threading.Tasks;
using Firebase.AppCheck;
using Firebase.Functions;
using UnityEngine;
public class TestScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
FirebaseInitializer firebaseInitializer = new FirebaseInitializer();
firebaseInitializer.Initialize();
}
public void Check()
{
CheckHash().Forget();
}
public void GenerateApp()
{
GenerateAppAttest().Forget();
}
private async UniTaskVoid GenerateAppAttest()
{
FirebaseAppCheck.SetAppCheckProviderFactory(AppAttestProviderFactory.Instance);
Debug.Log("Generrate AppattestToken");
}
private async UniTaskVoid CheckHash()
{
try
{
Debug.Log("result1 start");
var r = FirebaseFunctions.DefaultInstance.GetHttpsCallable("PrintHash");
await r.CallAsync("");
Debug.Log("result1:" + r);
}
catch (Exception e)
{
Debug.LogError("1:" + e);
}
try
{
Debug.Log("result2 start");
var r = FirebaseFunctions.DefaultInstance.GetHttpsCallable("PrintHash2");
await r.CallAsync("");
Debug.Log("result2:" + r);
}
catch (Exception e)
{
Debug.LogError("2:" + e);
}
}
}
原来是我们的 Apple Team ID 不同,导致了这个问题。