emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/mastodon 7a45ec461b 07/76: add auth-source customize, shor


From: ELPA Syncer
Subject: [nongnu] elpa/mastodon 7a45ec461b 07/76: add auth-source customize, shorten some lines
Date: Sun, 30 Mar 2025 13:01:41 -0400 (EDT)

branch: elpa/mastodon
commit 7a45ec461b496a4f740bbca8f1ed486db09e206e
Author: marty hiatt <martianhiatus@disroot.org>
Commit: marty hiatt <martianhiatus@disroot.org>

    add auth-source customize, shorten some lines
---
 lisp/mastodon-auth.el   | 47 ++++++++++++++++++++++++++++-------------------
 lisp/mastodon-client.el | 16 +++++++++++-----
 2 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el
index 6e90b5348f..6e932a9160 100644
--- a/lisp/mastodon-auth.el
+++ b/lisp/mastodon-auth.el
@@ -55,6 +55,12 @@
   :prefix "mastodon-auth-"
   :group 'mastodon)
 
+(defcustom mastodon-auth-use-auth-source t
+  "Whether to use auth sources for user credentials.
+If t, save and read user access token in the user's auth source
+file (see `auth-sources'). If nil, use `mastodon-client--token-file'
+instead.")
+
 (defvar mastodon-auth-source-file nil
   "This variable is obsolete.
 This variable currently serves no purpose and will be removed in
@@ -171,25 +177,28 @@ When ASK is absent return nil."
 (defun mastodon-auth--access-token ()
   "Return the access token to use with `mastodon-instance-url'.
 Generate/save token if none known yet."
-  (cond (mastodon-auth--token-alist
-         ;; user variables are known and initialised.
-         (alist-get mastodon-instance-url mastodon-auth--token-alist nil nil 
#'string=))
-        ((plist-get (mastodon-client--active-user) :access_token)
-         ;; user variables need to be read from plstore.
-         (push (cons mastodon-instance-url
-                     (plist-get (mastodon-client--active-user) :access_token))
-               mastodon-auth--token-alist)
-         (alist-get mastodon-instance-url mastodon-auth--token-alist nil nil 
#'string=))
-        ((null mastodon-active-user)
-         ;; user not aware of 2FA-related changes and has not set
-         ;; `mastodon-active-user'. Make user aware and error out.
-         (mastodon-auth--show-notice mastodon-auth--user-unaware
-                                     "*mastodon-notice*")
-         (error "Variables not set properly"))
-        (t
-         ;; user access-token needs to fetched from the server and
-         ;; stored and variables initialised.
-         (mastodon-auth--handle-token-response (mastodon-auth--get-token)))))
+  (cond
+   (mastodon-auth--token-alist
+    ;; user variables are known and initialised.
+    (alist-get mastodon-instance-url
+               mastodon-auth--token-alist nil nil #'string=))
+   ((plist-get (mastodon-client--active-user) :access_token)
+    ;; user variables need to be read from plstore.
+    (push (cons mastodon-instance-url
+                (plist-get (mastodon-client--active-user) :access_token))
+          mastodon-auth--token-alist)
+    (alist-get mastodon-instance-url
+               mastodon-auth--token-alist nil nil #'string=))
+   ((null mastodon-active-user)
+    ;; user not aware of 2FA-related changes and has not set
+    ;; `mastodon-active-user'. Make user aware and error out.
+    (mastodon-auth--show-notice mastodon-auth--user-unaware
+                                "*mastodon-notice*")
+    (error "Variables not set properly"))
+   (t
+    ;; user access-token needs to fetched from the server and
+    ;; stored and variables initialised.
+    (mastodon-auth--handle-token-response (mastodon-auth--get-token)))))
 
 (defun mastodon-auth--handle-token-response (response)
   "Add token RESPONSE to `mastodon-auth--token-alist'.
diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el
index 93c50bd3cd..63ef8c3c31 100644
--- a/lisp/mastodon-client.el
+++ b/lisp/mastodon-client.el
@@ -39,7 +39,8 @@
 (autoload 'mastodon-http--api "mastodon-http")
 (autoload 'mastodon-http--post "mastodon-http")
 
-(defcustom mastodon-client--token-file (concat user-emacs-directory 
"mastodon.plstore")
+(defcustom mastodon-client--token-file
+  (concat user-emacs-directory "mastodon.plstore")
   "File path where Mastodon access tokens are stored."
   :group 'mastodon
   :type 'file)
@@ -85,7 +86,8 @@ If you change the value of this variable, you need to also 
delete
     (let ((json-object-type 'plist)
           (json-key-type 'keyword)
           (json-array-type 'vector)
-          (json-string (buffer-substring-no-properties (point) (point-max))))
+          (json-string
+           (buffer-substring-no-properties (point) (point-max))))
       (json-read-from-string json-string))))
 
 (defun mastodon-client--token-file ()
@@ -103,7 +105,8 @@ Make `mastodon-client--fetch' call to determine client 
values."
        ;; seems to ensure this cannot happen so let's do that ourselves:
        (print-length nil)
        (print-level nil))
-    (plstore-put plstore (concat "mastodon-" mastodon-instance-url) client nil)
+    (plstore-put plstore
+                 (concat "mastodon-" mastodon-instance-url) client nil)
     (plstore-save plstore)
     (plstore-close plstore)
     client))
@@ -117,7 +120,9 @@ Make `mastodon-client--fetch' call to determine client 
values."
 (defun mastodon-client--read ()
   "Retrieve client_id and client_secret from `mastodon-client--token-file'."
   (let* ((plstore (plstore-open (mastodon-client--token-file)))
-         (mastodon (plstore-get plstore (concat "mastodon-" 
mastodon-instance-url))))
+         (mastodon
+          (plstore-get plstore
+                       (concat "mastodon-" mastodon-instance-url))))
     (mastodon-client--remove-key-from-plstore mastodon)))
 
 (defun mastodon-client--general-read (key)
@@ -213,7 +218,8 @@ Details is a plist."
 Read plist from `mastodon-client--token-file' if variable is nil.
 Fetch and store plist if `mastodon-client--read' returns nil."
   (let ((client-details
-         (cdr (assoc mastodon-instance-url 
mastodon-client--client-details-alist))))
+         (cdr (assoc mastodon-instance-url
+                     mastodon-client--client-details-alist))))
     (unless client-details
       (setq client-details
             (or (mastodon-client--read)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]