从用于Google API的Azure网站中的p12证书生成X509Certificate2时出现502错误

mhc*_*ner 12 c# asp.net google-api azure

我正在使用此类GoogleJsonWebToken生成一个访问令牌,用于对Google Calendar 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"];
Run Code Online (Sandbox Code Playgroud)

为了测试这个,我只是@Token在我的cshtml razor视图中调用.当我将其发布到我的Azure网站时,它不起作用.如果我不GoogleJsonWebToken修改我的课程,我会得到一个非常无益的502 - Web server received an invalid response while acting as a gateway or proxy server.,没有其他信息.

在一些谷歌搜索,我发现这个SO帖子是一个类似的问题.所以System.Security.Cryptography.CryptographicException: The system cannot find the file specified.当我从Azure网站运行时,我尝试了他们的解决方案.当它从我的开发机器上运行,我得到System.Net.WebException: The remote server returned an error: (400) Bad Request.我认为这是因为该解决方案的CspKeyContainerInfo.KeyContainerNamenull,而当我的dev的机器上运行未经修改的原始类的给我像{C0E26DC5-5D2C-4C77-8E40-79560F519588}每个时间是随机生成的这个值是在过程中使用签署签名.

然后我找到了这个SO帖子,但该解决方案产生的结果与上一个解决方案相同.

我也试过大多数不同的组合X509KeyStorageFlags无济于事.

如何生成CspKeyContainerInfo.KeyContainerName自己或以其他方式成功生成X509Certificate2

mhc*_*ner 21

我在这个MSDN论坛帖子上找到了解决方案.基本上我需要X509KeyStorageFlags.Exportable | X509KeyStorageFlags.MachineKeySet在我提到的第一篇SO帖子中设置,然后我需要Flags = CspProviderFlags.UseMachineKeyStore在我的CspParamaters中.

我已经在GitHub上发布了我的完整解决方案