jstedfast / MailKit

A cross-platform .NET library for IMAP, POP3, and SMTP.

Home Page:http://www.mimekit.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] Detecting if Account requires oAuth2

abhay991 opened this issue · comments

So i was checking outlook account and i have 2 of them. One has OAuth enabled and other is disabled so basically what i want to do is if account has it enabled then i will display browser like thunderbird does for getting the required tokens. Question is how do i detect this stuff? It keeps throwing AuthenticationException with message 'LOGIN failed'. Any help is appreciated.

You can check if a server supports OAUTH2 by looking at the values in the *Client.AuthenticationMechanisms property for XOAUTH2 or OAUTH-BEARER (I think Exchange only supports XOAUTH2 and not OAUTH-BEARER, but that could change at any moment since OAUTH-BEARER is now the official standard).

If if contains OAUTH-BEARER, you need to use SaslMechanismOAuthBearer. If, instead, it only contains XOAUTH2, then use SaslMechanismOAuth2. If it doesn't contain either of those, then it doesn't support OAUTH2 at all.

That's detecting if server supports oAuth or not but i am using outlook and there are two different accounts on same host one enabled and one not so i need to detect it for specific account instead of server. Thunderbird does this and displays pop up browser if account has oAuth else directly logs you in if it is disabled.

That's going to be based on the configuration of your Outlook client. There's no way for MailKit to detect that.