我一直在關注this resource以在azure上創建一個應用程序,該應用程序使用azure活動目錄進行身份驗證。我們希望使用來自交換機和EWS託管API的身份驗證交互中的令牌來冒充我們組織中的每個人,而無需登錄。用於交換模擬的Azure AD僅限應用程序訪問令牌
我已經在我們的組織上註冊了一個應用程序,並授權它進行交換。創建證書和與之建立我們的Azure應用程序後,我可以通過下面的代碼使用ADAL一個唯一的應用程序的訪問令牌......
string authority = "https://login.windows.net/{tenant}/oauth2/authorize";
AuthenticationContext authenticationContext = new AuthenticationContext(authority, false);
var certPath = @"C:\path\to\cert\Cert.pfx";
var certfile = System.IO.File.OpenRead(certPath);
var certificateBytes = new byte[certfile.Length];
certfile.Read(certificateBytes, 0, (int)certfile.Length);
var cert = new X509Certificate2(
certificateBytes,
PRIVATE_KEY_PASSWORD,
X509KeyStorageFlags.Exportable |
X509KeyStorageFlags.MachineKeySet |
X509KeyStorageFlags.PersistKeySet);
ClientAssertionCertificate cac = new ClientAssertionCertificate(CLIENT_ID, cert);
var token = await authenticationContext.AcquireTokenAsync("https://outlook.office365.com/", cac);
有了這個標記的代碼進行交互與預警管理API是這樣的..
ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
_ExchangeService = new ExchangeService(ExchangeVersion.Exchange2013_SP1) {
Credentials = new OAuthCredentials(token),
Url = new Uri("https://outlook.office365.com/ews/exchange.asmx"),
ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.PrincipalName, "[email protected]"),
};
_ExchangeService.HttpHeaders.Add("X-AnchorMailbox", "[email protected]");
這似乎是通過管理API設置模擬,雖然每個請求返回401錯誤未經授權的正確方法。
我的問題歸結爲,我在這裏做錯了什麼?還是有什麼我需要做我的應用程序訪問交換服務器?
我跟着的article確實提到了客戶同意流程,但該部分的細節並不清楚。如果沒有事先徵得他們的同意,我是否可以不給予我的應用許可?
這正是我所需要的。我剛剛忘記申請許可。感謝您的幫助。 – dannylindquist
嗨我在這裏面對同樣的401錯誤:https://stackoverflow.com/questions/45614307/401-unauthorized-while-subscribeing-to-push-notifications-with-exchange-service-a我給了必要的權限我的應用程序在天青門戶,但仍然沒有運氣。 – tavier