2017-10-10 4 views
0

私はthisページの指示に従っています。私はWindowsサービスを自分で作成しました。Azure ADのアクセストークンを要求しています。 私は認証コードを取得できましたが、私はPOSTのときにredirect_uriエラーを受け取ります。これは私のコードの外観です:AADSTS90102: 'redirect_uri'の値は有効な絶対Uriでなければなりません

var dictionary = new Dictionary<string, string> 
      { 
       { "resource", "https%3A%2F%2Foutlook.office365.com"}, 
       {"client_id","Application ID from azure AD portal" }, //-is this ok? 
       {"client_secret","Object ID from azure AD portal" }, //-is this ok? 
       {"grant_type","authorization_code" }, 
       {"redirect_uri",HttpUtility.UrlEncode("https://haw.trustteam.be/") }, 
       { "code","AQABAAIAAAAB..1AiAA"} 
      }; 
      var content = new FormUrlEncodedContent(dictionary); 

      string requestUrl = "https://login.windows.net/common/oauth2/token"; // also tried with login.microsoftonline.com 
      using (HttpClient client = new HttpClient()) 
      { 
       HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUrl); 
       request.Content = content; 

       using (HttpResponseMessage response = await client.SendAsync(request)) 
       { 
        string responseString = await response.Content.ReadAsStringAsync(); 

        return response.Content.ToString(); 
       } 
      } 

私は間違っていますか?

答えて

0

FormUrlEncodedContent関数は、HttpMessage本体のデータをURLエンコードされたキーと値のペアとして送信するのにも役立ちます。

  var dictionary = new Dictionary<string, string> 
      { 
       { "resource", "https://outlook.office365.com"}, 
       {"client_id","Application ID from azure AD portal" }, 
       {"client_secret","Application key from azure portal" }, 
       {"grant_type","authorization_code" }, 
       {"redirect_uri","https://haw.trustteam.be/" }, 
       { "code","AQABAAIAAAAB..1AiAA"} 
      }; 
      var content = new FormUrlEncodedContent(dictionary); 

はまた、あなたは紺碧の広告アプリケーションのKeysブレードにクライアントシークレットを追加することができます。だからHttpUtility.UrlEncode機能を削除します。 this documentを参照してください。

関連する問題