You are not logged in.

#1 2020-07-05 21:36:45

redshoe
Member
Registered: 2015-12-16
Posts: 250

[SOLVED] Authentication failure in mutt. one using OAuth

So, I have four email accounts and one of them uses OAuth authentication (which is personal gmail account). Other accounts just work fine, but when I include this email in muttrc and startup mutt, it gives me authentication failure with the following error message.

OAUTHBEARER authentication failed.

But, if I don't include this particular email in my muttrc and run mutt everything works fine. Is this problem of $folder variable confusion for mutt?

My muttrc file is like the following.

# General options
set header_cache     = "~/.cache/mutt"
set message_cachedir = "~/.cache/mutt"
unset imap_passive
set imap_keepalive   = 300
set mail_check       = 120
set mbox_type        = Maildir
set sort             = reverse-date-received
set editor           = vim
 
# email1
source "~/.mutt/email1"
folder-hook $folder "source ~/.mutt/email1"
 
# email2
source "~/.mutt/email2"
folder-hook $folder "source ~/.mutt/email2"
 
# email3
source "~/.mutt/email3"
folder-hook $folder "source ~/.mutt/email3"
 
# email4
source "~/.mutt/email4"
folder-hook $folder "source ~/.mutt/email4"
 
macro index <f2> '<sync-mailbox><enter-command>source ~/.mutt/email1<enter><change-folder>!<enter>'
macro index <f3> '<sync-mailbox><enter-command>source ~/.mutt/email2<enter><change-folder>!<enter>'
macro index <f4> '<sync-mailbox><enter-command>source ~/.mutt/email3<enter><change-folder>!<enter>'
macro index <f5> '<sync-mailbox><enter-command>source ~/.mutt/email4<enter><change-folder>!<enter>'
  
bind index "G" imap-fetch-mail

Email1,3,4 has the following setting format (they are similar)

# Encrypted password
source "gpg -d ~/.mutt/ps/ps.gpg |"
 
# Receiving options
set imap_user           =  "email134@gmail.com"
set imap_authenticators =  ""
set folder              =  "imaps://email134@gmail.com@imap.gmail.com:993"
set spoolfile           =  "+INBOX"
set postponed           =  "+Drafts"
set record              =  "+Sent"
 
# Sending options
set smtp_url            =  "smtps://email134@gmail.com@smtp.gmail.com:465"
set from                =  "email134@gmail.com"
 
# Connection security settings
set ssl_force_tls       =  yes
 
# Hook
account-hook $folder "set imap_user = email134@gmail.com"

Email2 has the OAuth authentication and its setting is like the following

# Encrypted password
source "gpg -d ~/.mutt/ps/ps.gpg |"
 
# Receiving options
set imap_user                    =  "email2@gmail.com"
set imap_authenticators          =  "oauthbearer"
set imap_oauth_refresh_command   =  "python2 ~/.mutt/oauth2.py --quiet --user=email2@gmail.com --client_id=client_id --client_secret=client_secret --refresh_token=refresh_token"
set smtp_authenticators          =  "oauthbearer"
set smtp_oauth_refresh_command   =  "python2 ~/.mutt/oauth2.py --quiet --user=email2@gmail.com --client_id=client_id --client_secret=client_secret --refresh_token=refresh_token"

set folder                       =  "imaps://email2@gmail.com@imap.gmail.com:993"
set spoolfile                    =  "+INBOX"
set postponed                    =  "+Drafts"
set record                       =  "+Sent"
 
# Sending options
set smtp_url                     =  "smtps://smtp.gmail.com:465"
set from                         =  "email2@gmail.com"
 
# Connection security settings
set ssl_force_tls                =  yes
 
# Hook
account-hook $folder "set imap_user = email2@gmail.com"

Last edited by redshoe (2020-07-05 23:19:21)

Offline

#2 2020-07-05 23:18:45

redshoe
Member
Registered: 2015-12-16
Posts: 250

Re: [SOLVED] Authentication failure in mutt. one using OAuth

Ahh... I think I understood the muttrc wrong. I fixed it somehow.

Here is my muttrc now.

# General options
set header_cache     = "~/.cache/mutt"
set message_cachedir = "~/.cache/mutt"
unset imap_passive
set imap_keepalive   = 300
set mail_check       = 120
set mbox_type        = Maildir
set sort             = reverse-date-received
set editor           = vim
 
# Default account (Stony Brook)
source "~/.mutt/email1"
 
# Folder hooks
folder-hook "email1@gmail.com" "source ~/.mutt/email1"
folder-hook "email2@gmail.com" "source ~/.mutt/email2"
folder-hook "email3@gmail.com" "source ~/.mutt/email3"
folder-hook "email4@gmail.com" "source ~/.mutt/email4"
 
# Macro for switching accounts
macro index <f2> '<sync-mailbox><enter-command>source ~/.mutt/stonyb<enter><change-folder>!<enter>'
macro index <f3> '<sync-mailbox><enter-command>source ~/.mutt/wreckd<enter><change-folder>!<enter>'
macro index <f4> '<sync-mailbox><enter-command>source ~/.mutt/bumrin<enter><change-folder>!<enter>'
macro index <f5> '<sync-mailbox><enter-command>source ~/.mutt/umich<enter><change-folder>!<enter>'

bind index "G" imap-fetch-mail

Offline

#3 2025-06-25 11:15:23

frisket
Member
Registered: 2021-05-22
Posts: 3

Re: [SOLVED] Authentication failure in mutt. one using OAuth

This almost works for me (I no longer get the SASL error) but it now says "No authenticators available".

redshoe wrote:
set imap_authenticators          =  "oauthbearer"

What is oauthbearer and where do I get it from?

Offline

#4 2025-06-25 12:42:51

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 69,766

Re: [SOLVED] Authentication failure in mutt. one using OAuth

Nowhere, it's a module in mutt - the this is a dated thread and it references python2 scripts which is neither what you want, nor likely will it work on your system.
You're gonna use /usr/share/doc/mutt/samples/mutt_oauth2.py and there's also a .README next to it.

Edit

set from = "your@email.com"
set realname = "Your Name"
set imap_user = "your@email.com"
set imap_pass = "supersecretpassword"
set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set postponed ="+[Gmail]/Drafts"
set smtp_url = "smtps://your@email.com@smtp.gmail.com:465/"
set smtp_pass = "supersecretpassword"

set imap_authenticators="oauthbearer:xoauth2"
set imap_oauth_refresh_command="/home/USERNAME/.mutt/oauth2.sh"
set smtp_authenticators=${imap_authenticators}
set smtp_oauth_refresh_command=${imap_oauth_refresh_command}


account-hook $folder "set imap_user=your@email.com imap_pass=supersecretpassword imap_authenticators='oauthbearer:xoauth2'"

~/.mutt/oauth2.sh
This checks the authorization and will otherwise send a notification. Dunst handles the click to open the google account verification in your browser.

#!/bin/sh
cd ~/.mutt # location of the token
./mutt_oauth2.py your.email.com $@ && exit
mkfifo /tmp/.oauth.mutt
(sleep 5; dunstify -a OAuth2 "mutt OAuth2 request" '<a href="'$(head -n1 /tmp/.oauth.mutt)'">Authenticate mutt with Google</a>') &
~/.mutt/mutt_oauth2.py your.email.com --authflow localhostauthcode --authorize > /tmp/.oauth.mutt
# optional last step, open a url to automatically log out from google again, .openurl.sh is a local script to discriminate urls - you can just say "firefox"
.openurl.sh 'https://accounts.google.com/Logout?service=mail'

dunst config

[oauth]
    appname = OAuth2
    message = mutt OAuth2 request
    background = "#d02617"
    frame_color = "#fafafa"
    foreground = "#fafafa"
    timeout = 0
    mouse_left_click = open_url, do_action, close_current
    history_ignore = true

Last edited by seth (2025-06-25 12:51:14)

Offline

Board footer

Powered by FluxBB