title: Storing a JWT token in Blazor Client Side
body: <p>I am trying my first Blazor app, client side, and am battling with authentication. I have managed to call my API, get a token, and authenticate in the app. I need to store the JWT token somewhere - and I thought, in the claims, might be OK. (Maybe this is where I go wrong, and it should be somehow, in LocalStorage or something?)</p>
  <p>So for my authorisation, I have a <code>AuthenticationStateProvider</code>, where - things work OK. I get authenticated. But I am unable to acceess my token.</p>
  <p>Is this the right place to be adding it? And if so, why is this code failing me?</p>
  <pre><code>    public class CustomAuthenticationStaterProvider : AuthenticationStateProvider
      {
          public override Task&lt;AuthenticationState&gt; GetAuthenticationStateAsync()
          {
              var identity = new ClaimsIdentity();
  
              var user = new ClaimsPrincipal(identity);
  
              return Task.FromResult(new AuthenticationState(user));
          }
  
          public void AuthenticateUser(AuthenticationResponse request)
          {
              if (request.ResponseDetails.IsSuccess == false)
                  return;
  
              var identity = new ClaimsIdentity(new[]
              {
                  new Claim(&quot;token&quot;, request.Token),
                  new Claim(ClaimTypes.Email, request.Email),
                  new Claim(ClaimTypes.Name, $&quot;{request.Firstname} {request.Surname}&quot;),
              }, &quot;apiauth_type&quot;);
  
              var user = new ClaimsPrincipal(identity);
  
              NotifyAuthenticationStateChanged(Task.FromResult(new AuthenticationState(user)));
          }
  
          public void LogoutUser()
          {
              // Hwo??
           
          }
      }
  </code></pre>
  <p>My index page is working:</p>
  <pre><code>    &lt;Authorized&gt;
          &lt;p&gt;Welcome, @context.User.Identity.Name&lt;/p&gt;
      &lt;/Authorized&gt;
      &lt;NotAuthorized&gt;
          &lt;p&gt;You're not signed in&lt;/p&gt;
      &lt;/NotAuthorized&gt;
  &lt;/AuthorizeView&gt;
  </code></pre>
  <p>It shows my name, when logged in, as expected.</p>
  <p>But on a page where I need to send the JWT token to the API, I am trying to find it:</p>
  <pre><code>
          var user = authState.User;
  </code></pre>
  <p>But <code>user</code> seems to have no 'token' parameter.</p>
  <p><a href="https://i.stack.imgur.com/vembO.png" rel="noreferrer"><img src="https://i.stack.imgur.com/vembO.png" alt="enter image description here" /></a></p>
  <p>How should I be storing my JWT, and having access to it when ever I am about to use my http client?</p>