passport-telegram-web-app
Version:
A [Passport](https://www.passportjs.org/) strategy for [telegram web app (bots)](https://core.telegram.org/bots/webapps) authentication.
22 lines (17 loc) • 609 B
text/typescript
import { DataInterface } from "./interfaces/data.interface";
export class ExtractData {
public static fromHeaders(request: any): DataInterface | null {
const authDate = request.headers["tg-web-app-auth-date"];
const queryId = request.headers["tg-web-app-query-id"];
const userRaw = request.headers["tg-web-app-user"];
if (!(authDate && queryId && userRaw)) {
return null;
}
const userRawDecoded = decodeURIComponent(userRaw.toString());
return {
authDate: authDate as string,
queryId: queryId as string,
user: JSON.parse(userRawDecoded),
};
}
}