title: How to add OpenIdConnect via IdentityServer4 to ASP.NET Core ServerSide Blazor web app?
body: <p>I did the following (It should work but it does not), no redirect, no error, no nothing, it just displays the page without auth, what am I doing wrong?</p>
  
  <hr>
  
  <h1><strong>ASP.NET Core 3.1 Blazor</strong></h1>
  
  <p><strong>Step 1.</strong> Install-Package Microsoft.AspNetCore.Authentication.OpenIdConnect</p>
  
  <p><strong>Step 2.</strong> Edit Statup.cs</p>
  
  <p>Under "ConfigurationServices" add</p>
  
  <pre><code>        services.AddAuthentication(options =&gt;
          {
              options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
              options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
          })
          .AddCookie()
          .AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =&gt;
          {
             options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
             options.Authority = "http://localhost:5000";
             options.RequireHttpsMetadata = false; //false for development only
             options.ClientId = "mywebclient";
             options.ResponseType = "code";
             options.UsePkce = true;
             options.Scope.Add("profile");
             options.Scope.Add("offline_access");
             options.SaveTokens = true;
          });
  </code></pre>
  
  <p>Under "Configure" add</p>
  
  <pre><code>        ...
          services.AddAuthorization();
  
          app.UseStaticFiles();
  
          app.UseRouting();
  
  
          app.UseAuthentication();
          app.UseAuthorization();
  
          ....
  </code></pre>
  
  <p><strong>Step 3.</strong> Add attribute Authorize to blazor page</p>
  
  <pre><code>        @page "/item"
          @attribute [Authorize] 
  </code></pre>