5

I can't seem to figure out how to get mbsync to work with OAuth for Gmail because I can't get mbsync to find the xoauth2 sasl plugin on Ubuntu. I'm fairly confident that everything about my mbsync config for OAuth is working correctly (e.g. manually testing the PassCmd successfully generates an access token)

edit: I have installed sasl-bin via apt, and https://github.com/robn/sasl2-oauth from source.


Questions

  • How can I manually "register" a sasl plugin for mbsync? (aka add it to the list of 'available' SASL mechanisms in the first log pasted below)
  • Could this issue be due to another component in my "email stack"? Some threads I've read suggest recompiling mutt from source, but I don't understand why mutt would be causing auth problems.

Using mbsync installed via nix-env, I haven't been able to get past

C: 0/1  B: 0/0  M: +0/0 *0/0 #0/0  S: +0/0 *0/0 #0/0
IMAP error: selected SASL mechanism(s) not available;
   selected: XOAUTH2
   available: GS2-IAKERB GS2-KRB5 SCRAM-SHA-1 SCRAM-SHA-256 GSS-SPNEGO GSSAPI DIGEST-MD5 EXTERNAL OTP CRAM-MD5 PLAIN LOGIN ANONYMOUS
C: 1/1  B: 0/0  M: +0/0 *0/0 #0/0  S: +0/0 *0/0 #0/0

I've also tried reinstalling mbsync/isync from apt, as well as building isync from the source. Both of which result in the following error.

Notice: Master/Slave are deprecated; use Far/Near instead.
C: 0/1  B: 0/0  F: +0/0 *0/0 #0/0  N: +0/0 *0/0 #0/0
Error: SASL(-1): generic failure: Unable to find a callback: 32775
C: 1/1  B: 0/0  F: +0/0 *0/0 #0/0  N: +0/0 *0/0 #0/0

3 Answers 3

8

Thanks to your previous hints. I've managed to get XOAUTH2 working in SASL and use it with mbsync. Here is how I got it working on my Ubuntu 20.10:

Install Cyrus SASL OAuth2

# Clone the Cyrus SASL OAuth2 sources.
git clone https://github.com/moriyoshi/cyrus-sasl-xoauth2.git

# Configure and make.
cd cyrus-sasl-xoauth2
./autogen.sh
./configure

# SASL2 libraries on Ubuntu are in /usr/lib/x86_64-linux-gnu/; modify the Makefile accordingly
sed -i 's%pkglibdir = ${CYRUS_SASL_PREFIX}/lib/sasl2%pkglibdir = ${CYRUS_SASL_PREFIX}/lib/x86_64-linux-gnu/sasl2%' Makefile

make
sudo make install

# Verify XOAUTH2 is known to SASL.
saslpluginviewer | grep XOAUTH2

mbsync

Older versions (up to 1.3.1?) have PassCmd buffer set to 80 -- and this is not enough for OAuth2 tokens. I compiled the current 1.4.0:

# Clone the isync/mbsync 1.4 sources.
git clone --branch 1.4 --depth 1 https://git.code.sf.net/p/isync/isync isync-isync

# Configure and make.
cd isync-isync
./autogen.sh
./configure
make

mutt_oauth2.py

Download mutt_oauth2.py from https://gitlab.com/muttmua/mutt/-/blob/master/contrib/mutt_oauth2.py and make it executable.

I have a modified version that creates a socket with OAuth2 tokens. So I can then access the tokens via the socket:

curl --unix-socket ~/.mutt/oauth2.socket x

Please note that your mileage may vary and you will need a different PassCmd to access the OAuth2 tokens.

mbsyncrc

Configure mbsync to use XOAUTH2 and set PassCmd to execute the above curl command:

IMAPAccount <account-name>
Host outlook.office365.com
User <[email protected]>
AuthMechs XOAUTH2
PassCmd "curl --unix-socket ~/.mutt/oauth2.socket x"
SSLType IMAPS
SSLVersions TLSv1.1 TLSv1.2

mbsync then works as expected; notice the output from curl below:

$ mbsync -a
C: 0/1  B: 0/0  F: +0/0 *0/0 #0/0  N: +0/0 *0/0 #0/0  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1963    0  1963    0     0   479k      0 --:--:-- --:--:-- --:--:--  479k
C: 1/1  B: 15/15  F: +0/0 *0/0 #0/0  N: +847/847 *0/0 #0/0

3
  • 1
    Hi! I used something similar on Unix in the past, but can't get cyrus-sasl-xoauth2 to work on Mac OS. Do you know how that might work?
    – guibor
    Jun 25, 2021 at 16:12
  • 1
    Thanks for this step-by-step. Could you elaborate on why the socket with OAuth2 tokens useful? Also, can you link to your modified version?
    – Tohiko
    Oct 4, 2021 at 10:38
  • For me, using the original script mutt_oauth2.py directly in the PassCmd worked, after setting up a token as explained in the mutt_oauth2.py README: PassCmd="path/to/mutt2_oauth2.py path/to/token". But I also had to install libsasl2-modules-kdexoauth2 as mentioned in @Rovanion's answer, as well as sasl-xoauth2 and set up the /etc/sasl-xoauth2.conf config file Jul 3 at 2:30
2

On Ubuntu 22.10 installing libsasl2-modules-kdexoauth2 solved the "IMAP error: selected SASL mechanism(s) not available;" issue for me.

0

I am working on figuring out the same issue. Here are some resources that may help.

  1. https://bbs.archlinux.org/viewtopic.php?id=238727
  2. https://isync-devel.narkive.com/i6h4k9hB/mbsync-xoauth2-and-gmail
  3. http://blog.onodera.asia/2020/06/how-to-use-google-g-suite-oauth2-with.html

I haven't succeeded in fixing the error but it seems you need to have https://www.cyrusimap.org/sasl/ installed. Next, use one of these plugins:

Hope that helps. I'll keep trying to see if I can get all this to work.

3
  • Thanks, yea seems like we're in a similar place. But the threads I've found where someone fixes this issue are always arch related fixes.
    – jackmac92
    Dec 23, 2020 at 21:19
  • Have you tried installing this? github.com/moriyoshi/cyrus-sasl-xoauth2.That seems promising but having some issues that are OSX issues.
    – Carlos
    Dec 24, 2020 at 1:55
  • yea I think I had before, and just re-compiled but mbsync still doesn't see it as an available SASL mechanism. After building there is output about from the install about how to link with the library. But not sure what I need to rebuild with this lib linked
    – jackmac92
    Dec 25, 2020 at 21:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .