【发布时间】:2026-01-17 16:55:01
【问题描述】:
我正在使用 Postman,首先我请求一个令牌:
这为我提供了正确的令牌响应:
{
"access_token": "MY_BEARER_TOKEN",
"expires_in": ?,
"token_type": "Bearer",
"refresh_token": "MY_REFRESH_TOKEN"
}
比我发布到我需要的实际网址:
将此值用于授权标头:
BEARER *MY_BEARER_TOKEN*
虽然这是一个新请求的令牌,但我得到:
{
"message": "Authorization has been denied for this request."
}
当我检查我的 API 日志时,我看到了:
Error | IdentityServer3.AccessTokenValidation.IntrospectionEndpointTokenProvider | Error returned from introspection endpoint: An error occurred while sending the request.
Warn | Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationMiddleware | invalid bearer token received
这很奇怪,因为它是我正在使用的新令牌。可能是其他原因导致了这种情况,但如果是这样,这里没有描述,身份服务器日志中也没有描述。这似乎很好:
Info | IdentityServer3.Core.ResponseHandling.TokenResponseGenerator | Creating token response
Info | IdentityServer3.Core.ResponseHandling.TokenResponseGenerator | Processing token request
Info | Identity.Api.Monitoring.IdentityEventService | Information - 2020 - Refresh token issued - - IdentityServer3.Core.Events.RefreshTokenDetails
Info | Identity.Api.Monitoring.IdentityEventService | Information - 2000 - Access token issued - - IdentityServer3.Core.Events.AccessTokenIssuedDetails
Info | Identity.Api.Monitoring.IdentityEventService | Success - 3000 - Endpoint success - - IdentityServer3.Core.Events.EndpointDetail
Info | IdentityServer3.Core.Endpoints.TokenEndpointController | End token request
Info | IdentityServer3.Core.Results.TokenResult | Returning token response.
知道会发生什么吗?
【问题讨论】:
-
请向我们展示一个不起作用的令牌示例(真实值 - 不要虚构)。
-
遇到了同样的问题,还没有找到解决办法。我从 api 得到 401,NLog 显示:Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationMiddleware|invalid Bearer token received。我生成的令牌是 JWT Bearer 令牌。
标签: c# oauth-2.0 asp.net-web-api2 identityserver3