通过ASP.NET Boilerplate中的JWT令牌获取用户ID

问题描述 投票:0回答:1

我将JWT Auth添加到我的asp.net样板项目中。

我尝试通过令牌获取用户身份(理想情况下将为ID)>

这是我尝试这样做的方式。

[Authorize]
    [HttpGet]
    [ProducesResponseType(typeof(ShowJobDto), (int)System.Net.HttpStatusCode.OK)]
    public async Task<IActionResult> GetJobs(DateTime? from, DateTime? to)
    {
        var identity = (ClaimsIdentity)User.Identity;
        List<ShowJobDto> jobs;
        var query = _jobRepository.GetAllIncluding(x => x.WorkOrder.Quote,
            x => x.WorkOrder.Quote.Property.Addresses,
            x => x.Engineer).Where(x => x.JobStatus != JobStatus.Pending);
        if (from != null && to != null)
        {
            jobs = await query.Where(x => x.JobDate >= from).Where(x => x.JobDate <= to)
                .ProjectTo<ShowJobDto>(ObjectMapper).OrderBy(x => x.TimeFrom).ToListAsync();
            return Ok(jobs);
        }

        jobs = await query.ProjectTo<ShowJobDto>(ObjectMapper).OrderBy(x => x.TimeFrom).ToListAsync();
        return Ok(jobs);
    }

我邮递员我像这样通过了beare令牌

enter image description here

但是当我在此处设置断点var identity = (ClaimsIdentity)User.Identity;

我什么都没有。我的问题在哪里?

我将JWT Auth添加到我的asp.net样板项目中。我尝试通过令牌获取用户身份(理想情况下将为ID)这是我尝试执行的操作。 [授权] [HttpGet] [ProducesResponseType(typeof(...

c# asp.net asp.net-core aspnetboilerplate
1个回答
0
投票

我使用以下方法来授权我的一个应用程序中的用户。因此,我确定您可以对此代码进行一些更改并获得所需的内容:

© www.soinside.com 2019 - 2024. All rights reserved.