Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add passkey and Add authenticator #340

Merged
merged 2 commits into from
Sep 12, 2024
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
53 changes: 53 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 @@ -360,6 +361,58 @@ export class Auth {
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,
};

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;
}

getUserInfo(): AuthUserInfo {
if (!this.sessionManager.sessionId) {
throw LoginError.userNotLoggedIn();
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 @@
*/
extraLoginOptions?: ExtraLoginOptions;
};

export const LANGUAGES = {
en: "en",
ja: "ja",
Expand Down Expand Up @@ -335,19 +336,19 @@
/**
* Language specific link for terms and conditions on torus-website. See (examples/vue-app) to configure
* e.g.
* tncLink: {

Check warning on line 339 in src/utils/interfaces.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-latest)

tsdoc-malformed-inline-tag: Expecting a TSDoc tag starting with "{@"
* en: "http://example.com/tnc/en",
* ja: "http://example.com/tnc/ja",
* }

Check warning on line 342 in src/utils/interfaces.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-latest)

tsdoc-escape-right-brace: The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
*/
tncLink?: Partial<Record<LANGUAGE_TYPE, string>>;
/**
* Language specific link for privacy policy on torus-website. See (examples/vue-app) to configure
* e.g.
* privacyPolicy: {

Check warning on line 348 in src/utils/interfaces.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-latest)

tsdoc-malformed-inline-tag: Expecting a TSDoc tag starting with "{@"
* en: "http://example.com/tnc/en",
* ja: "http://example.com/tnc/ja",
* }

Check warning on line 351 in src/utils/interfaces.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-latest)

tsdoc-escape-right-brace: The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
*/
privacyPolicy?: Partial<Record<LANGUAGE_TYPE, string>>;
};
Expand Down
Loading