私はこれを理解しようとして何時間も費やしました。誰かが助けてくれることを願っています。ユーザーは、Azure AD (Microsoft 組織アカウント) を使用して ASP.NET サイトに対して認証を行います。理想的には、Exchange Web サービスに接続できるようにしたいのですが、資格情報を渡す方法がわかりません。検索から、User.Identity からパスワードを取得する方法がないことがわかりました。
Pop または IMAP で同じ問題が発生しています。
このコードは、「自動検出サービスが見つかりませんでした」を返しています。サーバー名を明示的に伝えると、401 Unauthorized エラーが発生します。
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.UseDefaultCredentials = true;
service.AutodiscoverUrl(User.Identity.Name, RedirectionUrlValidationCallback);
private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
// The default for the validation callback is to reject the URL.
bool result = false;
Uri redirectionUri = new Uri(redirectionUrl);
// Validate the contents of the redirection URL. In this simple validation
// callback, the redirection URL is considered valid if it is using HTTPS
// to encrypt the authentication credentials.
if (redirectionUri.Scheme == "https")
{
result = true;
}
return result;
}