登录后未从身份服务器生成 JWT 令牌

时间:2021-06-22 21:42:49

标签: asp.net asp.net-core jwt identityserver4

我创建了一个空的 .net5 Web API 项目。项目应使用 Identity Server 为 API 用户生成 JWT 令牌。

startup.cs

 public void ConfigureServices(IServiceCollection services){
   services.AddDbContext<ApplicationDbContext>(...);
   services.AddIdentity<ApplicationUser, IdentityRole>()
      .AddEntityFrameworkStores<ApplicationDbContext>()
      .AddDefaultTokenProviders();
   services.AddIdentityServer(...)
      .AddAspNetIdentity<ApplicationUser>()
      .AddConfigurationStore(...);
   services
      .AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
      .AddJwtBearer();
    ...
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env){
    ...
    app.UseAuthentication();
    app.UseIdentityServer();
    app.UseAuthorization();
    ...
}

代码编译没有错误

登录功能

var result = await _signInManager
        .PasswordSignInAsync(model.Email, model.Password, false, lockoutOnFailure: false);
    if (result.Succeeded)
    {
        _logger.LogInformation("User logged in.");
        return Ok();
    }
    return BadRequest("Invalid Login Attempt");

我从服务器收到了 ok 结果,但在响应的标头中没有返回 JWT。我还注意到,当我创建第二个请求时,我发现我以前的登录数据存储在控制器的 User 属性中。

我的问题是在哪里可以找到我的端点生成的令牌?

0 个答案:

没有答案
相关问题