Skip to content

Instantly share code, notes, and snippets.

View shlyk's full-sized avatar
🏠
Working from home

Alexey Shlyk shlyk

🏠
Working from home
View GitHub Profile
export interface WebAppUser {
id: number;
is_bot: boolean;
first_name: string;
last_name: string;
username: string;
language_code: string;
photo_url: string;
}
@shlyk
shlyk / check-signature.js
Last active April 28, 2022 08:27
Web Apps for Telegram Bots: Validating data received via the Web App
import { createHmac } from 'crypto';
function isValidSignature(checkString) {
const decoded = decodeURIComponent(checkString)
.split('&')
.map(chunk => chunk.split('='))
.reduce((accumulator, [key, value]) => ({ ...accumulator, [key]: value }), {});
const user = JSON.parse(decoded.user);
@shlyk
shlyk / get-id-token.ts
Created January 13, 2022 13:14
Firebase exchange a refresh token for an ID token
import axios from "axios";
import { Auth } from "firebase-admin/auth";
export const getIdToken = async (auth: Auth, uid: string) => {
const customToken = await auth.createCustomToken(uid);
const res = await axios.post(
`http://localhost:[PORT]/www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken?key=[KEY]`,
{
token: customToken,
returnSecureToken: true,