2017-10-10 4 views
0

Ich befolge die Anweisungen von this Seite. Ich habe mir selbst einen Windows-Dienst erstellt und bin dabei, ein Zugriffstoken von Azure AD anzufordern. Ich habe es geschafft, einen Autorisierungscode zu bekommen, aber ich bekomme den redirect_uri Fehler, wenn ich POST. So sieht mein Code aus:AADSTS90102: 'redirect_uri' Wert muss ein gültiger absoluter sein 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(); 
       } 
      } 

Was mache ich falsch?

Antwort

0

Die Funktion "FormUrlEncodedContent" unterstützt auch die Veröffentlichung von Daten im HttpMessage-Text als URL-codierte Schlüssel/Wert-Paare. So entfernen Sie einfach die HttpUtility.UrlEncode Funktion:

  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); 

Darüber hinaus können Sie die Client-Geheimnis in Keys Klinge Ihrer azur Anzeige Anwendung hinzufügen. Bitte beziehen Sie sich auf this document.

Verwandte Themen