从 Google 身份验证服务为 .NET 中的 REST 服务检索新的 Firebase 访问令牌
Retrieving new Firebase access token for REST services in .NET from Google auth service
更改 firebase 授权系统后,我正在尝试从 google 身份验证服务器检索 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 特定 firebase 项目的开发人员控制台下载的密钥文件。
代码工作正常,但它 returns 令牌不适用于 firebase,我试过:
https://fiery-torch-xxxx.firebaseio.com/.json?access_token=retrived token
但我收到:
"error" : "Permission denied."
我做错了什么?或者我错过了什么?
我读了 docs,它指出 url
参数应该是 "auth" 而不是 "access_token"。你能试试吗?
我在范围内包含“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
更改 firebase 授权系统后,我正在尝试从 google 身份验证服务器检索 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 特定 firebase 项目的开发人员控制台下载的密钥文件。
代码工作正常,但它 returns 令牌不适用于 firebase,我试过:
https://fiery-torch-xxxx.firebaseio.com/.json?access_token=retrived token
但我收到:
"error" : "Permission denied."
我做错了什么?或者我错过了什么?
我读了 docs,它指出 url
参数应该是 "auth" 而不是 "access_token"。你能试试吗?
我在范围内包含“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