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);