title: AspNetCore 2.2 as API - How to logout using Identity methods?
body: <p>I created web application with Angular 7 as <a href="https://github.com/BiserB/NameGeneratorFrontend" rel="nofollow noreferrer">front-end</a>,
  DotNetCore 2.2 as <a href="https://github.com/BiserB/NameGeneratorBackend" rel="nofollow noreferrer">back-end API</a> (SQL Server for db).
  When I initially created the project, I didn't add Authentication, because
  there is no need of UI pages. I plan to use Identity authentication with cookies.</p>
  
  <p>While Login and [Authorize] work well, Logout doesn't work with signInManager.SignOutAsync().</p>
  
  <p>Microsoft states:
  "SignOutAsync clears the user's claims stored in a cookie.
   Don't redirect after calling SignOutAsync or the user will not be signed out."
  Seems that the cookie is not deleted and it is accepted as valid from API (except when it is expired).
  I tried with Response.Cookies.Delete() and HttpContext.SignOutAsync() without success.</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      services.AddCors(options =&gt;
      {
          options.AddPolicy("CORS", builder =&gt; 
          {
              builder.WithOrigins("http://localhost:42000")
              .AllowAnyHeader()
              .AllowCredentials();
          });
      });
  
      services.Configure&lt;CookiePolicyOptions&gt;(options =&gt;
      {
          options.CheckConsentNeeded = context =&gt; false;
          options.MinimumSameSitePolicy = SameSiteMode.None;
      });
  
      services.AddDbContext&lt;NGDbContext&gt;(options =&gt;  options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
  
      services.AddIdentity&lt;NGUser, IdentityRole&gt;()
              .AddEntityFrameworkStores&lt;NGDbContext&gt;()
              .AddDefaultTokenProviders();
  
      services.Configure&lt;IdentityOptions&gt;(options =&gt;
      {
          // some options...
      });
  
      services.ConfigureApplicationCookie(options =&gt;
      {
          options.Cookie.HttpOnly = true;
          options.ExpireTimeSpan = TimeSpan.FromMinutes(1);
          options.SlidingExpiration = true;
          //options.CookieName = "MyCookie";
      });
  
      services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
  
      services.AddScoped&lt;NamesService, NamesService&gt;();
  }
  
  public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  {
      if (env.IsDevelopment())
      {
          app.UseDeveloperExceptionPage();
  
          InitialSeeder.Seed(app);
      }
      else
      {
          app.UseHsts();
      }
  
      app.UseCors("CORS");
      app.UseHttpsRedirection();
      app.UseCookiePolicy();
      app.UseAuthentication();
      app.UseMvc();
  }
  </code></pre>
  
  <pre><code>[Route("api/[controller]")]
  [ApiController]
  public class AuthController : ControllerBase
  {
      private UserManager&lt;NGUser&gt; userManager;
      private SignInManager&lt;NGUser&gt; signInManager;
  
      public AuthController(UserManager&lt;NGUser&gt; userManager, SignInManager&lt;NGUser&gt; signInManager)
      {
          this.userManager = userManager;
          this.signInManager = signInManager;
      }
  
      [HttpPost("Login")]
      public async Task&lt;ActionResult&gt; Login(LoginModel model)
      {
          var user = await this.userManager.FindByNameAsync(model.Username);
  
          if (user == null)
          {
              return Unauthorized();
          }
  
          var signInResult = await this.signInManager.PasswordSignInAsync(user, model.Password, false, false);
  
          if (!signInResult.Succeeded)
          {
              return Unauthorized();
          }
  
          return Ok();
      }
  
      [HttpPost("Logout")]
      public async Task&lt;ActionResult&gt; Logout()
      {
          await this.signInManager.SignOutAsync();
  
          return Ok();
      }
  }
  </code></pre>
  
  <p>Is it possible to benefit from Identity sign-in sign-out methods?
  Or should use custom methods?</p>