Skip to content

Commit

Permalink
enables addpasskey and addauthenticator
Browse files Browse the repository at this point in the history
  • Loading branch information
arch1995 committed Sep 8, 2024
1 parent 41d2027 commit d59b30f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/core/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
BrowserStorage,
BUILD_ENV,
jsonToBase64,
LOGIN_PROVIDER,
LoginParams,
SocialMfaModParams,
UX_MODE,
Expand Down Expand Up @@ -350,6 +351,59 @@ export class Auth {
params: {
...defaultParams,
...params,
loginProvider: "authenticator",
},
sessionId: this.sessionId,
};

const result = await this.authHandler(`${this.baseUrl}/start`, dataObject);
if (this.options.uxMode === UX_MODE.REDIRECT) return undefined;
if (result.error) return false;
return true;
}

async addAuthenticatorFactor(params: Partial<BaseRedirectParams>): Promise<boolean> {
if (!this.sessionId) throw LoginError.userNotLoggedIn();

// in case of redirect mode, redirect url will be dapp specified
// in case of popup mode, redirect url will be sdk specified
const defaultParams: BaseRedirectParams = {
redirectUrl: this.options.redirectUrl,
};

const dataObject: AuthSessionConfig = {
actionType: AUTH_ACTIONS.ADD_AUTHENTICATOR_FACTOR,
options: this.options,
params: {
...defaultParams,
...params,
loginProvider: LOGIN_PROVIDER.AUTHENTICATOR,
},
sessionId: this.sessionId,
};

const result = await this.authHandler(`${this.baseUrl}/start`, dataObject);
if (this.options.uxMode === UX_MODE.REDIRECT) return undefined;
if (result.error) return false;
return true;
}

async addPasskeyFactor(params: Partial<BaseRedirectParams>): Promise<boolean> {
if (!this.sessionId) throw LoginError.userNotLoggedIn();

// in case of redirect mode, redirect url will be dapp specified
// in case of popup mode, redirect url will be sdk specified
const defaultParams: BaseRedirectParams = {
redirectUrl: this.options.redirectUrl,
};

const dataObject: AuthSessionConfig = {
actionType: AUTH_ACTIONS.ADD_PASSKEY_FACTOR,
options: this.options,
params: {
...defaultParams,
...params,
loginProvider: LOGIN_PROVIDER.PASSKEYS,
},
sessionId: this.sessionId,
};
Expand Down
4 changes: 4 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export const LOGIN_PROVIDER = {
SMS_PASSWORDLESS: "sms_passwordless",
WEBAUTHN: "webauthn",
JWT: "jwt",
PASSKEYS: "passkeys",
AUTHENTICATOR: "authenticator",
} as const;

export const MFA_LEVELS = {
Expand All @@ -52,6 +54,8 @@ export const AUTH_ACTIONS = {
ENABLE_MFA: "enable_mfa",
MANAGE_MFA: "manage_mfa",
MODIFY_SOCIAL_FACTOR: "modify_social_factor",
ADD_AUTHENTICATOR_FACTOR: "add_authenticator_factor",
ADD_PASSKEY_FACTOR: "add_passkey_factor",
} as const;

export const BUILD_ENV = {
Expand Down
1 change: 1 addition & 0 deletions src/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export type SocialMfaModParams = {
*/
extraLoginOptions?: ExtraLoginOptions;
};

export const LANGUAGES = {
en: "en",
ja: "ja",
Expand Down

0 comments on commit d59b30f

Please sign in to comment.