title: Get access token in middleware .net core 2.0
body: <p>I am trying to get the access_token in my middleware class after one authentication process in .net core. </p>
  
  <p>I am getting my token in my controllers using this code</p>
  
  <pre><code>var accessToken = await HttpContext.GetTokenAsync("access_token");
  </code></pre>
  
  <p>But when I want to get it on the middleware which is called after the authentication part the method <code>GetTokenAsync</code> is not existing for the HttpContext. </p>
  
  <p>My middleware class is this </p>
  
  <pre><code>public class Session
      {
          private readonly RequestDelegate _next;
          public Session(RequestDelegate next)
          {
              _next = next;
          }
  
          public async Task InvokeAsync(HttpContext httpContext)
          {
              var accessToken = // here I want to get my token
  
              await _next(httpContext);
          }
      }
  </code></pre>
  
  <p>I tried different ways and I have been looking for a long time for answers but I still have no solution. </p>
  
  <p>I think that the HttpContext class is different in Middleware and Controllers but I don't know how to solve this in the Middleware. </p>
  
  <p>Someone knows how can I get access to the token in the middleware call or if it is even possible?</p>
  
  <p>My startup callins are theese, maybe it is usefull too.</p>
  
  <pre><code>app.UseAuthentication();
  app.UseHttpsRedirection();
  app.UseMiddleware&lt;Session&gt;();
  app.UseMvc();
  </code></pre>