如何使用RestSharp使用JWT访问令牌和用户声明

Rah*_*hul 5 c# restsharp jwt thinktecture-ident-server asp.net-web-api2

我正在使用以下代码从Asp.net Web Api 2.2服务中使用JWT访问令牌.我已按照本文在Web Api服务中设置授权服务器.我在客户端使用RestSharp.

客户代码:

            var client = new RestClient(http://localhost:58030);
            client.Timeout = 30000;
            var request = new RestRequest(@"/Oauth/Token", Method.POST);
            request.AddHeader("content-type", "application/x-www-form-urlencoded");
            request.AddHeader("grant_type", "password");
            request.AddHeader("username", "admin@example.com");
            request.AddHeader("password", "Admin@456");
            IRestResponse response = client.Execute(request);
            result = response.Content;
Run Code Online (Sandbox Code Playgroud)

结果我得到以下错误:

{
  "error_description":"grant type not supported",
  "error":"unsupported_grant_type"
}
Run Code Online (Sandbox Code Playgroud)
  1. 为什么我收到此错误,我该如何解决?
  2. 如何访问客户端中的用户名等声明?
  3. 或者,我如何使用Identity Model来使用服务?

sep*_*ehr 2

您在http 请求中添加了grant_typeusername,它应该是一部分。passwordHeaderBody