更改了firebase授权系统后,我正在尝试从google auth服务器中检索c#中的访问令牌。
根据新文件:https://firebase.google.com/docs/reference/rest/database/user-auth#section-api-usage
我在c#中创建了类似的东西:
using Google.Apis.Auth.OAuth2;
[...]
async Task<string> GetToken()
{
GoogleCredential credential;
using (var stream = new System.IO.FileStream("gckey.json",
System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
credential = GoogleCredential.FromStream(stream).CreateScoped(
new string[] { "https://www.googleapis.com/auth/firebase.database" }
);
}
ITokenAccess c = credential as ITokenAccess;
return await c.GetAccessTokenForRequestAsync();
}
gckey.json是从Google Developer Console下载的特定firebase项目的密钥文件。
代码工作正常,但它返回不与firebase一起使用的令牌,我试过:
https://fiery-torch-xxxx.firebaseio.com/.json?access_token=retrived token
但我收到:
"error" : "Permission denied."
我做错了什么?或者我错过了什么?
答案 0 :(得分:5)
我在范围
中加入“https://www.googleapis.com/auth/userinfo.email”后,我才开始工作using Google.Apis.Auth.OAuth2;
[...]
async Task<string> GetToken()
{
GoogleCredential credential;
using (var stream = new System.IO.FileStream("gckey.json",
System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
credential = GoogleCredential.FromStream(stream).CreateScoped(
new string[] {
"https://www.googleapis.com/auth/firebase.database",
"https://www.googleapis.com/auth/userinfo.email" }
);
}
ITokenAccess c = credential as ITokenAccess;
return await c.GetAccessTokenForRequestAsync();
}
我在阅读以下google小组帖子时发现了这一点:
Permission denied error when using Google Oauth2 access token
答案 1 :(得分:1)
我读了docs并且它声明url
参数应该是“auth”而不是“access_token”。你能试试吗?