Skip to content

Commit

Permalink
Inject github API token in headers for gists
Browse files Browse the repository at this point in the history
This makes it possible to actually use gist pasting (even potentially doing
private pastes)
  • Loading branch information
Stanislav Ochotnický committed Jul 16, 2022
1 parent 7827266 commit a94ea00
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions webpaste.el
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ This uses `browse-url-generic' to open URLs."

("gist.github.com"
:uri "https://api.github.com/gists"
:headers-lambda webpaste--provider-gist-headers
:post-field nil
:post-field-lambda (lambda () (cl-function (lambda (&key text &allow-other-keys)
(let ((filename (if (buffer-file-name)
Expand Down Expand Up @@ -321,6 +322,22 @@ This is the default failover hook that we use for most providers."
(webpaste--return-url (cdr (assq 'link (json-read-from-string data)))))))


(cl-defun webpaste--provider-gist-headers ()
"Provide headers for gist API authentication.
This expects your authinfo to contain authorization for using gist API.
You can generate your token at https://github.com/settings/tokens
Only gist scope is necessary.
Then save the token in your authinfo as:
machine api.github.com/gists login wgetpaste password <token>"
(cl-function (lambda ()
(cons `("Authorization" . ,(concat "token "
(auth-source-pick-first-password
:host "api.github.com/gists"
:login "wgetpaste"))) nil))))




(cl-defun webpaste--get-lang-alist-with-overrides (overrides)
Expand All @@ -344,6 +361,7 @@ This is the default failover hook that we use for most providers."
(post-data '())
(post-lang-field-name nil)
(parser 'buffer-string)
(headers-lambda nil)
(lang-overrides '())
(lang-uri-separator nil)
(error-lambda 'webpaste--providers-error-lambda)
Expand Down Expand Up @@ -390,6 +408,10 @@ Optional params:
`webpaste--providers-error-lambda-no-failover' available if
you need a provider that isn't allowed to failover.
:headers-lambda Function that builds and returns headers that should be sent
to the provider. This can be useful to add authentication
for example.
:post-field-lambda Function that builds and returns the post data that should be
sent to the provider. It should accept named parameters by
the names TEXT, POST-FIELD and POST-DATA. POST-DATA should
Expand Down Expand Up @@ -432,6 +454,7 @@ Optional params:
:post-lang-field-name post-lang-field-name
:post-data post-data)
:parser parser
:headers (when headers-lambda (funcall (funcall headers-lambda)))
:success (funcall success-lambda)
:sync sync
:error (funcall error-lambda :text text))))))
Expand Down

0 comments on commit a94ea00

Please sign in to comment.