From 55417ec61c91f6b4d8e16a0c9933fb178d7bb657 Mon Sep 17 00:00:00 2001 From: Xiyue Deng Date: Sun, 28 Jul 2024 03:41:20 -0700 Subject: [PATCH 5/6] Add debug messages and provide a switch variable for enabling This helps debugging whether the authorization and refresh requests were successful and inspecting the responses. * packages/oauth2/oauth2.el: add support for debug messages and a switch variable for enabling. --- oauth2.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/oauth2.el b/oauth2.el index 035971ac85..ce7a835100 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,14 @@ :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")) +(defvar oauth2-debug nil + "Enable debug messages.") + +(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 +88,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 +97,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