Skip to content

Commit ed0d8b0

Browse files
author
Stanislav Ochotnický
committed
Inject github API token in headers for gists
This makes it possible to actually use gist pasting (even potentially doing private pastes)
1 parent 7827266 commit ed0d8b0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

webpaste.el

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ This uses `browse-url-generic' to open URLs."
135135

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

323324

325+
(cl-defun webpaste--provider-gist-headers ()
326+
"Provide headers for gist API authentication.
327+
328+
This expects your authinfo to contain authorization for using gist API.
329+
You can generate your token at https://github.com/settings/tokens
330+
Only gist scope is necessary.
331+
332+
Then save the token in your authinfo as:
333+
machine api.github.com/gists login wgetpaste password <token>"
334+
(cl-function (lambda ()
335+
(cons `("Authorization" . ,(concat "token "
336+
(auth-source-pick-first-password
337+
:host "api.github.com/gists"
338+
:login "wgetpaste"))) nil))))
339+
340+
324341

325342

326343
(cl-defun webpaste--get-lang-alist-with-overrides (overrides)
@@ -344,6 +361,7 @@ This is the default failover hook that we use for most providers."
344361
(post-data '())
345362
(post-lang-field-name nil)
346363
(parser 'buffer-string)
364+
(headers-lambda nil)
347365
(lang-overrides '())
348366
(lang-uri-separator nil)
349367
(error-lambda 'webpaste--providers-error-lambda)
@@ -432,6 +450,7 @@ Optional params:
432450
:post-lang-field-name post-lang-field-name
433451
:post-data post-data)
434452
:parser parser
453+
:headers (when headers-lambda (funcall (funcall headers-lambda)))
435454
:success (funcall success-lambda)
436455
:sync sync
437456
:error (funcall error-lambda :text text))))))

0 commit comments

Comments
 (0)