【发布时间】:2020-05-15 15:38:25
【问题描述】:
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Authorization: Bearer MyMagicToken
Connection: keep-alive
Content-Length: 103
Content-Type: application/json
Host: localhost:63304
Origin: http://localhost:4200
Referer: http://localhost:4200/fooBar
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36
我将上述请求发送到我的 WebApI 2 控制器。控制器用[Authorize] 属性装饰
由于某种原因,我的 AUTHORIZE 属性的第一行返回 null
protected override Task HandleRequirementAsync(AuthorizationHandlerContext
context, HasPermissionRequirement requirement)
{
var token = this._httpContextAccessor.HttpContext.GetTokenAsync("access_token").Result;
我应该如何更改我的 http 请求以使 var token 等于 MyMagicToken ?
在ApiStartup我有
app.UseAuthentication();
app.UseAuthorization();
【问题讨论】:
-
你有请求中间件吗?
-
不在
AUTHORIZATION代码中,我设置了ErrorMiddleWare。 -
确保认证完成
-
@DanielA.White 我通过添加中间件修改了问题。这是你说的吗?
标签: c# asp.net-core asp.net-core-3.0