【发布时间】:2015-05-08 10:19:25
【问题描述】:
我正在使用This GoogleJsonWebToken 类来生成一个访问令牌,以便与对 Google 日历 API 的 json 调用一起使用。当我使用以下内容(使用我的实际服务帐户电子邮件)时,它在我的开发机器上的 IIS Express 中运行良好:
string p12Path = HttpContext.Current.Server.MapPath("~/App_Data/certificate.p12");
var auth = GoogleJsonWebToken.GetAccessToken("uniquestring@developer.gserviceaccount.com",
p12Path,
"https://www.googleapis.com/auth/calendar");
string Token = auth["access_token"];
为了测试这一点,我只是在我的 cshtml razor 视图中调用@Token。当我将此发布到我的 Azure 网站时,它不起作用。如果我不修改GoogleJsonWebToken 类,我会得到一个非常无用的502 - Web server received an invalid response while acting as a gateway or proxy server.,没有其他信息。
经过一些谷歌搜索后,我发现this SO post 这是一个类似的问题。所以我尝试了他们的解决方案,当从我的 Azure 网站运行时,我得到了System.Security.Cryptography.CryptographicException: The system cannot find the file specified.。当它从我的开发机器上运行时,我得到System.Net.WebException: The remote server returned an error: (400) Bad Request.,我认为这是因为使用该解决方案CspKeyContainerInfo.KeyContainerName 是null,而在我的开发机器上运行时原始未修改的类给了我类似{C0E26DC5-5D2C-4C77-8E40-79560F519588} 的东西,这是随机的每次生成,这个值在签名的过程中使用。
然后我找到了this SO post,但该解决方案产生的结果与上一个解决方案相同。
我也尝试了X509KeyStorageFlags 的大多数不同组合,但均无济于事。
我怎样才能自己生成CspKeyContainerInfo.KeyContainerName 或以其他方式成功生成X509Certificate2?
【问题讨论】:
标签: c# asp.net azure google-api