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)
(defun get-access-token (domain options)
(let ((token
(if (getf options :quick-connect-p)
;; go through the whole quick connect rigamarole
@ -11,13 +12,16 @@
;; authenticates the user via username and password
(gethash "AccessToken"
(json-request (format-url domain "Users/AuthenticateByName")
(generate-authorization "")
(generate-authorization)
:method :post
: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)
(let* ((auth (generate-authorization ""))
(let* ((auth (generate-authorization))
(qc-session (handler-case
(json-request (format-url domain "QuickConnect/Initiate") auth)
(dex:http-request-unauthorized ()

@ -18,6 +18,12 @@
:short #\q
:long "quick-connect"
: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
:short #\o
:long "output"

@ -65,7 +65,6 @@
(download-item-or-children item))))
(defun main ()
"binary entry point"
(handle-user-abort
@ -82,8 +81,9 @@
(unless (or (and (getf opts :username)
(getf opts :password))
(getf opts :quick-connect-p))
(quit-with-message 1 "please provide username & password, or use quick connect"))
(getf opts :quick-connect-p)
(getf opts :token))
(quit-with-message 1 "please provide an access token, username & password, or use quick connect"))
(unless (getf opts :media-type)
(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"))
(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
(getf opts :media-type)
(url-encode search-term))))

@ -5,11 +5,11 @@
(eval-when (:compile-toplevel)
(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"
(format nil *authorization-format*
(seanut-version) (uiop:hostname) (md5-string (uiop:hostname))
(seanut-version) token))
(seanut-version) (or token "")))
(defun format-url (domain slug &rest args)
"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"
(parse (dex:request url :method method
:content content
:headers `(("X-Emby-Authorization" . ,auth)
:headers `(("Authorization" . ,auth)
,@extra-headers))))
(defun run-search-query (domain auth type name)

Loading…
Cancel
Save