aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-client.el
diff options
context:
space:
mode:
authorAbhiseck Paira <abhiseckpaira@disroot.org>2022-01-17 20:03:01 +0530
committerAbhiseck Paira <abhiseckpaira@disroot.org>2022-01-17 20:03:01 +0530
commitebb4bfcee21020cec5cae08955cf2a8c57d3532c (patch)
tree4ea92ea03070c7a38539c5028e050eede46ffeba /lisp/mastodon-client.el
parenta80bd14c4c22bf5aeda7b37e6f0631a9f4912384 (diff)
store access token in plstore of the current user
Store access token in the plstore of the current user. To do that introduce the function `mastodon-client-store-access-token' of one argument TOKEN. Also define a helper function `mastodon-client--make-user-details-plist' which creates a plist with current users details and returns it.
Diffstat (limited to 'lisp/mastodon-client.el')
-rw-r--r--lisp/mastodon-client.el22
1 files changed, 22 insertions, 0 deletions
diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el
index f7d06a5..1c3b2e1 100644
--- a/lisp/mastodon-client.el
+++ b/lisp/mastodon-client.el
@@ -116,6 +116,28 @@ Return plist without the KEY."
(plstore-item (plstore-get plstore key)))
(mastodon-client--remove-key-from-plstore plstore-item)))
+(defun mastodon-client--make-user-details-plist ()
+ "Make a plist with current user details. Return it."
+ `(:username ,(mastodon-client-form-user-from-vars)
+ :instance ,mastodon-instance-url
+ :client_id ,(plist-get (mastodon-client) :client_id)
+ :client_secret ,(plist-get (mastodon-client) :client_secret)))
+
+(defun mastodon-client-store-access-token (token)
+ "Save TOKEN as :access_token in plstore of the current user.
+Return the plist after the operation."
+ (let* ((user-details (mastodon-client--make-user-details-plist))
+ (plstore (plstore-open (mastodon-client--token-file)))
+ (username (plist-get user-details :username))
+ (plstore-value (setq user-details
+ (plist-put user-details :access_token token)))
+ (print-length nil)
+ (print-level nil))
+ (plstore-put plstore (concat "user-" username) plstore-value nil)
+ (plstore-save plstore)
+ (plstore-close plstore)
+ plstore-value))
+
(defun mastodon-client-form-user-from-vars ()
"Create a username from user variable. Return that username.