2017-10-10 1 views
0

나는 this 페이지의 지침을 따르고 있습니다. 나 자신에게 윈도우 서비스를 만들었고 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을 참조하십시오.