Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions keeperapi/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion keeperapi/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@keeper-security/keeperapi",
"description": "Keeper API Javascript SDK",
"version": "17.0.6",
"version": "17.0.7",
"browser": "dist/index.es.js",
"main": "dist/index.cjs.js",
"types": "dist/node/index.d.ts",
Expand Down
12 changes: 6 additions & 6 deletions keeperapi/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
LoginError,
TwoFactorChannelData
} from './configuration'
import {KeeperEndpoint, KeeperEnvironment} from "./endpoint";
import {KeeperEndpoint, KeeperEnvironment, ExecuteRestOptions} from "./endpoint";
import {KeyWrapper, platform} from "./platform";
import {
generateEncryptionKey,
Expand Down Expand Up @@ -615,13 +615,13 @@ export class Auth {
}
}

async getSsoProvider(ssoDomain: string, locale?: string, ecOnly = false) {
async getSsoProvider(ssoDomain: string, locale?: string, ecOnly = false, skipRegionRedirect = false) {
let domainRequest: ISsoServiceProviderRequest = {
name: ssoDomain.trim(),
locale: locale,
clientVersion: this.endpoint.clientVersion,
}
const domainResponse = await this.executeRest(ssoServiceProviderRequestMessage(domainRequest))
const domainResponse = await this.executeRest(ssoServiceProviderRequestMessage(domainRequest), { skipRegionRedirect })
const params = domainResponse.isCloud
? '?payload=' + await this._endpoint.prepareSsoPayload(this.messageSessionUid)
: '?embedded&key=' + await this._endpoint.getOnsitePublicKey(ecOnly)
Expand Down Expand Up @@ -1117,8 +1117,8 @@ export class Auth {
// return this.endpoint.executeV2Command(command);
// }

async executeRest<TIn, TOut>(message: RestOutMessage<TOut> | RestMessage<TIn, TOut>): Promise<TOut> {
return this.endpoint.executeRest(message, this._sessionToken);
async executeRest<TIn, TOut>(message: RestOutMessage<TOut> | RestMessage<TIn, TOut>, options?: ExecuteRestOptions): Promise<TOut> {
return this.endpoint.executeRest(message, this._sessionToken, options);
}

async executeRestCommand<Request, Response>(command: RestCommand<Request, Response>): Promise<Response> {
Expand Down Expand Up @@ -1374,4 +1374,4 @@ function chooseErrorMessage(loginState: Authentication.LoginState){
}

const hasYubikeyChannel = (channels: Authentication.ITwoFactorChannelInfo[]): boolean =>
!!channels.find(({challenge, channelType}) => challenge && (channelType === Authentication.TwoFactorChannelType.TWO_FA_CT_U2F || channelType === Authentication.TwoFactorChannelType.TWO_FA_CT_WEBAUTHN))
!!channels.find(({challenge, channelType}) => challenge && (channelType === Authentication.TwoFactorChannelType.TWO_FA_CT_U2F || channelType === Authentication.TwoFactorChannelType.TWO_FA_CT_WEBAUTHN))
13 changes: 10 additions & 3 deletions keeperapi/src/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import SsoCloudResponse = SsoCloud.SsoCloudResponse;
import {KeeperHttpResponse, RestCommand} from './commands'
import {AllowedEcKeyIds, AllowedMlKemKeyIds, isAllowedEcKeyId, isAllowedMlKemKeyId} from './transmissionKeys'

export type ExecuteRestOptions = {
skipRegionRedirect?: boolean
}

export class KeeperEndpoint {
private _transmissionKey?: TransmissionKey
private locale?: string
Expand Down Expand Up @@ -154,16 +158,16 @@ export class KeeperEndpoint {
}
}

async executeRest<TIn, TOut>(message: RestOutMessage<TOut> | RestMessage<TIn, TOut>, sessionToken?: string): Promise<TOut> {
async executeRest<TIn, TOut>(message: RestOutMessage<TOut> | RestMessage<TIn, TOut>, sessionToken?: string, options?: ExecuteRestOptions): Promise<TOut> {
// @ts-ignore
return this.executeRestInternal(message, sessionToken)
return this.executeRestInternal(message, sessionToken, options)
}

async executeRestAction<TIn>(message: RestInMessage<TIn> | RestActionMessage, sessionToken?: string): Promise<void> {
return this.executeRestInternal(message, sessionToken)
}

private async executeRestInternal<TIn, TOut>(message: RestInMessage<TIn> | RestOutMessage<TOut> | RestMessage<TIn, TOut> | RestActionMessage, sessionToken?: string): Promise<TOut | void> {
private async executeRestInternal<TIn, TOut>(message: RestInMessage<TIn> | RestOutMessage<TOut> | RestMessage<TIn, TOut> | RestActionMessage, sessionToken?: string, options?: ExecuteRestOptions): Promise<TOut | void> {
this._transmissionKey = await this.getTransmissionKey()
while (true) {
const payload = 'toBytes' in message ? message.toBytes() : new Uint8Array()
Expand Down Expand Up @@ -233,6 +237,9 @@ export class KeeperEndpoint {
await this.updateTransmissionKey(newEcKeyId, newMlKemKeyId)
continue
case 'region_redirect':
if (options?.skipRegionRedirect) {
throw new Error('region_redirect')
}
this.options.host = errorObj.region_host!
if (this.options.onRegionChanged) {
await this.options.onRegionChanged(this.options.host);
Expand Down