From 525235938369dd035c3e2bd073186266c7815af9 Mon Sep 17 00:00:00 2001 From: Johnson Denen Date: Wed, 12 Apr 2017 12:59:11 -0400 Subject: Add mastodon--get-access-token test Abstract Email and Password prompts to `mastodon-auth--user-and-passwd' function --- lisp/mastodon-auth.el | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'lisp/mastodon-auth.el') diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 9ded694..1f4adaf 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -113,18 +113,27 @@ STATUS is passed by `url-retrieve'." (mastodon--http-response-triage status 'mastodon-auth--get-token-success)) +(defun mastodon-auth--user-and-passwd () + "Prompt for user email and password." + (let ((email (read-string "Email: ")) + (passwd (read-string "Password: "))) + (cons email passwd))) + (defun mastodon--get-access-token () "Retrieve access token from instance. Authenticates with email address and password. Neither are not stored." - (mastodon--http-post (concat mastodon-instance-url "/oauth/token") - 'mastodon--get-access-token-triage - `(("client_id" . ,(plist-get (mastodon--client-app) :client_id)) - ("client_secret" . ,(plist-get (mastodon--client-app) :client_secret)) - ("grant_type" . "password") - ("username" . ,(read-string "Email: ")) - ("password" . ,(read-passwd "Password: ")) - ("scope" . "read write follow")))) + (let* ((creds (mastodon-auth--user-and-passwd)) + (email (car creds)) + (passwd (cdr creds))) + (mastodon--http-post (concat mastodon-instance-url "/oauth/token") + 'mastodon--get-access-token-triage + `(("client_id" . ,(plist-get (mastodon--client-app) :client_id)) + ("client_secret" . ,(plist-get (mastodon--client-app) :client_secret)) + ("grant_type" . "password") + ("username" . ,email) + ("password" . ,passwd) + ("scope" . "read write follow"))))) (defun mastodon--access-token () "Return `mastodon--api-token-string'. -- cgit v1.2.3