[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/oauth2 8f5cf79 14/23: * oauth2.el: Only require CL at c
From: |
Stefan Monnier |
Subject: |
[elpa] externals/oauth2 8f5cf79 14/23: * oauth2.el: Only require CL at compile time and avoid flet. |
Date: |
Tue, 1 Dec 2020 16:32:00 -0500 (EST) |
branch: externals/oauth2
commit 8f5cf79a2f8be779798da9a589a3e9634f7b1dbb
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
* oauth2.el: Only require CL at compile time and avoid flet.
(success): Don't defvar.
(oauth--url-advice, oauth--tokens-need-renew): New dynbind variables.
(url-http-handle-authentication): Add advice.
(oauth2-url-retrieve-synchronously): Use the advice instead of flet.
---
oauth2.el | 44 ++++++++++++++++++++++++--------------------
1 file changed, 24 insertions(+), 20 deletions(-)
diff --git a/oauth2.el b/oauth2.el
index 6ad3639..64962bf 100644
--- a/oauth2.el
+++ b/oauth2.el
@@ -1,6 +1,6 @@
;;; oauth2.el --- OAuth 2.0 Authorization Protocol
-;; Copyright (C) 2011-2012 Free Software Foundation, Inc
+;; Copyright (C) 2011-2013 Free Software Foundation, Inc
;; Author: Julien Danjou <julien@danjou.info>
;; Version: 0.9
@@ -35,7 +35,7 @@
;;; Code:
-(require 'cl)
+(eval-when-compile (require 'cl))
(require 'plstore)
(require 'json)
(require 'url-http)
@@ -186,29 +186,33 @@ This allows to store the token in an unique way."
(if (string-match-p "\?" url) "&" "?")
"access_token=" (oauth2-token-access-token token)))
-;; Local variable from `url'
-;; defined here to avoid compile warning
-(defvar success)
+(defvar oauth--url-advice nil)
+(defvar oauth--tokens-need-renew)
+
+;; FIXME: We should change URL so that this can be done without an advice.
+(defadvice url-http-handle-authentication (around oauth-hack activate)
+ (if (not oauth--url-advice)
+ ad-do-it
+ (setq oauth--tokens-need-renew t)
+ ;; This is to make `url' think it's done.
+ (if (boundp 'success) (setq success t)) ;For URL library in Emacs<24.4.
+ (setq ad-return-value t))) ;For URL library in Emacsā„24.4.
;;;###autoload
(defun oauth2-url-retrieve-synchronously (token url &optional request-method
request-data request-extra-headers)
"Retrieve an URL synchronously using TOKENS to access it.
TOKENS can be obtained with `oauth2-auth'."
- (let (tokens-need-renew)
- (flet ((url-http-handle-authentication (proxy)
- (setq tokens-need-renew t)
- ;; This is to make `url' think
- ;; it's done.
- (setq success t)))
- (let ((url-request-method request-method)
- (url-request-data request-data)
- (url-request-extra-headers request-extra-headers)
- (url-buffer))
- (setq url-buffer (url-retrieve-synchronously
- (oauth2-url-append-access-token token url)))
- (if tokens-need-renew
- (oauth2-url-retrieve-synchronously (oauth2-refresh-access token)
url request-method request-data request-extra-headers)
- url-buffer)))))
+ (let* ((oauth--tokens-need-renew nil)
+ (url-buffer
+ (let ((oauth--url-advice t) ;Activate our advice.
+ (url-request-method request-method)
+ (url-request-data request-data)
+ (url-request-extra-headers request-extra-headers))
+ (url-retrieve-synchronously
+ (oauth2-url-append-access-token token url)))))
+ (if oauth--tokens-need-renew
+ (oauth2-url-retrieve-synchronously (oauth2-refresh-access token) url
request-method request-data request-extra-headers)
+ url-buffer)))
(provide 'oauth2)
- [elpa] externals/oauth2 d5e5e70 10/23: oauth2: add redirect-uri parameter, update to 0.6, (continued)
- [elpa] externals/oauth2 d5e5e70 10/23: oauth2: add redirect-uri parameter, update to 0.6, Stefan Monnier, 2020/12/01
- [elpa] externals/oauth2 1d352b3 17/23: Fix some quoting problems in doc strings, Stefan Monnier, 2020/12/01
- [elpa] externals/oauth2 86a4afd 19/23: fix(oauth2): rename forgotten instance of resource-url -> scope, Stefan Monnier, 2020/12/01
- [elpa] externals/oauth2 7619d08 23/23: * .gitignore: New file, Stefan Monnier, 2020/12/01
- [elpa] externals/oauth2 61bcabe 16/23: oauth2: send authentication token via Authorization header, Stefan Monnier, 2020/12/01
- [elpa] externals/oauth2 bf96d9f 11/23: oauth2: store access-reponse, bump versino to 0.7, Stefan Monnier, 2020/12/01
- [elpa] externals/oauth2 bcf36ae 18/23: feat(oauth2): add state parameter support, rename resource-url to scope, Stefan Monnier, 2020/12/01
- [elpa] externals/oauth2 0abcea1 15/23: oauth2.el: Add support for async retrieve., Stefan Monnier, 2020/12/01
- [elpa] externals/oauth2 54da2ff 21/23: * packages/oauth2/oauth2.el: Use lexical-binding, cl-lib, and nadvice, Stefan Monnier, 2020/12/01
- [elpa] externals/oauth2 b383a42 22/23: * packages/oauth2/oauth2.el: update version to 0.15, Stefan Monnier, 2020/12/01
- [elpa] externals/oauth2 8f5cf79 14/23: * oauth2.el: Only require CL at compile time and avoid flet.,
Stefan Monnier <=
- [elpa] externals/oauth2 9108df0 20/23: feat(oauth2): do not include &client_secret if no client_secret set, Stefan Monnier, 2020/12/01