【发布时间】:2022-08-15 20:55:08
【问题描述】:
我现在正在处理从 Unity Editor 到 Firebase Cloud Messaging 和 Firebase Realtime Database 的 Rest API 调用。我用来创建具有多个分数的令牌的代码在哪里。
private static readonly string[] _scores = new[]
{
\"https://www.googleapis.com/auth/userinfo.email\",
\"https://www.googleapis.com/auth/firebase.database\",
\"https://www.googleapis.com/auth/firebase.messaging\"
};
public string CreateToken(DateTimeOffset now, string[] scores)
{
var nowSeconds = now.ToUnixTimeSeconds();
var inOneHour = GetExpirationTime(now);
var scope = string.Join(\",\", scores);
var payload = new Dictionary<string, object>
{
{ \"iss\", _serviceAccountData.ClientEmail },
{ \"scope\", scope },
{ \"aud\", _serviceAccountData.TokenUri },
{ \"iat\", nowSeconds },
{ \"exp\", inOneHour }
};
return SignToken(payload);
}
但这不起作用,调用https://fcm.googleapis.com/v1/projects/{0}/messages:send 返回401未经授权.如果我只传递https://www.googleapis.com/auth/firebase.messaging 作为范围,一切正常。但我仍然需要调用 firebase 实时数据库。是否可以使用相同的不记名令牌调用这两个 API 还是我需要有 2 个不同的令牌才能实现这种行为?
我在项目中有“firebase_admin_sdk.json”和Jose.JWT 来签署请求。
-
我的猜测是 2 个不同的主机名意味着 2 个不同的令牌。
-
是的,我也想过这个问题,但对我来说有点奇怪,因为 OAuth 服务器用有效的令牌响应我们。
-
嗯,它是。对于 www.googleapis..... 不适合 fcm.google..... 也许
-
我为实时数据库制作了单独的模块并按照here 的描述创建了令牌(但使用 Jose-jwt 进行签名)但仍然出现错误 401。我像以前一样提供来自
firebase_admin_sdk.json的数据。
标签: unity3d firebase-realtime-database firebase-authentication firebase-cloud-messaging unity-editor