         (url-request-extra-headers
          '(("Content-Type" . "application/x-www-form-urlencoded"))))
     (with-current-buffer (url-retrieve-synchronously url)
-      (prog1 (oauth2-request-access-parse)
-        (kill-buffer)))))
+      (let ((data (oauth2-request-access-parse)))
+        (kill-buffer (current-buffer))
+        data))))
 
 (defstruct oauth2-token
   plstore

          (if (string-match-p "\?" url) "&" "?")
          "access_token=" (oauth2-token-access-token token)))

;; Local variable from `url'
;; defined here to avoid compile warning
(defvar success)

;;;###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)))))

(provide 'oauth2)


                         :refresh-token
                         ,(oauth2-token-refresh-token token)
                         :access-response
                         ,(oauth2-token-access-response token)
                         ))
      (plstore-save plstore)))
  token)

