From 230665ba8b8242c39bce475a6f1340ca80a8feeb Mon Sep 17 00:00:00 2001 From: Jasdeep Singh Date: Fri, 30 Jun 2023 23:18:20 +0530 Subject: [PATCH] fix: Connector config opt replaceCallbackURIDomain (#79) * fix: Connector config opt replaceCallbackURIDomain * chore: Debug * chore: Debug * Update index.ts --------- Co-authored-by: Ankur Banerjee --- src/constant.ts | 3 ++- src/index.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/constant.ts b/src/constant.ts index 7879ed8..d075ab6 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -42,8 +42,9 @@ export const defaultMetadata: ConnectorMetadata = { }, { key: 'replaceCallbackURIDomain', - type: ConnectorConfigFormItemType.Text, + type: ConnectorConfigFormItemType.Switch, required: false, + defaultValue: false, label: 'Replace Callback URI with Bot Origin?', placeholder: 'false', }, diff --git a/src/index.ts b/src/index.ts index 41b94a6..4ebaf07 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,7 +37,7 @@ const getAuthorizationUri = // Reconstruct the return_to url // eslint-disable-next-line let returnTo = new URL(redirectUri); - + if (config.replaceCallbackURIDomain) { // eslint-disable-next-line returnTo = new URL(returnTo.pathname, config.origin); @@ -57,7 +57,9 @@ const getAuthorizationUri = }; const authorizationCallbackHandler = async (parameterObject: unknown) => { + console.log('authorizationCallbackHandler-parameterObject:', parameterObject); const result = authResponseGuard.safeParse(parameterObject); + console.log('authorizationCallbackHandler-result:', result); if (!result.success) { throw new ConnectorError(ConnectorErrorCodes.General, JSON.stringify(parameterObject)); @@ -71,6 +73,7 @@ const performTelegramIntegrityCheck = ( botToken: string ): boolean => { const fields: string[] = []; + console.log('telegramResponse:', telegramResponse); for (const key of Object.keys(telegramResponse)) { if (key === 'hash') { continue; @@ -80,17 +83,21 @@ const performTelegramIntegrityCheck = ( fields.push(field); } const data = fields.sort().join('\n'); + console.log('telegramResponse-data:', data); const botSecretKey = createHash('sha256').update(Buffer.from(botToken)).digest(); const dataHash = createHmac('sha256', botSecretKey).update(data).digest('hex'); + console.log('telegramResponse-dataHash:', dataHash); return dataHash === telegramResponse.hash; }; const getUserInfo = (getConfig: GetConnectorConfig): GetUserInfo => async (data) => { + console.log('getUserInfo:', data); // Get tgAuthResult from parameterObject const { tgAuthResult } = await authorizationCallbackHandler(data); + console.log('tgAuthResult:', tgAuthResult); // Get config const config = await getConfig(defaultMetadata.id);