File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed
Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ const PASSPORT_FUNCTIONS = {
5353 getEmail : 'getEmail' ,
5454 getPassportId : 'getPassportId' ,
5555 getLinkedAddresses : 'getLinkedAddresses' ,
56+ storeTokens : 'storeTokens' ,
5657 imx : {
5758 getAddress : 'getAddress' ,
5859 isRegisteredOffchain : 'isRegisteredOffchain' ,
@@ -464,6 +465,19 @@ window.callFunction = async (jsonData: string) => {
464465 } ) ;
465466 break ;
466467 }
468+ case PASSPORT_FUNCTIONS . storeTokens : {
469+ const tokenResponse = JSON . parse ( data ) ;
470+ const profile = await getPassportClient ( ) . storeTokens ( tokenResponse ) ;
471+ identify ( { passportId : profile . sub } ) ;
472+ trackDuration ( moduleName , 'performedStoreTokens' , mt ( markStart ) ) ;
473+ callbackToGame ( {
474+ responseFor : fxName ,
475+ requestId,
476+ success : true ,
477+ error : null ,
478+ } ) ;
479+ break ;
480+ }
467481 case PASSPORT_FUNCTIONS . getEmail : {
468482 const userProfile = await getPassportClient ( ) . getUserInfo ( ) ;
469483 const success = userProfile ?. email !== undefined ;
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import MagicTEESigner from './magic/magicTEESigner';
1515import { PassportImxProviderFactory } from './starkEx' ;
1616import { PassportConfiguration } from './config' ;
1717import {
18+ DeviceTokenResponse ,
1819 DirectLoginMethod ,
1920 isUserImx ,
2021 isUserZkEvm ,
@@ -311,6 +312,14 @@ export class Passport {
311312 } , 'loginWithPKCEFlowCallback' ) ;
312313 }
313314
315+ public async storeTokens ( tokenResponse : DeviceTokenResponse ) : Promise < UserProfile > {
316+ return withMetricsAsync ( async ( ) => {
317+ const user = await this . authManager . storeTokens ( tokenResponse ) ;
318+ this . passportEventEmitter . emit ( PassportEvents . LOGGED_IN , user ) ;
319+ return user . profile ;
320+ } , 'storeTokens' ) ;
321+ }
322+
314323 /**
315324 * Logs out the current user.
316325 * @returns {Promise<void> } A promise that resolves when the logout is complete
Original file line number Diff line number Diff line change @@ -348,6 +348,16 @@ export default class AuthManager {
348348 return response . data ;
349349 }
350350
351+ public async storeTokens ( tokenResponse : DeviceTokenResponse ) : Promise < User > {
352+ return withPassportError < User > ( async ( ) => {
353+ const oidcUser = AuthManager . mapDeviceTokenResponseToOidcUser ( tokenResponse ) ;
354+ const user = AuthManager . mapOidcUserToDomainModel ( oidcUser ) ;
355+ await this . userManager . storeUser ( oidcUser ) ;
356+
357+ return user ;
358+ } , PassportErrorType . AUTHENTICATION_ERROR ) ;
359+ }
360+
351361 public async logout ( ) : Promise < void > {
352362 return withPassportError < void > ( async ( ) => {
353363 await this . userManager . revokeTokens ( [ 'refresh_token' ] ) ;
You can’t perform that action at this time.
0 commit comments