Trying to access a Google email account via IMAP with OAuth2 using the Chilkat IMAP email component. I am receiving this from the server response...
serverResponse: aaab NO [AUTHENTICATIONFAILED] Invalid credentials (Failure)
We are using VB.NET, and I am following the example at https://www.example-code.com/csharp/gmail_imap_login_oauth2.asp. Connecting to imap.gmail.com using SSL and port 993. I am setting the Imap.AuthMethod = "XOAUTH2"
and using the AuthToken instead of the password. The Imap.Login(LoginName, AuthToken)
is where the error message is coming from.
I have enabled IMAP with the Gmail account, and I have enabled less secure apps. I confirmed the right auth token is getting set for the password, and I have checked the API scope is properly set to https://mail.google.com/. If I just try straight Login Name and Password the login is successful.
Not sure what else to check to figure out what is causing the Invalid credentials error.
The cause of this problem was found.
In the call to Login, the application was passing "Bearer " instead of just "" for the password:
Correct: success = imap.Login("user@gmail.com","");
Incorrect: success = imap.Login("user@gmail.com","Bearer ");
The access token is considered to be the password. Chilkat adds the required "Bearer" string internally when composes the XOAUTH2 data sent to the IMAP server.