简体   繁体   English

Asp.Net WebApi核心2.0身份与JWTBearer没有cookie

[英]Asp.Net WebApi Core 2.0 Identity With JWTBearer Without cookies

I'm building Web service using ASP.Net Core WebApi. 我正在使用ASP.Net Core WebApi构建Web服务。 I would like to use Identity and also JWTBearer authentication. 我想使用Identity和JWTBearer身份验证。 My code in ConfigureService method of Startup class id: 我在Startup类id的ConfigureService方法中的代码:

services.AddIdentity<User, Role>()
      .AddDefaultTokenProviders();

  //JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

  services.AddAuthentication(options =>
  {
    options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
  })
  .AddJwtBearer(options =>
  {
    options.RequireHttpsMetadata = false;
    options.SaveToken = true;
    options.Audience = Configuration.GetSection("JwtIssuer").Value;
    options.ClaimsIssuer = Configuration.GetSection("JwtIssuer").Value;
    options.TokenValidationParameters = new TokenValidationParameters
    {
      ValidateIssuer = true,
      ValidateAudience = true,
      ValidateLifetime = true,
      ValidateIssuerSigningKey = true,
      ValidIssuer = Configuration["JwtIssuer"],
      ValidAudience = Configuration["JwtIssuer"],
      IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JwtKey"]))
    };
  });

Configure method of Startup class contains: Startup类的Configure方法包含:

if (env.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}
app.UseAuthentication();
app.UseMvc();

My problem is that when I call signInManager.PasswordSignInAsync it include cookie with authentication token to response. 我的问题是,当我调用signInManager.PasswordSignInAsync它包含带有身份验证令牌的cookie来响应。 But i Would like only to use JwtBearer in header. 但我只想在标题中使用JwtBearer。 Is there any option how to disable cookies for SignInManager ? 有没有选项如何禁用SignInManager cookie?

使用SignInManager.CheckPasswordSignInAsync() :它执行完全相同的检查,但与SignInManager.PasswordSignInAsync不同,不返回任何cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM