问题描述
我正在尝试使用 OAuth2.0 和 C# 以及来自 Google 的 JSON 文件简单地对 Google Cloud Storage API 进行身份验证。
这是我的 OAuth JSON 文件:
{
"client_id": "ClientIdHere","project_id": "ProjectName","auth_uri": "https://accounts.google.com/o/oauth2/auth","token_uri": "https://oauth2.googleapis.com/token","auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs","client_secret": "ClientSecretHere","redirect_uris": [ "https://localhost:44349//RedirectPage.aspx" ]
}
借来的
protected void DoTheThingsAgain()
{
try
{
string bucketName = "Daves-Bucket";
string sharedkeyFilePath = "C:\\inetpub\\wwwroot\\GoogleAPITest\\GoogleAPITest\\App_Data\\JSONFile.json";
GoogleCredential credential = null;
using (var jsonStream = new FileStream(sharedkeyFilePath,FileMode.Open,FileAccess.Read,FileShare.Read))
{
credential = GoogleCredential.FromStream(jsonStream);
}
}
catch (Exception ex)
{
throw ex;
}
}
一切正常,直到碰到这一行:
**credential = GoogleCredential.FromStream(jsonStream);**
然后它给了我错误:从 JSON 创建凭证时出错。无法识别的凭据类型。
如何为 OAuth 指定凭据类型?
我已经看到了其他解决方案,但在使用 OAuth 时没有,只有使用 ServiceAccounts。
请提前为您提供任何帮助!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)