Added some OAuth 2.0 logging

This commit is contained in:
Gregory Schier 2017-11-03 17:25:12 +01:00
parent 68cda7187b
commit 6ee6422e94
2 changed files with 6 additions and 1 deletions

View File

@ -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,

View File

@ -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()}`);
}
});