From 6ee6422e947bbe7a2f75577cafe6780d71139a4d Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Fri, 3 Nov 2017 17:25:12 +0100 Subject: [PATCH] Added some OAuth 2.0 logging --- app/network/o-auth-2/grant-authorization-code.js | 4 +++- app/network/o-auth-2/misc.js | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/network/o-auth-2/grant-authorization-code.js b/app/network/o-auth-2/grant-authorization-code.js index 9a0243a02..2a0d08c35 100644 --- a/app/network/o-auth-2/grant-authorization-code.js +++ b/app/network/o-auth-2/grant-authorization-code.js @@ -57,10 +57,12 @@ async function _authorize (url, clientId, redirectUri = '', scope = '', state = // Add query params to URL const qs = querystring.buildFromParams(params); const finalUrl = querystring.joinUrl(url, qs); - const regex = new RegExp(`${escapeRegex(redirectUri)}.*(code=|error=)`); + const regex = new RegExp(`${escapeRegex(redirectUri)}.*(code=|error=)`, 'i'); const redirectedTo = await authorizeUserInWindow(finalUrl, regex); + console.log('[oauth2] Detected redirect ' + redirectedTo); + const {query} = urlParse(redirectedTo); return responseToObject(query, [ c.P_CODE, diff --git a/app/network/o-auth-2/misc.js b/app/network/o-auth-2/misc.js index 05ac8da1e..4cab44584 100644 --- a/app/network/o-auth-2/misc.js +++ b/app/network/o-auth-2/misc.js @@ -53,8 +53,11 @@ export function authorizeUserInWindow (url, urlRegex = /.*/) { child.webContents.on('did-navigate', () => { const url = child.webContents.getURL(); if (url.match(urlRegex)) { + console.log(`[oauth2] Matched redirect to "${url}" with ${urlRegex.toString()}`); finalUrl = url; child.close(); + } else { + console.log(`[oauth2] Ignoring redirect to "${url}" with match ${urlRegex.toString()}`); } });