2014-12-16 2 views
14

Azure 사용자가 Azure Service Management API를 사용하여 가입/서비스를 볼 수있는 Windows Phone 8.1 앱을 구축하고 있습니다. 인증은 관리 인증서를 사용하여 수행되며 인증서는 API에 대한 모든 요청에 ​​첨부됩니다. 그것은 단일 사용자에 대해 잘 작동합니다. 그러나 여러 구독에 대한 기능을 포함하려고 할 때 문제가 발생합니다. 인증서 저장소에 인증서를 설치하고 검색 할 수 있습니다. 하지만 문제는 API에 요청을 보낼 때 발생합니다. 올바른 인증서를 첨부하고 있지만 403 금지 된 오류가 발생합니다. 다음은 내가 사용한 코드입니다.HttpClient를 사용한 여러 인증서

public async Task<Certificate> GetCertificate() 
{ 
      await CertificateEnrollmentManager.ImportPfxDataAsync(Certificate, "", ExportOption.Exportable, KeyProtectionLevel.NoConsent, InstallOptions.None, SubscriptionID); 
      CertificateQuery query = new CertificateQuery(); 
      query.FriendlyName = SubscriptionID; 
      var c = await CertificateStores.FindAllAsync(query); 
      return c[0]; 
} 

public async Task<HttpResponseMessage> SendRequest(string url,string version) 
{ 
     HttpResponseMessage response = null; 
     try 
     { 
      HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter(); 
      filter.ClientCertificate = await GetCertificate(); 
      HttpClient client = new HttpClient(filter); 
      HttpRequestMessage request = new HttpRequestMessage(); 
      request.RequestUri = new Uri(url); 
      request.Headers.Add("x-ms-version", version); 
      response = await client.SendRequestAsync(request, 0); 
      return response; 
     } 
     catch(Exception e) 
     { 
      var status=Windows.Web.WebError.GetStatus(e.HResult); 
      if (status == WebErrorStatus.CannotConnect) 
       throw new Exception("Cannot connect to internet. Check your connection."); 
      else if (status == WebErrorStatus.Disconnected) 
       throw new Exception("Connection was disconnected."); 
      else if (status == WebErrorStatus.ServiceUnavailable) 
       throw new Exception("Server was unavailable"); 
      else if (status == WebErrorStatus.ConnectionReset) 
       throw new Exception("Connection was reset."); 
      else if (status == WebErrorStatus.BadGateway) 
       throw new Exception("Bad gateway."); 
      else if (status == WebErrorStatus.InternalServerError) 
       throw new Exception("Internal server error occurred"); 
      else if (status == WebErrorStatus.HostNameNotResolved) 
       throw new Exception("Check your network connection. Host name could not be resolved."); 
     } 
     return response; 

} 

Windows Phone OS에는 응용 프로그램의 인증서가 제한되어 있습니까?

+0

:

당신은 푸른 서비스 관리 API로 네이티브 클라이언트 애플리케이션 액세스를 부여합니다. 내가 부르는 관리 끝점이 같은 도메인이라고 생각합니다. 나는 이것이 기본 라이브러리 상태와 관련이 있으며 클라이언트 인증서를 "캐싱 (caching)"하는 방법이라고 생각한다. 나는이 문제 또는 해결책에 대한 언급을 발견하지 못했다. – ameer

+0

Windows 7. 5에서 자체 서명 된 인증서를 사용할 수 없음을 기억합니다. 저장소에 자신의 루트 CA를 설치해야합니까? –

답변

1

실제로 인증서 문제를 해결하는 방법에 직접 답변하지는 않지만 더 잘 작동하는 해결 방법을 제안합니다.

인증서 대신 Bearer 토큰과 Azure AD 인증을 서비스 API에 사용하십시오.

따라서 여러 인증서를 관리하는 대신 ADAL을 사용하여 Azure AD에서 토큰을 얻을 수 있습니다. 사용자가받는 단일 토큰은 사용자가 액세스 할 수있는 모든 구독에 대해 유효합니다.

authenticating service management API calls with Azure AD here에 대한 자세한 내용을 볼 수 있습니다.

그리고 more about using ADAL with Windows Phone app here을 알 수 있습니다. 동일한 도메인에 대한 요청에 대해 클라이언트 인증서를 변경하려고 할 때 나는 비슷한 경험했던

enter image description here