I'm building Web service using ASP.Net Core WebApi. I would like to use Identity and also JWTBearer authentication. My code in ConfigureService method of Startup class id:
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:
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. But i Would like only to use JwtBearer in header. Is there any option how to disable cookies for SignInManager
?
Use SignInManager.CheckPasswordSignInAsync()
: it does exactly the same checks but unlike SignInManager.PasswordSignInAsync
, doesn't return any cookie.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With