Skip to content

Commit 3717a38

Browse files
authored
Merge pull request #392 from torusresearch/feat/telegram-vue-example
feat: custom auth vue app
2 parents 917e8ba + 21ffcfb commit 3717a38

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/handlers/TelegramHandler.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import base64url from "base64url";
22
import deepmerge from "deepmerge";
33

44
import { UX_MODE } from "../utils/enums";
5-
import { broadcastChannelOptions, getTimeout, validateAndConstructUrl } from "../utils/helpers";
5+
import { broadcastChannelOptions, getTimeout, objectToAuthDataMap, validateAndConstructUrl } from "../utils/helpers";
66
import log from "../utils/loglevel";
77
import PopupHandler from "../utils/PopupHandler";
88
import AbstractLoginHandler from "./AbstractLoginHandler";
@@ -60,13 +60,9 @@ export default class TelegramHandler extends AbstractLoginHandler {
6060
this.finalURL = finalUrl;
6161
}
6262

63-
objectToAuthDataMap(tgAuthenticationResult: string) {
64-
return JSON.parse(atob(tgAuthenticationResult)) as { first_name: string; last_name: string; photo_url: string; username: string; id: number };
65-
}
66-
6763
async getUserInfo(params: LoginWindowResponse): Promise<TorusVerifierResponse> {
6864
const { idToken } = params;
69-
const userInfo = this.objectToAuthDataMap(idToken);
65+
const userInfo = objectToAuthDataMap(idToken);
7066
const { photo_url: profileImage = "", first_name = "", last_name = "", id } = userInfo;
7167
return {
7268
email: "", // Telegram does not provide email

src/login.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ class CustomAuth {
232232
if (hash && queryParameters) {
233233
const { error, hashParameters, instanceParameters } = handleRedirectParameters(hash, queryParameters);
234234
if (error) throw new Error(error);
235-
const { access_token: accessToken, id_token: idToken, ...rest } = hashParameters;
235+
const { access_token: accessToken, id_token: idToken, tgAuthResult, ...rest } = hashParameters;
236236
// State has to be last here otherwise it will be overwritten
237-
loginParams = { accessToken, idToken, ...rest, state: instanceParameters };
237+
loginParams = { accessToken, idToken: idToken || tgAuthResult || "", ...rest, state: instanceParameters };
238238
} else {
239239
this.storageHelper.clearOrphanedLoginDetails();
240240
if (this.config.uxMode === UX_MODE.REDIRECT) {

src/utils/helpers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ export const validateAndConstructUrl = (domain: string): URL => {
207207
}
208208
};
209209

210+
export const objectToAuthDataMap = (tgAuthenticationResult: string) => {
211+
return JSON.parse(atob(tgAuthenticationResult)) as { first_name: string; last_name: string; photo_url: string; username: string; id: number };
212+
};
213+
210214
export function isMobileOrTablet(): boolean {
211215
const browser = Bowser.getParser(navigator.userAgent);
212216
const platform = browser.getPlatform();

0 commit comments

Comments
 (0)