Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I do basic authentication in Emacs Lisp?

I'm trying to authenticate to an API using basic authentication. It seems like the code below should work, but it's breaking when I run it in the scratch buffer after running it with C-x C-e (says: debugger entered--Lisp error: (wrong-type-argument characterp)).

My code is below. If anyone knows what I need to change to make this work, please let me know! There are basically no complete Emacs Lisp basic authentication examples I could find online, so this would be a huge help.

(setq ztoken "areallyfaketokenrandomtokenwithfakechars")
(setq zsite "https://fake.zendesk.com/api/v2/users/1100000011/related.json")

(let ((url-request-method "GET")
  (url-request-extra-headers '(("Content Type" . "application/json")
   ("Authorization" . ,(concat "Basic "
(base64-encode-string
   (concat "[email protected]/token" ":" ztoken)))))))    
(condition-case nil
    (url-retrieve-synchronously
     (format zsite))))
like image 810
jumar Avatar asked Jul 24 '26 11:07

jumar


1 Answers

As lawlist mentions, your code uses a single-quote instead of a back-tick. Below is an alternative approach, that does not use the back-tick/comma. For more information on backquotes: https://www.gnu.org/software/emacs/manual/html_node/elisp/Backquote.html#Backquote

(let* ((url-request-method "GET")
       (base64 (concat "Basic "
               (base64-encode-string
            (concat "[email protected]/token" ":" ztoken))))
       (url-request-extra-headers (list (cons "Content Type" "application/json")
                    (cons "Authorization" base64))))    
  (condition-case nil
      (url-retrieve-synchronously
       (format zsite))))
like image 185
V. Semeria Avatar answered Jul 26 '26 03:07

V. Semeria



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!