【问题标题】:API call with correct access token in header gives me a 401 unauthorized标头中具有正确访问令牌的 API 调用给了我 401 未授权
【发布时间】:2018-09-05 09:56:33
【问题描述】:

我正在为当前项目请求针对身份服务器应用程序的令牌,我们在之前的项目中使用了该令牌。在我的本地机器上,所以是 localhost 级别。

令牌请求有效:

IdentityServer3.Core.ResponseHandling.TokenResponseGeneratorCreating token response
IdentityServer3.Core.ResponseHandling.TokenResponseGeneratorProcessing token request
Identity.Api.Monitoring.IdentityEventServiceInformation - 2020 - Refresh token issued -  - IdentityServer3.Core.Events.RefreshTokenDetails
Identity.Api.Monitoring.IdentityEventServiceInformation - 2000 - Access token issued -  - IdentityServer3.Core.Events.AccessTokenIssuedDetails
Identity.Api.Monitoring.IdentityEventServiceSuccess - 3000 - Endpoint success -  - IdentityServer3.Core.Events.EndpointDetail
IdentityServer3.Core.Endpoints.TokenEndpointControllerEnd token request
IdentityServer3.Core.Results.TokenResultReturning token response.

我收到以下回复:

{
    "access_token": "myaccesstoken",
    "expires_in": 86400,
    "token_type": "Bearer",
    "refresh_token": "myrefreshtoken"
}

现在,如果我在请求中使用该令牌,我会收到 401 unauthorized 响应:

从表面上看,我希望这个调用能奏效,因为我传递了一个正确的 令牌。那么,我该怎么做才能弄清楚为什么它不起作用?

【问题讨论】:

    标签: c# .net oauth-2.0 identityserver3


    【解决方案1】:

    授权标头应该有 Bearer 而不是 BASIC

    Authorization: Bearer SomeTokenHere
    

    【讨论】:

    • 哦,这么简单,不知道是怎么做到的。一个疏忽:)。
    • 顺便说一句,400 Bad Request 响应似乎比我得到的 401 更合乎逻辑。收到 401 让我过度思考这个问题,因为我没有方向可看。
    • 我相信会返回 400,因为它不会将 Basic Auth 标头视为格式正确的请求。在这里讨论:stackoverflow.com/questions/10576898/…
    猜你喜欢
    • 2017-07-06
    • 2017-06-11
    • 2019-11-02
    • 2021-01-11
    • 2020-04-10
    • 2017-06-07
    • 2012-04-04
    • 2015-02-22
    • 2022-08-18
    相关资源
    最近更新 更多