added ability to pass in access token

fixed using deprecated authorization header
main
a. fox 2 years ago
parent a839ca60b0
commit 90532da65a

@ -3,6 +3,7 @@
(in-package :seanut) (in-package :seanut)
(defun get-access-token (domain options) (defun get-access-token (domain options)
(let ((token
(if (getf options :quick-connect-p) (if (getf options :quick-connect-p)
;; go through the whole quick connect rigamarole ;; go through the whole quick connect rigamarole
@ -11,13 +12,16 @@
;; authenticates the user via username and password ;; authenticates the user via username and password
(gethash "AccessToken" (gethash "AccessToken"
(json-request (format-url domain "Users/AuthenticateByName") (json-request (format-url domain "Users/AuthenticateByName")
(generate-authorization "") (generate-authorization)
:method :post :method :post
:content `(("Username" . ,(getf options :username)) :content `(("Username" . ,(getf options :username))
("Pw" . ,(getf options :password))))))) ("Pw" . ,(getf options :password))))))))
(format t "Your access token: ~A~&Next time you use seanut, pass this with -t to skip having to authorize~&"
token)
token))
(defun quick-connect-dance (domain) (defun quick-connect-dance (domain)
(let* ((auth (generate-authorization "")) (let* ((auth (generate-authorization))
(qc-session (handler-case (qc-session (handler-case
(json-request (format-url domain "QuickConnect/Initiate") auth) (json-request (format-url domain "QuickConnect/Initiate") auth)
(dex:http-request-unauthorized () (dex:http-request-unauthorized ()

@ -18,6 +18,12 @@
:short #\q :short #\q
:long "quick-connect" :long "quick-connect"
:description "alternative login method to providing username/password - times out after ~1min") :description "alternative login method to providing username/password - times out after ~1min")
(:name :token
:short #\t
:long "token"
:meta-var "TOKEN"
:arg-parser #'identity
:description "access token - if you do not have one please authenticate first")
(:name :output (:name :output
:short #\o :short #\o
:long "output" :long "output"

@ -65,7 +65,6 @@
(download-item-or-children item)))) (download-item-or-children item))))
(defun main () (defun main ()
"binary entry point" "binary entry point"
(handle-user-abort (handle-user-abort
@ -82,8 +81,9 @@
(unless (or (and (getf opts :username) (unless (or (and (getf opts :username)
(getf opts :password)) (getf opts :password))
(getf opts :quick-connect-p)) (getf opts :quick-connect-p)
(quit-with-message 1 "please provide username & password, or use quick connect")) (getf opts :token))
(quit-with-message 1 "please provide an access token, username & password, or use quick connect"))
(unless (getf opts :media-type) (unless (getf opts :media-type)
(quit-with-message 1 "Please specify media type to download.~%~A ~{~A~^, ~}" (quit-with-message 1 "Please specify media type to download.~%~A ~{~A~^, ~}"
@ -94,7 +94,8 @@
(quit-with-message 1 "domain and/or media name not provided")) (quit-with-message 1 "domain and/or media name not provided"))
(destructuring-bind (domain search-term) args (destructuring-bind (domain search-term) args
(let* ((authorization (generate-authorization (get-access-token domain opts))) (let* ((authorization (or (getf opts :token)
(generate-authorization (get-access-token domain opts))))
(results (run-search-query domain authorization (results (run-search-query domain authorization
(getf opts :media-type) (getf opts :media-type)
(url-encode search-term)))) (url-encode search-term))))

@ -5,11 +5,11 @@
(eval-when (:compile-toplevel) (eval-when (:compile-toplevel)
(declaim (inline json-request format-url generate-authorization download-media))) (declaim (inline json-request format-url generate-authorization download-media)))
(defun generate-authorization (token) (defun generate-authorization (&optional token)
"generates a properly formatted authorization header" "generates a properly formatted authorization header"
(format nil *authorization-format* (format nil *authorization-format*
(seanut-version) (uiop:hostname) (md5-string (uiop:hostname)) (seanut-version) (uiop:hostname) (md5-string (uiop:hostname))
(seanut-version) token)) (seanut-version) (or token "")))
(defun format-url (domain slug &rest args) (defun format-url (domain slug &rest args)
"formats DOMAIN into a url, ensures we include the url scheme "formats DOMAIN into a url, ensures we include the url scheme
@ -27,7 +27,7 @@ if EXTRA-HEADERS is non-nil, includes them in the headers alongside the X-Emby-A
if CONTENT is non-nil, passes that along to the request" if CONTENT is non-nil, passes that along to the request"
(parse (dex:request url :method method (parse (dex:request url :method method
:content content :content content
:headers `(("X-Emby-Authorization" . ,auth) :headers `(("Authorization" . ,auth)
,@extra-headers)))) ,@extra-headers))))
(defun run-search-query (domain auth type name) (defun run-search-query (domain auth type name)

Loading…
Cancel
Save