Blazor webassembly with Authentication in production

Cristóvão Morgado 101 Reputation points

I'm deploying a blazor app hosted with authentication (just use the default template in visual studio)

As such I'm changing my appsettins.production.jon to:

 "Key": {
      "Type": "File",
      "FilePath": "",
      "Password": "mysuperpassword"

I have the file on the root and when I try to login, I always get "There was an error trying to log you in: '' "

Everything works fine on my computer either with IIS express or Kestrel.

Looking at logs I found out the tat it says file not found
An unhandled exception has occurred while executing the request.
Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: The system cannot find the file specified.

Is there any tip on how to get this working? I cannot use the

"Key": {
  "Type": "Store",
  "StoreName": "My",
  "StoreLocation": "LocalMachine",
  "Name": "CN=SigningCertificate"

due to hosting limitations.

A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,372 questions
A set of technologies in the .NET Framework for building web applications and XML web services.
3,237 questions
{count} votes

Accepted answer
  1. Cristóvão Morgado 101 Reputation points

    Well, I found the solution...
    It's in fact simple

       var identityBuilder = services.AddIdentityServer();
                        .AddApiAuthorization<ApplicationUser, ApplicationDbContext>(options =>
                            options.IdentityResources["openid"].UserClaims.Add("role"); // Roles
                            options.IdentityResources["openid"].UserClaims.Add("custom_claim"); // Custom Claim
                            options.IdentityResources["openid"].UserClaims.Add("custom_claim2"); // Custom Claim
                            options.IdentityResources["openid"].UserClaims.Add("Application.Permission"); // Custom Claim
                    var key = new RsaSecurityKey(RSA.Create(2048))
                        KeyId = Guid.NewGuid().ToString()
                    identityBuilder.AddSigningCredential(new SigningCredentials(key, SecurityAlgorithms.RsaSsaPssSha256));
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful