我有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身份验证:不记名
在何处以及何时设置第二个值?