title: .NET Core 3.1 Web API and Blazor Server Side JWT Authentication
body: <p>I would like to understand, how it is possible to set up <strong>JWT</strong> <strong>authentication</strong> for <strong>Blazor Server Side Apps</strong>?</p>
  <p>Let me draw up an example: Let's say we have a .NET Core 3.1 Web API project. The project has its own <code>TokenController</code> implementation, which gives out JWT for a valid user / password combination. All other Controllers require such a token for each request.</p>
  <p>The Middleware for validating the Authentication is configured like so:</p>
  <pre><code>// enabling JWT bearer scheme
  services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
      .AddJwtBearer(options =&gt; 
      {
          options.TokenValidationParameters = new TokenValidationParameters 
          {
              // TOKEN VALIDATION PARAMETERS
          };
      });
  
  // applying default authentication policy
  services.AddMvc(o =&gt; 
  {
      o.EnableEndpointRouting = false;
      var policy = new AuthorizationPolicyBuilder()
          .RequireAuthenticatedUser()
          .Build();
      o.Filters.Add(new AuthorizeFilter(policy));
  }).SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
  </code></pre>
  <p>Up until here, this is working perfectly fine.</p>
  <p>Now I would like to add a nice Blazor Server Side UI to this project, and I just can't wrap my head around how to do the Authentication then?</p>
  <p>According to Microsoft Docs, the Authentication for Server Side Apps is supposed to take place at establishing the SignalR connection:</p>
  <blockquote>
  <p><strong>Blazor Server authentication</strong></p>
  <p>Blazor Server apps operate over a real-time connection that's created using SignalR. Authentication in SignalR-based apps is handled when the connection is established. Authentication can be based on a cookie <em>or some other bearer token.</em></p>
  <p>(source: <a href="https://docs.microsoft.com/en-us/aspnet/core/security/blazor/?view=aspnetcore-3.1&amp;tabs=visual-studio" rel="noreferrer">https://docs.microsoft.com/en-us/aspnet/core/security/blazor/?view=aspnetcore-3.1&amp;tabs=visual-studio</a>)</p>
  </blockquote>
  <p>Unfortunately I am not able to figure out how this works - the tutorials and tips I found are either for Client Side Blazor or use Cookie / Identity...</p>
  <p>Any ideas?</p>