[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)
- [nongnu] elpa/mastodon updated (fd59828c89 -> 163ba2b0b8), ELPA Syncer, 2025/03/30
- [nongnu] elpa/mastodon e1885da9c1 02/76: move mastodon-notifications-grouped-types to file mastodon.el., ELPA Syncer, 2025/03/30
- [nongnu] elpa/mastodon ef89f5849a 04/76: store user's access-token encrypted in the plstore. #310., ELPA Syncer, 2025/03/30
- [nongnu] elpa/mastodon 3b17af2c43 05/76: defcustom default t for encrypt user access token. #310, ELPA Syncer, 2025/03/30
- [nongnu] elpa/mastodon 438d3f701b 03/76: add mastodon-tl-follow-user-by-handle, mod tl--userhandle-from-url for it. FIX #665., ELPA Syncer, 2025/03/30
- [nongnu] elpa/mastodon 4c72994a48 06/76: add mastodon-forget-all-logins, ELPA Syncer, 2025/03/30
- [nongnu] elpa/mastodon 7a45ec461b 07/76: add auth-source customize, shorten some lines,
ELPA Syncer <=
- [nongnu] elpa/mastodon 0fe10fbedf 08/76: add optional auth-source support., ELPA Syncer, 2025/03/30
- [nongnu] elpa/mastodon 642f39becf 25/76: clear client/auth variables in forget-logins., ELPA Syncer, 2025/03/30
- [nongnu] elpa/mastodon f764ffbb12 01/76: readme, sachac link, ELPA Syncer, 2025/03/30
- [nongnu] elpa/mastodon 7eed335c50 09/76: media.el: update media item help-echo. (did we lose copy image URL?), ELPA Syncer, 2025/03/30
- [nongnu] elpa/mastodon 48acaae37d 11/76: auth/client fixes: #668., ELPA Syncer, 2025/03/30
- [nongnu] elpa/mastodon eff960c0b6 12/76: auth/client flychecks, ELPA Syncer, 2025/03/30
- [nongnu] elpa/mastodon 600f2574f9 15/76: move auth-source check up the cond, ELPA Syncer, 2025/03/30
- [nongnu] elpa/mastodon fdc45a69f9 17/76: index update, ELPA Syncer, 2025/03/30
- [nongnu] elpa/mastodon ca7c3a814d 21/76: mastodon.el defvar token file, ELPA Syncer, 2025/03/30
- [nongnu] elpa/mastodon 97a317da50 26/76: auth: amend auth source/plstore check error message #671., ELPA Syncer, 2025/03/30