- "Retrieve an URL synchronously using TOKENS to access it.
-TOKENS can be obtained with `oauth2-auth'."
- (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)))
+ "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))))