The token is typically encrypted which offers better security than
storing client_secret in plaintext.
---
 contrib/mutt_oauth2.py        | 13 ++++++++++++-
 contrib/mutt_oauth2.py.README | 22 ++++++++++++----------
 2 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/contrib/mutt_oauth2.py b/contrib/mutt_oauth2.py
index d136a2f9..6286dbce 100644
--- a/contrib/mutt_oauth2.py
+++ b/contrib/mutt_oauth2.py
@@ -1,7 +1,8 @@
 #!/usr/bin/env python3
 #
 # Mutt OAuth2 token management script, version 2026-11-07
-# Modified by Aiden Woodruff to mention Google's removal of authcode.
+# Modified by Aiden Woodruff to mention Google's removal of authcode and store
+# client_id and client_secret in the encrypted token.
 #
 # Mutt OAuth2 token management script, version 2020-08-07
 # Written against python 3.7.3, not tried with earlier python versions.
@@ -142,6 +143,10 @@ if not token:
     if token['authflow'] not in authflows:
         sys.exit(f'ERROR: Unknown authflow "{token['authflow']}".')
     token['email'] = input('Account e-mail address: ')
+    if not registration['client_id']:
+        token['client_id'] = input('Client ID: ')
+    if not registration['client_secret']:
+        token['client_secret'] = input('Client secret: ')
     token['access_token'] = ''
     token['access_token_expiration'] = ''
     token['refresh_token'] = ''
@@ -160,6 +165,12 @@ if args.authflow == 'authcode' and token['registration'] 
== 'google':
     sys.exit('Google has removed the standard authcode method for security'
              'reasons. Use localauthcode.')
 
+if 'client_id' in token:
+    registration['client_id'] = token['client_id']
+
+if 'client_secret' in token:
+    registration['client_secret'] = token['client_secret']
+
 baseparams = {'client_id': registration['client_id']}
 # Microsoft uses 'tenant' but Google does not
 if 'tenant' in registration:
diff --git a/contrib/mutt_oauth2.py.README b/contrib/mutt_oauth2.py.README
index 61f85884..abb67b4b 100644
--- a/contrib/mutt_oauth2.py.README
+++ b/contrib/mutt_oauth2.py.README
@@ -152,12 +152,12 @@ might want an official app registration from a developer 
(the creation of
 which and blessing by the cloud provider might require payment and/or arduous
 review), or might perhaps be willing to roll their own "in-house" registration.
 
-What you ultimately need is the "client_id" (and "client_secret" if
-one was set) for this registration. Those values must be edited into
-the mutt_oauth2.py script.  If your work or school environment has a
-knowledge base that provides the client_id, then someone already took
-care of the app registration, and you can skip the step of creating
-your own registration.
+What you ultimately need is the "client_id" (and "client_secret" if one was
+set) for this registration. Those values must be edited into the mutt_oauth2.py
+script or interactively supplied with "--authorize".  If your work or school
+environment has a knowledge base that provides the client_id, then someone
+already took care of the app registration, and you can skip the step of
+creating your own registration.
 
 
 -- How to create a Google registration --
@@ -177,8 +177,9 @@ matter and could be "mutt registration project".
  - At top, choose Create Credentials / OAuth2 client iD
    - Application type is "Desktop app"
 
-Edit the client_id (and client_secret if there is one) into the
-mutt_oauth2.py script.
+Edit the client_id (and client_secret if there is one) into the mutt_oauth2.py
+script. These values can also be interactively entered with "--authorize" which
+saves them to the encrypted token file.
 
 
 -- How to create a Microsoft registration --
@@ -212,8 +213,9 @@ portal.azure.com for their work/school account can 
temporarily use an
 incognito browser window to create a free outlook.com account and use that
 to create the app registration.
 
-Edit the client_id (and client_secret if there is one) into the
-mutt_oauth2.py script.
+Edit the client_id (and client_secret if there is one) into the mutt_oauth2.py
+script. These values can also be interactively entered with "--authorize" which
+saves them to the encrypted token file.
 
 
 Running the script manually to authorize tokens
-- 
2.56.0

Reply via email to