Skip to content

Instantly share code, notes, and snippets.

@moeinrahimi1
Created December 26, 2024 08:34
Show Gist options
  • Select an option

  • Save moeinrahimi1/276eb2e5ec4392974bbf321c068e7164 to your computer and use it in GitHub Desktop.

Select an option

Save moeinrahimi1/276eb2e5ec4392974bbf321c068e7164 to your computer and use it in GitHub Desktop.
telegram login Checking authorization
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