使用IMAP和OAUTH2从Office 365下载消息
我需要使用IMAP从Office 365服务器检索电子邮件。这些电子邮件将具有需要在C#中处理的附件,然后发布给另一个第三方。
最初,我们需要连接,但我会得到一个例外。这是我当前的代码:
var options = new PublicClientApplicationOptions {
ClientId = "12345...",
TenantId = "67890...",
RedirectUri = "https://login.microsoftonline.com/common/oauth2/nativeclient"
};
var publicClientApplication = PublicClientApplicationBuilder
.CreateWithApplicationOptions (options)
.Build ();
var scopes = new string[] {
"email",
"offline_access",
"https://outlook.office.com/IMAP.AccessAsUser.All", // Only needed for IMAP
//"https://outlook.office.com/POP.AccessAsUser.All", // Only needed for POP
//"https://outlook.office.com/SMTP.Send", // Only needed for SMTP
};
var authToken = await publicClientApplication.AcquireTokenInteractive (scopes).ExecuteAsync ();
var oauth2 = new SaslMechanismOAuth2 (authToken.Account.Username, authToken.AccessToken);
using (var client = new ImapClient (new ProtocolLogger("imap.log"))) {
await client.ConnectAsync ("outlook.office365.com", 993, SecureSocketOptions.SslOnConnect);
await client.AuthenticateAsync (oauth2);
await client.DisconnectAsync (true);
}
我没有管理员访问服务器或用户帐户的访问。为我提供了租户ID,客户ID,秘密价值和秘密ID。
运行时,以上代码会在uplinClientApplication.acquiretoken Interactive
上引发异常。
Microsoft.Identity.Client.MSAlClientException:'仅循环重定向 乌里得到了支持,但是urn:ietf:wg:oauth:2.0:被发现了OOB。配置 http:// localhost或http:// localhost:在应用程序注册期间两者端口 当您创建uplinClientApplication对象时。看 https://aka.ms/msal net-net-net-net-net-os-browser 有关详细信息'
我已经阅读了推荐的URL,但是我仍然不清楚为什么会发生这种情况。谁能帮助我了解纠正此问题需要做什么?
I need to retrieve email from an Office 365 server using IMAP. The emails will have attachments that need to be processed in C#, then published to another 3rd party.
Initially, we need to connect, but I'm getting an Exception. Here is my current code:
var options = new PublicClientApplicationOptions {
ClientId = "12345...",
TenantId = "67890...",
RedirectUri = "https://login.microsoftonline.com/common/oauth2/nativeclient"
};
var publicClientApplication = PublicClientApplicationBuilder
.CreateWithApplicationOptions (options)
.Build ();
var scopes = new string[] {
"email",
"offline_access",
"https://outlook.office.com/IMAP.AccessAsUser.All", // Only needed for IMAP
//"https://outlook.office.com/POP.AccessAsUser.All", // Only needed for POP
//"https://outlook.office.com/SMTP.Send", // Only needed for SMTP
};
var authToken = await publicClientApplication.AcquireTokenInteractive (scopes).ExecuteAsync ();
var oauth2 = new SaslMechanismOAuth2 (authToken.Account.Username, authToken.AccessToken);
using (var client = new ImapClient (new ProtocolLogger("imap.log"))) {
await client.ConnectAsync ("outlook.office365.com", 993, SecureSocketOptions.SslOnConnect);
await client.AuthenticateAsync (oauth2);
await client.DisconnectAsync (true);
}
I don't have Administrator access to the server or user account. I've been provided with a Tenant Id, Client Id, Secret Value, and Secret Id.
When run, the above code throws an Exception on publicClientApplication.AcquireTokenInteractive
...
Microsoft.Identity.Client.MsalClientException: 'Only loopback redirect
uri is supported, but urn:ietf:wg:oauth:2.0:oob was found. Configure
http://localhost or http://localhost:port both during app registration
and when you create the PublicClientApplication object. See
https://aka.ms/msal-net-os-browser for details'
I have read the referred URL, but it's still not clear to me why this is happening. Can anyone help me understand what is needed to be done to correct this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论