diff --git a/plugins/auth-oauth2/src/getAccessToken.ts b/plugins/auth-oauth2/src/getAccessToken.ts index 82f98e4f..def2c6f1 100644 --- a/plugins/auth-oauth2/src/getAccessToken.ts +++ b/plugins/auth-oauth2/src/getAccessToken.ts @@ -24,7 +24,7 @@ export async function getAccessToken( params: HttpUrlParameter[]; }, ): Promise { - console.log('Getting access token', accessTokenUrl); + console.log('[oauth2] Getting access token', accessTokenUrl); const httpRequest: Partial = { method: 'POST', url: accessTokenUrl, diff --git a/plugins/auth-oauth2/src/getOrRefreshAccessToken.ts b/plugins/auth-oauth2/src/getOrRefreshAccessToken.ts index 43df1402..94abfc82 100644 --- a/plugins/auth-oauth2/src/getOrRefreshAccessToken.ts +++ b/plugins/auth-oauth2/src/getOrRefreshAccessToken.ts @@ -68,7 +68,7 @@ export async function getOrRefreshAccessToken(ctx: Context, contextId: string, { if (resp.status === 401) { // Bad refresh token, so we'll force it to fetch a fresh access token by deleting // and returning null; - console.log('Unauthorized refresh_token request'); + console.log('[oauth2] Unauthorized refresh_token request'); await deleteToken(ctx, contextId); return null; } diff --git a/plugins/auth-oauth2/src/grants/authorizationCode.ts b/plugins/auth-oauth2/src/grants/authorizationCode.ts index cd729764..b8da7618 100644 --- a/plugins/auth-oauth2/src/grants/authorizationCode.ts +++ b/plugins/auth-oauth2/src/grants/authorizationCode.ts @@ -70,7 +70,8 @@ export async function getAuthorizationCode( return new Promise(async (resolve, reject) => { const authorizationUrlStr = authorizationUrl.toString(); - console.log('Authorizing', authorizationUrlStr); + const logsEnabled = (await ctx.store.get('enable_logs')) ?? false; + console.log('[oauth2] Authorizing', authorizationUrlStr); let foundCode = false; @@ -85,11 +86,15 @@ export async function getAuthorizationCode( }, async onNavigate({ url: urlStr }) { const url = new URL(urlStr); + if (logsEnabled) console.log('[oauth2] Navigated to', urlStr); + if (url.searchParams.has('error')) { return reject(new Error(`Failed to authorize: ${url.searchParams.get('error')}`)); } + const code = url.searchParams.get('code'); if (!code) { + console.log('[oauth2] Code not found'); return; // Could be one of many redirects in a chain, so skip it } @@ -97,6 +102,7 @@ export async function getAuthorizationCode( foundCode = true; close(); + console.log('[oauth2] Code found'); const response = await getAccessToken(ctx, { grantType: 'authorization_code', accessTokenUrl, diff --git a/plugins/auth-oauth2/src/index.ts b/plugins/auth-oauth2/src/index.ts index f14238a6..9597a6d5 100644 --- a/plugins/auth-oauth2/src/index.ts +++ b/plugins/auth-oauth2/src/index.ts @@ -53,6 +53,7 @@ const authorizationUrls = [ 'https://www.dropbox.com/oauth2/authorize', 'https://www.linkedin.com/oauth/v2/authorization', 'https://MY_SHOP.myshopify.com/admin/oauth/access_token', + 'https://appcenter.intuit.com/app/connect/oauth2/authorize', ]; const accessTokenUrls = [ @@ -69,6 +70,7 @@ const accessTokenUrls = [ 'https://www.googleapis.com/oauth2/v4/token', 'https://www.linkedin.com/oauth/v2/accessToken', 'https://MY_SHOP.myshopify.com/admin/oauth/authorize', + 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer', ]; export const plugin: PluginDefinition = { @@ -109,6 +111,17 @@ export const plugin: PluginDefinition = { await resetDataDirKey(ctx, contextId); }, }, + { + label: 'Toggle Debug Logs', + async onSelect(ctx) { + const enableLogs = await ctx.store.get('enable_logs'); + await ctx.store.set('enable_logs', !enableLogs); + await ctx.toast.show({ + message: `Debug logs ${enableLogs ? 'enabled' : 'disabled'}`, + color: 'info', + }); + }, + }, ], args: [ { diff --git a/plugins/auth-oauth2/src/store.ts b/plugins/auth-oauth2/src/store.ts index ba193741..f0d06837 100644 --- a/plugins/auth-oauth2/src/store.ts +++ b/plugins/auth-oauth2/src/store.ts @@ -37,12 +37,12 @@ export async function getDataDirKey(ctx: Context, contextId: string) { return `${contextId}::${key}`; } -function tokenStoreKey(context_id: string) { - return ['token', context_id].join('::'); +function tokenStoreKey(contextId: string) { + return ['token', contextId].join('::'); } -function dataDirStoreKey(context_id: string) { - return ['data_dir', context_id].join('::'); +function dataDirStoreKey(contextId: string) { + return ['data_dir', contextId].join('::'); } export interface AccessToken {