Tuesday, August 5, 2014

JavaMail - OAuth connexion failed




Hello,




I tryed to connect oAuth2 with gmail.




In command line, no problem. But with Javamail it failed.




The source of the exemple are here : http://ift.tt/1noPFWF




Last modified is in 2012 then, maybe, this code is obsolete.




In command line it works fine :






Java Code:






openssl s_client -crlf -connect imap.gmail.com:993
A002 AUTHENTICATE XOAUTH2
+
my_token_who_end_with__
Response : A002 OK myaddress@gmail.com ForName Name authenticated (Success)




Did one of you know what is the problem ?

For information :



- it failed with token and refresh token



- here are the logs :






Java Code:






DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle]
DEBUG IMAPS: mail.imap.fetchsize: 16384
DEBUG IMAPS: mail.imap.ignorebodystructuresize: false
DEBUG IMAPS: mail.imap.statuscachetimeout: 1000
DEBUG IMAPS: mail.imap.appendbuffersize: -1
DEBUG IMAPS: mail.imap.minidletime: 10
DEBUG IMAPS: disable AUTH=LOGIN
DEBUG IMAPS: disable AUTH=PLAIN
DEBUG IMAPS: enable SASL
DEBUG IMAPS: SASL mechanisms allowed: XOAUTH2
DEBUG IMAPS: trying to connect to host "imap.gmail.com", port 993, isSSL true
* OK Gimap ready for requests from 195.6.245.82 i1mb40455339wjn
A0 CAPABILITY
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH AUTH=XOAUTH2 AUTH=PLAIN AUTH=PLAIN-CLIENTTOKEN
A0 OK Thats all she wrote! i1mb40455339wjn
DEBUG IMAPS: AUTH: XOAUTH
DEBUG IMAPS: AUTH: XOAUTH2
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: AUTH: PLAIN-CLIENTTOKEN
DEBUG IMAPS: protocolConnect login, host=imap.gmail.com, user=myaddress@gmail.com, password=<non-null>
DEBUG IMAPS: SASL authentication command trace suppressed
DEBUG IMAPS: SASL Mechanisms:
DEBUG IMAPS: XOAUTH2
DEBUG IMAPS:
DEBUG IMAPS: SASL client XOAUTH2
DEBUG IMAPS: SASL callback length: 1
DEBUG IMAPS: SASL callback 0: javax.security.auth.callback.NameCallback@45258dfd
DEBUG IMAPS: SASL no response
Exception : -->javax.mail.AuthenticationFailedException: [ALERT] Invalid credentials (Failure) at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:715) at javax.mail.Service.connect(Service.java:364) at com.myproject.MailboxHelper.testMailboxWithOAuth(MailboxHelper.java:179)




Best regards




No comments:

Post a Comment