WWW身份验证的重复承载架构

时间:2020-04-23 10:52:45

标签: asp.net-web-api jwt asp.net-identity www-authenticate

我有REST API应用程序,正在使用DelegatingHandler验证收到的令牌。

如果令牌无效,我将返回401响应代码,并尝试设置WWW-Authenticate标头。

    var unauthorizedResponse = request.CreateErrorResponse(HttpStatusCode.Unauthorized, errorDetails);
    unauthorizedResponse.Headers.WwwAuthenticate.Clear();
    unauthorizedResponse.Headers.Remove("WWW-Authenticate");
    unauthorizedResponse.Headers.WwwAuthenticate.Add(new AuthenticationHeaderValue("Bearer", $"error=invalid_token, error_description={errorMessage}"));

问题在于,在响应中,我将其复制为“ Bearer”方案。

HTTP / 1.1 401未经授权

Content-Type:application / json; charset = utf-8

服务器:Microsoft-IIS / 10.0

WWW-Authenticate:承载错误=无效令牌,error_description =无效令牌!

WWW身份验证:不记名

在何处以及何时设置第二个值?

0 个答案:

没有答案
相关问题