- "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
- (url-generic-parse-url
- (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)))))
+ "Retrieve an URL synchronously using TOKEN to access it.
+TOKEN can be obtained with `oauth2-auth'."
+ (let* ((oauth--token-data (cons token url)))
+ (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)))))
+
+;;;###autoload
+(defun oauth2-url-retrieve (token url callback &optional
+ cbargs
+ request-method request-data request-extra-headers)
+ "Retrieve an URL asynchronously using TOKEN to access it.
+TOKEN can be obtained with `oauth2-auth'. CALLBACK gets called with CBARGS
+when finished. See `url-retrieve'."
+ ;; TODO add support for SILENT and INHIBIT-COOKIES. How to handle this in `url-http-handle-authentication'.
+ (let* ((oauth--token-data (cons token url)))
+ (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
+ (oauth2-url-append-access-token token url)
+ callback cbargs))))