Hello all,
I'm trying to connect to outlook 365 through my console application(C#) using OAUTH2 but I keep getting **AUTHENTICATE failed (NO)** when authenticating the connection. I have tried the same acquired token with another library and I was able to connect, Authenticate and read my emails.
I also disabled the Multi factor authentication in Azure.
Please advise.
var clientApp = ConfidentialClientApplicationBuilder
.Create("ClientID")
.WithTenantId("TenantID")
.WithClientSecret("ClientSecret")
.Build();
var authenticationResult = await clientApp
.AcquireTokenForClient(new[] { "https://outlook.office365.com/.default"})
.ExecuteAsync();
var accessToken = authenticationResult.AccessToken;
string rawToken = string.Format("user={0}{1}auth=Bearer {2}{1}{1}", email, '\x1', accessToken);
string rawXOAUTH2Token= Convert.ToBase64String(Encoding.ASCII.GetBytes(rawToken));
ComponentPro.Net.Mail.Imap imap = new ComponentPro.Net.Mail.Imap();
await imap.ConnectAsync("outlook.office365.com", 993, SslSecurityMode.Implicit);
await imap.AuthenticateAsync(rawXOAUTH2Token, ImapAuthenticationMethod.OAuth20);
also, another question is, does ComponentPro supports connecting to Office 365 using OAuth2.0? if yes, then why there is the following summary for Enum 'ImapAuthenticationMethod.OAuth20'?
//
// Summary:
// OAuth 2.0 authentication defined by https://developers.google.com/google-apps/gmail/xoauth2_protocol#imap_protocol_exchange
Cheers,
edited 9/29/2022 2:13:27 PM
asked 9/28/2022 2:45:40 PM