Skip to content

Commit

Permalink
Add MFA Option constants.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joerger authored and github-actions committed Dec 9, 2024
1 parent 53342e7 commit 139717e
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions web/packages/teleport/src/services/mfa/mfaOptions.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
import { Auth2faType } from 'shared/services';

import { DeviceType, MfaAuthenticateChallenge } from './types';

export type MfaOption = {
value: DeviceType;
label: string;
};
import { DeviceType, MfaAuthenticateChallenge, SSOChallenge } from './types';

export function getMfaChallengeOptions(mfaChallenge: MfaAuthenticateChallenge) {
const mfaOptions: MfaOption[] = [];

if (mfaChallenge?.webauthnPublicKey) {
mfaOptions.push({ value: 'webauthn', label: 'Passkey or Security Key' });
mfaOptions.push(webauthnOption);
}

if (mfaChallenge?.totpChallenge) {
mfaOptions.push({ value: 'totp', label: 'Authenticator App' });
mfaOptions.push(totpOption);
}

if (mfaChallenge?.ssoChallenge) {
mfaOptions.push({
value: 'sso',
label:
mfaChallenge.ssoChallenge.device.displayName ||
mfaChallenge.ssoChallenge.device.connectorId,
});
mfaOptions.push(getSsoOption(mfaChallenge.ssoChallenge));
}

return mfaOptions;
Expand All @@ -34,12 +24,31 @@ export function getMfaRegisterOptions(auth2faType: Auth2faType) {
const mfaOptions: MfaOption[] = [];

if (auth2faType === 'webauthn' || auth2faType === 'on') {
mfaOptions.push({ value: 'webauthn', label: 'Passkey or Security Key' });
mfaOptions.push(webauthnOption);
}

if (auth2faType === 'otp' || auth2faType === 'on') {
mfaOptions.push({ value: 'totp', label: 'Authenticator App' });
mfaOptions.push(totpOption);
}

return mfaOptions;
}

export type MfaOption = {
value: DeviceType;
label: string;
};

const webauthnOption: MfaOption = {
value: 'webauthn',
label: 'Passkey or Security Key',
};

const totpOption: MfaOption = { value: 'totp', label: 'Authenticator App' };

const getSsoOption = (ssoChallenge: SSOChallenge): MfaOption => {
return {
value: 'sso',
label: ssoChallenge.device.displayName || ssoChallenge.device.connectorId,
};
};

0 comments on commit 139717e

Please sign in to comment.