jstedfast / MailKit

A cross-platform .NET library for IMAP, POP3, and SMTP.
http://www.mimekit.net
MIT License
6.25k stars 828 forks source link

office 365 oauth2 error #178

Closed yuribb closed 9 years ago

yuribb commented 9 years ago

Hi there I'm using Mailkit (from nuget) with an Office365 account and when I try to authenticate from oauth2 mechanism (using http://blogs.msdn.com/b/exchangedev/archive/2014/03/25/using-oauth2-to-access-calendar-contact-and-mail-api-in-exchange-online-in-office-365.aspx and this https://github.com/OfficeDev/PnP/blob/master/Samples/Office365Api.Overview/Office365Api.Helpers/AuthenticationHelper.cs as a password, but authentication is failed. This problem of solutions of Office 365 doesn't support oauth2 from imap?

jstedfast commented 9 years ago

I don't have an Office365 account so I can't easily debug it. Maybe you could get me the logs?

yuribb commented 9 years ago
Connected to imaps://outlook.office365.com:993/
S: * OK The Microsoft Exchange IMAP4 service is ready. [QQBNAFMAUABSADAANABDAEEAMAAwADMANAAuAGUAdQByAHAAcgBkADAANAAuAHAAcgBvAGQALgBvAHUAdABsAG8AbwBrAC4AYwBvAG0A]
C: A00000000 CAPABILITY
S: * CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS MOVE ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
S: A00000000 OK CAPABILITY completed.
C: A00000001 AUTHENTICATE XOAUTH2 dXNlcj15dXJpLmJAdXBzYWZlLm9ubWljcm9zb2Z0LmNvbQFhdXRoPUJlYXJlciBBQUFCQUFBQXZQTTFLYVBsckVxZEZTQnpqcWZUR0M4ZENqX3J5QU50M3VFM25ESWZVaFpNdnpBazliUVMxQUhiZVdMVU4yMFk2ajlLc1dULXJRR2xOUFl0RXdNUDNDbXFDSG0ydE1haG94aHdPU3ktdFRXOExyNUdmRFpFcVpxa3J1RDJ1Mm8zUE5MNnRwT21tRm5XQWtweHJ3MlREdVNTamFPOGg3R1g1WkhOajZTdzZtVnNsOGM0RkpOdjRFdlVhdUp6ekpyREJkNUhSdVFjQXNLUGNNQ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gdkp1ekNtZVpBUEVsenVpaEd4N0hMYm9IMmdQT2hPRVl1UnRIdE5sMXZhWjZ3Ni1la19Cbk9mOEtXNERKTWJKOUstVlpaME92dy1BNlR6bmgyQjJ1eGFubXA1QnZjQW9WamUydGpjZ0ZiS3BhaFNxblIzeGQtX3U0azNPNUYyMENKNnU2S3Vwd2ZENmM5RHJsY1diZFZfNU1VaVUzMkVVV3JPZEhRX2Vob1dqb0gycmI0SjBsVUdkcTFpcUlUbTVHcWdhcXc3aTFJSkRwTkNxZi1RREFuRG5JTDVHdTJVN3lsSUFBJnN0YXRl
S: A00000002 NO AUTHENTICATE failed.
C: A00000003 LOGIN yuri.b@donotshowme.onmicrosoft.com AAABAAAAvPM1KaPlrEqdFSBzjqfTGC8dCj_ryANt3uE3nDIfUhZMvzAk9bQS1AHbeWLUN20Y6j9KsWT-rQGlNPYtEwMP3CmqCHm2tMahoxhwOSy-tTW8Lr5GfDZEqZqkruD2u2o3PNL6tpOmmFnWAkpxrw2TDuSSjaO8h7GX5ZHNj6Sw6mVsl8c4FJNv4EvUauJzzJrDBd5HRuQcAsKPcMCk4YawTZzjJupGxs9jfbpnOnF3RPxOx_ZPzNGwnAG_lh3g_JmEHukotHK_MpRAkcuGMIkmYyMQuT5x_uYT_K-jYrtY4dCscQLto34EHh9gKxeusDKEofDanR7wIq5UbibXHBxYAjUCRxXTlnFvJuzCmeZAPElzuihGx7HLboH2gPOhOEYuRtHtNl1vaZ6w6-ek_BnOf8KW4DJMbJ9K-VZZ0Ovw-A6Tznh2B2uxanmp5BvcAoVje2tjcgFbKpahSqnR3xd-_u4k3O5F20CJ6u6KupwfD6c9DrlcWbdV_5MUiU32EUWrOdHQ_ehoWjoH2rb4J0lUGdq1iqITm5Gqgaqw7i1IJDpNCqf-QDAnDnIL5Gu2U7ylIAA&state
S: A00000003 NO LOGIN failed.
jstedfast commented 9 years ago

What value are you using as the password? It looks like you are using the wrong one.

jstedfast commented 9 years ago

You need to use the access_token which is the base64 url encoded JSON web token for API access.

The string you are using as a password is NOT base64-encoded JSON.

yuribb commented 9 years ago

Thank you for answer. I forget step four in solution. I got an access_token from JSON, but it still not work. Logs:

Connected to imaps://outlook.office365.com:993/
S: * OK The Microsoft Exchange IMAP4 service is ready. [QQBNAFMAUABSADAANABDAEEAMAAwADQAMgAuAGUAdQByAHAAcgBkADAANAAuAHAAcgBvAGQALgBvAHUAdABsAG8AbwBrAC4AYwBvAG0A]
C: A00000000 CAPABILITY
S: * CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS MOVE ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
S: A00000000 OK CAPABILITY completed.
C: A00000001 AUTHENTICATE XOAUTH2 dXNlcj15dXJpLmJAdXBzYWZlLm9ubWljcm9zb2Z0LmNvbQFhdXRoPUJlYXJlciBleUowZVhBaU9pSktWMVFpTENKaGJHY2lPaUpTVXpJMU5pSXNJbmcxZENJNklrMXVRMTlXV21OQlZHWk5OWEJQV1dsS1NFMWlZVGxuYjBWTFdTSjkuZXlKaGRXUWlPaUpvZEhSd2N6b3ZMMjkxZEd4dmIyc3ViMlptYVdObE16WTFMbU52YlM4aUxDSnBjM01pT2lKb2RIUndjem92TDNOMGN5NTNhVzVrYjNkekxtNWxkQzgyTW1ReE5tVTNaaTFqTm1NM0xUUXpaR010WVRNeFppMW1NVGxrTURRNU5UQTVZV1l2SWl3aWFXRjBJam94TkRJNU1UZzFOREF4TENKdVltWWlPakUwTWpreE9EVTBNREVzSW1WNGNDSTZNVFF5T1RFNE9UTXdNU3dpZG1WeUlqb2lNUzR3SWl3aWRHbGtJam9pTmpKa01UWmxOMll0WXpaak55MDBNMlJqTFdFek1XWXRaakU1WkRBME9UVXdPV0ZtSWl3aWIybGtJam9pTUdOa05HTTBZamd0TXpobE5pMDBZV1l5TFdJNVpEQXROalkyT1RFMVkyWmhZVFl4SWl3aWRYQnVJam9pZVhWeWFTNWlRSFZ3YzJGbVpTNXZib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RIwP9IuAXhoeG00AUq_OTrNlsj50iigfHI0iI2-shE3jIVwnCin5STtMc2A
S: A00000003 NO LOGIN failed.
jstedfast commented 9 years ago

The password string you are using is still not valid base64 JSON. I don't know what you're using, but it's still the wrong value.

yuribb commented 9 years ago

This is an access_token from JSON, responsed by microsoft. All JSON response look like this: {"token_type":"Bearer","expires_in":"3600","expires_on":"1429194411","not_before":"1429190511","resource":"https://outlook.office365.com/","access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik1uQ19WWmNBVGZNNXBPWWlKSE1iYTlnb0VLWSJ9.eyJhdWQiOiJodHRwczovL291dGxvb2sub2ZmaWNlMzY1LmNvbS8iLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC82MmQxNmU3Zi1jNmM3LTQzZGMtYTMxZi1mMTlkMDQ5NTA5YWYvIiwiaWF0IjoxNDI5MTkwNTExLCJuYmYiOjE0MjkxOTA1MTEsImV4cCI6MTQyOTE5NDQxMSwidmVyIjoiMS4wIiwidGlkIjoiNjJkMTZlN2YtYzZjNy00M2RjLWEzMWYtZjE5ZDA0OTUwOWFmIiwib2lkIjoiMGNkNGM0YjgtMzhlNi00YWYyLWI5ZDAtNjY2OTE1Y2ZhYTYxIiwidXBuIjoieXVyaS5iQHVwc2FmZS5vbm1pY3Jvc29mdC5jb20iLCJwdWlkIjoiMTAwMzNGRkY4REFEQjMzQSIsInN1YiI6ImlvaUlPbUc5ZWlCX3hyRVowc2N6MmNVRnRSdUQ4RVVBTFhBaWNtWHdHZVEiLCJnaXZlbl9uYW1lIjoiWXVyaSIsImZhbWlseV9uYW1lIjoiQiIsIm5hbWUiOiJZdXJpIEIiLCJhbXIiOlsicHdkIl0sImdyb3VwcyI6WyJlMjk4OTdhZi03OGUyLTQ2ZTctOTEyOS1lMmI5N2JkYzdmZjgiXSwidW5pcXVlX25hbWUiOiJ5dXJpLmJAdXBzYWZlLm9ubWljcm9zb2Z0LmNvbSIsImFwcG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3mVP0Jn1SwI38Dvm9L7UdlQBN3slTiL57hmVdE6HSAA","scope":"Mail.Read Mail.Send Mail.Write","id_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiJjNWZiMDg2OC1lYTg0LTQ4MTUtYjVjZC1iMWIxYWIzYTdlZjIiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC82MmQxNmU3Zi1jNmM3LTQzZGMtYTMxZi1mMTlkMDQ5NTA5YWYvIiwiaWF0IjoxNDI5MTkwNTExLCJuYmYiOjE0MjkxOTA1MTEsImV4cCI6MTQyOTE5NDQxMSwidmVyIjoiMS4wIiwidGlkIjoiNjJkMTZlN2YtYzZjNy00M2RjLWEzMWYtZjE5ZDA0OTUwOWFmIiwib2lkIjoiMGNkNGM0YjgtMzhlNi00YWYyLWI5ZDAtNjY2OTE1Y2ZhYTYxIiwidXBuIjoieXVyaS5iQHVwc2FmZS5vbm1pY3Jvc29mdC5jb20iLCJzdWIiOiJyUnRrUURaUVNWeXpUT3ItOEMzM2pLdlRWS0lRUzdCVDFJZ1FxWTczTWxZIiwiZ2l2ZW5fbmFtZSI6Ill1cmkiLCJmYW1pbHlfbmFtZSI6IkIiLFEaNW1lIjoiWXVyaSBCIiwiYW1yIjpbInB3ZCJdLCJncm91cHMiOlsiZTI5ODk3YWYtNzhlMi00NmU3LTkxMjktZTJiOTdiZGM3ZmY4Il0sInVuaXF1ZV9uYW1lIjoieXVyaS5iQHVwc2FmZS5vbm1pY3Jvc29mdC5jb20iLCJwd2RfZXhwIjoiNjE3Njc4ODMiLCJwd2RfdXJsIjoiaHR0cHM6Ly9wb3J0YWwubWljcm9zb2Z0b25saW5lLmNvbS9DaGFuZ2VQYXNzd29yZC5hc3B4In0.","pwd_exp":"61767883","pwd_url":"https://portal.microsoftonline.com/ChangePassword.aspx"}.

jstedfast commented 9 years ago

Try using the id_token instead.

yuribb commented 9 years ago

No, it doesn't work :(

jstedfast commented 9 years ago

Try this before you call Authenticate():

client.Capabilities &= ~ImapCapabilities.SaslIR;
yuribb commented 9 years ago

Authentication failed.

Connected to imaps://outlook.office365.com:993/
S: * OK The Microsoft Exchange IMAP4 service is ready. [QQBNAFMAUABSADAANABDAEEAMAAwADIAMQAuAGUAdQByAHAAcgBkADAANAAuAHAAcgBvAGQALgBvAHUAdABsAG8AbwBrAC4AYwBvAG0A]
C: A00000000 CAPABILITY
S: * CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS MOVE ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
S: A00000000 OK CAPABILITY completed.
C: A00000001 AUTHENTICATE XOAUTH2
S: +
C: dXNlcj15dXJpLmJAdXBzYWZlLm9ubWljcm9zb2Z0LmNvbQFhdXRoPUJlYXJlciBaWGxLTUdWWVFXbFBhVXBMVmpGUmFVeERTbWhpUjJOcFQybEtVMVY2U1RGT2FVbHpTVzVuTVdSRFNUWkphekYxVVRFNVYxZHRUa0pXUjFwT1RsaENVRmRYYkV0VFJURnBXVlJzYm1Jd1ZreFhVMG81TG1WNVNtaGtWMUZwVDJsS2IyUklVbmRqZW05MlRESTVNV1JIZUhaaU1uTjFZakphYldGWFRteE5lbGt4VEcxT2RtSlRPR2xNUTBwd1l6Tk5hVTlwU205a1NGSjNZM3B2ZGt3elRqQmplVFV6WVZjMWEySXpaSHBNYlRWc1pFTTRNazF0VVhoT2JWVXpXbWt4YWs1dFRUTk1WRkY2V2tkTmRGbFVUWGhhYVRGdFRWUnNhMDFFVVRWT1ZFRTFXVmRaZGtscGQybGhWMFl3U1dwdmVFNUVTVFZOVkd0NVRrUk5lVXhEU25WWmJWbHBUMnBGTUUxcWEzaFBWRWt3VFhwSmMwbHRWalJqUTBrMlRWUlJlVTlVUlRWT2FrMTZUV2wzYVdSdFZubEphbTlwVFZNMGQwbHBkMmxrUjJ4clNXcHZhVTVxU210TlZGcHNUakpaZEZsNldtcE9lVEF3VFRKU2FreFhSWHBOVj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WTJRdFlqRmlNV0ZpTTJFM1pXWXlJaXdpWVhCd2FXUmhZM0lpT2lJeElpd2ljMk53SWpvaVRXRnBiQzVTWldGa0lFMWhhV3d1VTJWdVpDQk5ZV2xzTGxkeWFYUmxJaXdpWVdOeUlqb2lNU0o5LnRMWWVPWnJUQVZTbDQzMGF5VDVkdVU1cmhpMVVrMmtFN0JxZEkybk9WUG1mU3Z6NVNZbmxCTW85dEphblhWVWxFckJUQ296dFBOajhPbDBwQW1MNmVXdXp0dG1ncWRBaVhnRnVoaGpjNGE1QUQ5VHZXd3JDVEZLeV93OF81d2dnQktiLUpkb3NmYzZSdDBoQ1VJaENpOU8xSkt1Vk1ES3lhTEhpS2k4NzZNMS1xbEYwMjJNQm1ldHVTTnp6NnhrNmdHQlViMUxxZEx6VVg1THJVdmhrYW1XX0ZNa1dLTlItUzZPRk85Rm9qb19xV1pSZWRzWXJ0anNqZ3ZPZGZsbXptNDhaWXA4ZU9tandYTmR5SEtxWXF2eWRsUlY3OGxUTldFNjREZU5tZGNIcUpfSEN4THVCa255a0dCdm9oTWxtdUR2QzI0cG9VUXcwa1RURnNZdlRSZw==
S: A00000003 NO LOGIN failed.
jstedfast commented 9 years ago

I have no idea what else to suggest. I know the XOAUTH2 code is correct (it works fine with GMail), so I know it's not a bug in MailKit.

jstedfast commented 9 years ago

FWIW, http://blogs.office.com/2013/09/12/outlook-com-now-has-imap/ explains:

Both IMAP and SMTP accept a base64-encoded string as below, where {user@domain.com} is the user’s account, {access token} is the OAuth access token, and ^A are Ctrl-A characters (U+0001):

user={user@domain.com}^Aauth=Bearer {access token}^A^A

If you look at https://github.com/jstedfast/MailKit/blob/master/MailKit/Security/SaslMechanismOAuth2.cs#L104, that's exactly what the MailKit code does.

This suggests that you are either giving it the wrong userName or the wrong auth_token value.

yuribb commented 9 years ago

This article about Outlook.com. XOAUTH2 code works with Outlook.com correct. I work with office 365 Outlook. Access token of outlook.com look like access token of gmail (short base64 string).

jstedfast commented 9 years ago

Ah, right, office365.com isn't the same as office.com. The XOATH2 authentication mechanism should work the same for all IMAP servers, though.

yuribb commented 9 years ago

i trying to found solve the problem in stackoverflow. And that the answer of my question http://stackoverflow.com/questions/29747477/imap-auth-in-office-365-using-oauth2-mechnism

jstedfast commented 9 years ago

Thanks for the update. I guess that explains why it wasn't working...

erikporter commented 9 years ago

Great to see an official statement from them about it. I was never able to get it to work either. Good to know for sure that they don't support it and have no plans to support it.

zousq19910623 commented 6 years ago

http://stackoverflow.com/questions/29747477/imap-auth-in-office-365-using-oauth2-mechnism this website is not found.

jstedfast commented 6 years ago

It seems to work for me. Could it be that you are just blocked from StackOverflow?

Here's a screenshot of the answer for your convenience.

oauthforoffice365notsupportedanswer
AlexanderPilhar commented 4 years ago

They have updated this question with another answer, stating they are working on OAuth support: IMAP auth in Office 365 using OAuth2