This project is read-only.

Support for outlook oaut2.0

Topics: Feature Requests, Help requests
Feb 13, 2015 at 3:54 PM
Edited Feb 13, 2015 at 3:55 PM
Hi! do you want to include support for imap with oauth 2.0 authentication for outlook? in your example for download I added the support for oauth 2.0 for outlook but I dnn't understand how to set the cofiguration for outlook here is the link
https://msdn.microsoft.com/en-us/library/dn440163.aspx

Your app/server passes the access token to our IMAP service in the AUTHENTICATE command. We accept a base64-encoded string that contains:
The user name.
The authentication type Bearer for direct OAuth 2.0 requests.
The access token granted by MSA.
For example, your app/server would base-64 encode this string:
user={user@domain.com}^Aauth=Bearer {Access Token}^A^A

The example on the links is this

[connection begins]
C: 000 CAPABILITY
S: * CAPABILITY IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2
S: 000 OK CAPABILITY completed
C: 001 AUTHENTICATE XOAUTH2
S: +
C: {base64-encoded string}
S: * CAPABILITY IMAP4rev1
S: 001 OK OAuth authentication successful
[connection continues]

I change the example added the user and the access token but in you SendAndReceive method doesn't conect I don't know how

If you want I can pass your code example with the modifications for oaut2.0 with outlook
Coordinator
Feb 14, 2015 at 11:09 AM
Edited Feb 14, 2015 at 11:12 AM
Hi apis3445,

when connecting using OAuth2, all you need is to pass the user email as well as the access token in the credentials:
var account = "test@outlook.com";
var accessToken = "your access token for outlook.com"

var client = new ImapClient("imap-mail.outlook.com", true);
if(client.Connect()) {
     client.Credentials = new OAuth2Credentials(account, accessToken);
     if (client.Login()) {
           // success, you can work with your IMAP account now
     }
}                
I added a sample for using Outlook.com OAuth2 in the latest source code (See the C# sample application).

Before you get started, make sure you registered your application at https://account.live.com/developers/applications/index. This is required to get your own Client ID and secret.

Greets,

Pavel
Feb 17, 2015 at 10:30 PM
Hi! thank you! Yahoo now supports oauth 2.0 would you like to include an example for yahoo please?
Coordinator
Feb 20, 2015 at 10:37 PM
Hi apis3445,

I added a sample for Yahoo in the latest source code. Basically you will get the following information from Yahoo:
access_token
xoauth_yahoo_guid // use this as the login name
However, Yahoo requires one more field for authentication, the vendor name. using latest code you can now pass it when creating the OAuth2Credentials object:
var xoauthYahooGuid = "your xoauth_yahoo_guid received in the auth process";
var accessToken = "your access token for yahoo"

var client = new ImapClient("imap.mail.yahoo.com", true);
if(client.Connect()) {
     client.Credentials = new OAuth2Credentials(xoauthYahooGuid, accessToken, "ImapX");
     if (client.Login()) {
           // success, you can work with your IMAP account now
     }
}   
Greets,

Pavel