diff --git a/keeperapi/package-lock.json b/keeperapi/package-lock.json index e8725223..d176a73d 100644 --- a/keeperapi/package-lock.json +++ b/keeperapi/package-lock.json @@ -1,12 +1,12 @@ { "name": "@keeper-security/keeperapi", - "version": "16.0.84", + "version": "16.0.85", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@keeper-security/keeperapi", - "version": "16.0.84", + "version": "16.0.85", "license": "ISC", "dependencies": { "asmcrypto.js": "^2.3.2", diff --git a/keeperapi/package.json b/keeperapi/package.json index 2e09e26f..5013d0bd 100644 --- a/keeperapi/package.json +++ b/keeperapi/package.json @@ -1,7 +1,7 @@ { "name": "@keeper-security/keeperapi", "description": "Keeper API Javascript SDK", - "version": "16.0.84", + "version": "16.0.85", "browser": "dist/index.es.js", "main": "dist/index.cjs.js", "types": "dist/node/index.d.ts", diff --git a/keeperapi/src/auth.ts b/keeperapi/src/auth.ts index e58c780f..9aed534f 100644 --- a/keeperapi/src/auth.ts +++ b/keeperapi/src/auth.ts @@ -33,6 +33,7 @@ import { ssoServiceProviderRequestMessage, startLoginMessage, startLoginMessageFromSessionToken, + switchAccountFromAuthenticated, twoFactorSend2FAPushMessage, twoFactorValidateMessage, twoFASendDuoMessage, @@ -42,7 +43,6 @@ import { import {AccountSummary, Authentication} from './proto'; import {RestCommand} from './commands' import {CloseReason, createAsyncSocket, SocketListener} from './socket'; -import IStartLoginRequest = Authentication.IStartLoginRequest; import ITwoFactorSendPushRequest = Authentication.ITwoFactorSendPushRequest; import TwoFactorExpiration = Authentication.TwoFactorExpiration; import TwoFactorPushType = Authentication.TwoFactorPushType; @@ -509,6 +509,23 @@ export class Auth { } } + async switchToActiveAccount({username}: {username: string}): Promise { + try { + const request = new Authentication.LoginAsUserRequest({username}) + const response = await this.executeRest(switchAccountFromAuthenticated(request)) + if (response.loginState !== Authentication.LoginState.LOGGED_IN) { + throw new Error('account switching failed') + } + if (response.cloneCode && response.cloneCode.length > 0) { + this.options.sessionStorage?.saveCloneCode(this.options.host as KeeperEnvironment, this._username, response.cloneCode) + } + return response + } catch (err) { + console.error(err) + return undefined + } + } + /** * The MV3 browser extension runs in a service worker that shuts down every 5 minutes. * This rehydrates the Auth class and re-opens our socket with the session parameters.