私はthis resourceに従って、晴れたアクティブディレクトリで認証するアプリケーションを作成しました。この認証相互作用のトークンをExchangeとEWS管理APIを使用して、組織内のすべてのユーザーを偽装し、ログインする必要はありません。交換偽装のためのAzure ADアプリケーション専用アクセストークン
私はazureに私たちの組織にアプリを登録し、交換を許可しました。これはEWSが管理と対話するためのコードをトークンで証明書を作成し、それを私たちの紺碧のアプリケーションを設定した後、私は次のコードを経由して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]");
すべての要求が401不正エラーを返しますが、これは、管理APIを介して偽装を設定するための正しい方法であるように思われます。
私の質問はここまでに間違っていますか?あるいは、私のアプリケーションにExchangeサーバへのアクセスを与えるために何か必要なことがありますか?
article私が従っていたのはクライアント同意フローでしたが、そのセクションの詳細は明確ではありません。最初に同意を促すことなく、誰にでもアプリを許可することはできません。
これは私が必要としていたものです。私はアプリケーションの許可を適用することを忘れてしまった。ご協力ありがとうございました。 – dannylindquist
こんにちは私は同じ401のエラーに直面している:https://stackoverflow.com/questions/45614307/401-unauthorized-while-subscribing-to-push-notifications-with-exchange-service-a私は必要な許可を与えた紺碧のポータルで私のアプリが、まだ運がない。 – tavier