There is a slight difference between IMAP/POP3/SMTP and EWS. Unlike the other protocols, the OAuth2 token for EWS is not supposed to be wrapped in "user="/"auth=Bearer" structure along with the user name and then Base64-encoded. Instead, it's just passed to EWS in the original form.
In practical terms, this means that for IMAP, you are probably doing something like this:
// get OAuth 2.0 token
string accessToken = ...;
// prepare token format suitable for IMAP, POP3, or SMTP
string pattern = string.Format("user={0}{1}auth=Bearer {2}{1}{1}", userName, '\x1', accessToken);
string token = Convert.ToBase64String(Encoding.ASCII.GetBytes(pattern));
// authenticate using IMAP
imapClient.Login(token, ImapAuthentication.OAuth20);
But for EWS, you only have to pass the token to the Login
method:
// get OAuth 2.0 token
string accessToken = ...;
// authenticate using EWS
ewsClient.Login(accessToken, EwsAuthentication.OAuth20);
Check out the following sample apps for details: