5

以下のコードを使用して、Asp.net Web Api 2.2サービスからJWTアクセストークンを消費しています。私はthis articleに続いてWeb APIサービスで認証サーバーを設定しました。私はRestSharpをクライアントで使用しています。RestSharpを使用してJWTアクセストークンとユーザークレームを消費する方法

クライアントコード:私は次のエラーを取得していた結果

  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", "[email protected]"); 
      request.AddHeader("password", "[email protected]"); 
      IRestResponse response = client.Execute(request); 
      result = response.Content; 

私はこのエラーを取得していますし、私はこれをどのように修正することができますなぜ
{ 
    "error_description":"grant type not supported", 
    "error":"unsupported_grant_type" 
} 
  1. クライアントのユーザー名などのクレームにはどうすればアクセスできますか?
  2. また、Identity Modelを使用してサービスを使用するにはどうすればよいですか。

答えて

-1

それは古い質問です、あなたはおそらく今が、ここでFWIW私のために働いたソリューションであることにより、実装を持つ

var client = new RestClient("http://blahblah/"); 
var request = new RestRequest("/token", Method.POST); 
// all parameters need to go in body as string 
var encodedBody = string.Format("username={0}&password={1}&grant_type=password", model.Username, model.Password); 
request.AddParameter("application/x-www-form-urlencoded", encodedBody, ParameterType.RequestBody); 
request.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader); 
var response = client.Execute(request); 
1

あなたはgrant_typeusernamepassword httpリクエストのHeaderに追加し、 Body部分にあるはずです。

関連する問題