我一直在关注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