c# - 502 error when generating X509Certificate2 from p12 certificate in Azure Websites for Google API -


i'm using this googlejsonwebtoken class generate access token used json calls google calendar api. works fine in iis express on dev machine when use following (using actual service account email):

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"]; 

to test i'm calling @token in cshtml razor view. when publish azure website doesn't work. if leave googlejsonwebtoken class unmodified unhelpful 502 - web server received invalid response while acting gateway or proxy server. no other information.

after google searches found this post similar problem. tried solution system.security.cryptography.cryptographicexception: system cannot find file specified. when run azure website. when run dev machine system.net.webexception: remote server returned error: (400) bad request. think because solution cspkeycontainerinfo.keycontainername null whereas original unmodified class when run on dev machine gives me {c0e26dc5-5d2c-4c77-8e40-79560f519588} randomly generated each time , value used in process of signing signature.

i found this post solution yielded same results last solution.

i have tried of different combinations of x509keystorageflags no avail.

how can either generate cspkeycontainerinfo.keycontainername myself or otherwise generate x509certificate2?

i found solution on this msdn forum post. needed set x509keystorageflags.exportable | x509keystorageflags.machinekeyset read in first post mentioned , needed flags = cspproviderflags.usemachinekeystore in cspparamaters.

i have posted full solution on github


Comments