【问题标题】:HttpBasicAuthenticator Authentication IssueHttpBasicAuthenticator 身份验证问题
【发布时间】:2018-10-08 06:04:25
【问题描述】:

我刚刚开始从事 3rd 方 API 集成工作。在 Postman 客户端 API 调用中,我在标头和带有令牌的承载中使用了授权密钥。当我开始与我的 C# 代码集成时。我使用 HttpBasicAuthenticator 使用访问令牌对 API 进行身份验证。但它会自动将“basic”作为字符串附加到令牌中,而不是我希望它附加“bearer”。

你能帮帮我吗?我该怎么做?

感谢您的帮助。谢谢

client.Authenticator = new HttpBasicAuthenticator(x, string.Format("Bearer {0}",ApiToken));

【问题讨论】:

  • 您使用的是哪个 REST 客户端? RestSharp?
  • @JatinParmar 是的,我正在使用 RestSharp。

标签: c# .net asp.net-mvc restful-authentication


【解决方案1】:

您使用了错误的身份验证器,

如果要使用 Bearer 令牌访问 API Endpoint,可以使用JwtAuthenticator

试试,

client.Authenticator = new JwtAuthenticator(ApiToken);

哪个解决了你的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-23
    • 2015-08-25
    • 2010-11-17
    • 2019-06-19
    • 2011-02-14
    • 2011-07-03
    • 2015-12-03
    相关资源
    最近更新 更多