From 6cf0ab190d24b6fc2a7335d02a8aef29ab24c622 Mon Sep 17 00:00:00 2001 From: Xiyue Deng Date: Sun, 28 Jul 2024 03:41:20 -0700 Subject: [PATCH 5/5] Add debug messages and provide a switch for enabling This helps debugging whether the authorization and refresh requests were successful and inspecting the responses. * packages/oauth2/oauth2.el: add debug message and option for enabling. --- oauth2.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/oauth2.el b/oauth2.el index ea012d4d38..06a880532e 100644 --- a/oauth2.el +++ b/oauth2.el @@ -40,6 +40,7 @@ (require 'plstore) (require 'json) (require 'url-http) +(require 'pp) (defvar url-http-data) (defvar url-http-method) @@ -53,6 +54,15 @@ :link '(url-link :tag "Savannah" "https://git.savannah.gnu.org/cgit/emacs/elpa.git/tree/?h=externals/oauth2") :link '(url-link :tag "ELPA" "https://elpa.gnu.org/packages/oauth2.html")) +(defcustom oauth2-debug nil + "Enable debug messages." + :type 'boolean) + +(defun oauth2--do-debug (&rest msg) + "Output debug messages when `oauth2-debug' is enabled." + (if oauth2-debug + (apply #'message msg))) + (defun oauth2-request-authorization (auth-url client-id &optional scope state redirect-uri) "Request OAuth authorization at AUTH-URL by launching `browse-url'. CLIENT-ID is the client id provided by the provider. @@ -79,6 +89,8 @@ It returns the code provided by the service." (defun oauth2-make-access-request (url data) "Make an access request to URL using DATA in POST." + (oauth2--do-debug "oauth2-make-access-request: url: %s" url) + (oauth2--do-debug "oauth2-make-access-request: data: %s" data) (let ((url-request-method "POST") (url-request-data data) (url-request-extra-headers @@ -86,6 +98,8 @@ It returns the code provided by the service." (with-current-buffer (url-retrieve-synchronously url) (let ((data (oauth2-request-access-parse))) (kill-buffer (current-buffer)) + (oauth2--do-debug "oauth2-make-access-request: response: %s" + (pp-to-string data)) data)))) (cl-defstruct oauth2-token -- 2.39.2