M_B
M_B

Reputation: 103

deploying identityserver 4 to azure app service

When deploying a blazor app that contains identityserver 4 to an azure app service, i get the following exception:

Exception Info: System.InvalidOperationException: There was an error loading the certificate. Either the password is incorrect or the process does not have permisions to store the key in the Keyset 'DefaultKeySet'

The certificate comes from azure keyvault and locally there are no issues. Below the code I use to call the cert and load it into the identityserver signingcredentials:

var pfx = Configuration["certname"];
var bytes = Convert.FromBase64String(pfx);
var certificate2Collection = new X509Certificate2Collection();
certificate2Collection.Import(bytes, null, X509KeyStorageFlags.UserKeySet);

services.AddIdentityServer()
.AddSigningCredential(certificate2Collection[0]);

Any thoughts on how to fix this?

Upvotes: 2

Views: 778

Answers (1)

M_B
M_B

Reputation: 103

A lot of searching gave me the answer.

I needed to do 2 things.

First I needed to add the certificate in the service app on azure: azure app service certificate

Then in the configuration of the service app, I needed to add an application setting: WEBSITE_LOAD_CERTIFICATES with the cert thumbprint as value: azure app service application settings

After that the certificate was found without a problem.

Upvotes: 1

Related Questions