Created
December 26, 2024 08:34
-
-
Save moeinrahimi1/276eb2e5ec4392974bbf321c068e7164 to your computer and use it in GitHub Desktop.
telegram login Checking authorization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import crypto from 'crypto'; | |
| const validateTelegramAuth= async(authData) { | |
| const { hash, ...data } = authData; | |
| const dataCheckString = Object.keys(data) | |
| .sort() | |
| .map(k => `${k}=${data[k]}`) | |
| .join('\n'); | |
| console.log(dataCheckString,'dataCheckString') | |
| const secretKey = crypto.createHash('sha256') | |
| .update(this.BOT_TOKEN) | |
| .digest(); | |
| const hmac = crypto.createHmac('sha256', secretKey) | |
| .update(dataCheckString) | |
| .digest('hex'); | |
| if (hmac === hash) { | |
| return user; | |
| } | |
| throw new Error('Invalid authentication data'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment