@oneblink/apps-react 11.0.0-beta.1 → 11.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apps/auth-service.d.ts +3 -3
- package/dist/apps/auth-service.js +2 -2
- package/dist/apps/auth-service.js.map +1 -1
- package/dist/apps/index.d.ts +10 -0
- package/dist/apps/index.js +10 -0
- package/dist/apps/index.js.map +1 -1
- package/dist/apps/mfa-service.d.ts +4 -0
- package/dist/apps/mfa-service.js +3 -0
- package/dist/apps/mfa-service.js.map +1 -0
- package/dist/apps/services/cognito.d.ts +3 -3
- package/dist/apps/services/cognito.js +3 -3
- package/dist/apps/services/cognito.js.map +1 -1
- package/dist/components/mfa/MfaAuthenticatorAppDialog.js +2 -2
- package/dist/components/mfa/MfaAuthenticatorAppDialog.js.map +1 -1
- package/dist/components/mfa/MfaMethodRow.d.ts +2 -1
- package/dist/components/mfa/MfaMethodRow.js +3 -3
- package/dist/components/mfa/MfaMethodRow.js.map +1 -1
- package/dist/components/mfa/MultiFactorAuthentication.d.ts +11 -10
- package/dist/components/mfa/MultiFactorAuthentication.js +20 -14
- package/dist/components/mfa/MultiFactorAuthentication.js.map +1 -1
- package/dist/hooks/useLogin.d.ts +2 -2
- package/dist/hooks/useLogin.js.map +1 -1
- package/dist/hooks/useMfa.d.ts +66 -29
- package/dist/hooks/useMfa.js +85 -43
- package/dist/hooks/useMfa.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/joinArray.d.ts +1 -0
- package/dist/utils/joinArray.js +7 -0
- package/dist/utils/joinArray.js.map +1 -0
- package/dist/utils/mfa-requirement.d.ts +12 -0
- package/dist/utils/mfa-requirement.js +96 -0
- package/dist/utils/mfa-requirement.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { MiscTypes } from '@oneblink/types';
|
|
2
2
|
import { getIdToken, getFormsKeyId, setFormsKeyToken } from './services/forms-key';
|
|
3
|
-
import { registerAuthListener, isLoggedIn, loginHostedUI, loginUsernamePassword, changePassword, forgotPassword, handleAuthentication, logoutHostedUI, getUserProfile, getUserFriendlyName
|
|
3
|
+
import { registerAuthListener, isLoggedIn, loginHostedUI, loginUsernamePassword, changePassword, forgotPassword, handleAuthentication, logoutHostedUI, getUserProfile, getUserFriendlyName } from './services/cognito';
|
|
4
4
|
import { getUserToken, setUserToken } from './services/user-token';
|
|
5
|
-
export { registerAuthListener, loginHostedUI, loginUsernamePassword, handleAuthentication, logoutHostedUI, changePassword, forgotPassword, isLoggedIn, getIdToken, getUserProfile, getFormsKeyId, setFormsKeyToken, getUserToken, setUserToken, getUserFriendlyName,
|
|
6
|
-
export type { LoginAttemptResponse
|
|
5
|
+
export { registerAuthListener, loginHostedUI, loginUsernamePassword, handleAuthentication, logoutHostedUI, changePassword, forgotPassword, isLoggedIn, getIdToken, getUserProfile, getFormsKeyId, setFormsKeyToken, getUserToken, setUserToken, getUserFriendlyName, };
|
|
6
|
+
export type { LoginAttemptResponse } from './services/cognito';
|
|
7
7
|
/**
|
|
8
8
|
* Log the current user out and remove an data stored locally by the user e.g.
|
|
9
9
|
* drafts.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import OneBlinkAppsError from './services/errors/oneBlinkAppsError';
|
|
2
2
|
import { getIdToken, getFormsKeyId, setFormsKeyToken, } from './services/forms-key';
|
|
3
|
-
import { init as initCognito, registerAuthListener, isLoggedIn, loginHostedUI, loginUsernamePassword, changePassword, forgotPassword, handleAuthentication, logoutHostedUI, logout as logoutCognito, getUserProfile, getUsername, getUserFriendlyName,
|
|
3
|
+
import { init as initCognito, registerAuthListener, isLoggedIn, loginHostedUI, loginUsernamePassword, changePassword, forgotPassword, handleAuthentication, logoutHostedUI, logout as logoutCognito, getUserProfile, getUsername, getUserFriendlyName, } from './services/cognito';
|
|
4
4
|
import { getRequest, postRequest } from './services/fetch';
|
|
5
5
|
import tenants from './tenants';
|
|
6
6
|
import { getUserToken, setUserToken } from './services/user-token';
|
|
7
7
|
import utilsService from './services/utils';
|
|
8
|
-
export { registerAuthListener, loginHostedUI, loginUsernamePassword, handleAuthentication, logoutHostedUI, changePassword, forgotPassword, isLoggedIn, getIdToken, getUserProfile, getFormsKeyId, setFormsKeyToken, getUserToken, setUserToken, getUserFriendlyName,
|
|
8
|
+
export { registerAuthListener, loginHostedUI, loginUsernamePassword, handleAuthentication, logoutHostedUI, changePassword, forgotPassword, isLoggedIn, getIdToken, getUserProfile, getFormsKeyId, setFormsKeyToken, getUserToken, setUserToken, getUserFriendlyName, };
|
|
9
9
|
import Sentry from './Sentry';
|
|
10
10
|
/**
|
|
11
11
|
* Log the current user out and remove an data stored locally by the user e.g.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-service.js","sourceRoot":"","sources":["../../src/apps/auth-service.ts"],"names":[],"mappings":"AACA,OAAO,iBAAiB,MAAM,qCAAqC,CAAA;AACnE,OAAO,EACL,UAAU,EACV,aAAa,EACb,gBAAgB,GACjB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,IAAI,IAAI,WAAW,EACnB,oBAAoB,EACpB,UAAU,EACV,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,MAAM,IAAI,aAAa,EACvB,cAAc,EACd,WAAW,EACX,mBAAmB,EAKnB,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,+BAA+B,EAC/B,qBAAqB,EACrB,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,EACxB,WAAW,EACX,oCAAoC,EACpC,oBAAoB,GACrB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,UAAU,EAAE,WAAW,EAAa,MAAM,kBAAkB,CAAA;AACrE,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,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B;YACzB,cAAc,EAAG,KAAmB,CAAC,MAAM;SAC5C,CACF,CAAA;IACH,CAAC;AACH,CAAC","sourcesContent":["import { MiscTypes } from '@oneblink/types'\nimport OneBlinkAppsError from './services/errors/oneBlinkAppsError'\nimport {\n getIdToken,\n getFormsKeyId,\n setFormsKeyToken,\n} from './services/forms-key'\nimport {\n init as initCognito,\n registerAuthListener,\n isLoggedIn,\n loginHostedUI,\n loginUsernamePassword,\n changePassword,\n forgotPassword,\n handleAuthentication,\n logoutHostedUI,\n logout as logoutCognito,\n getUserProfile,\n getUsername,\n getUserFriendlyName,\n LoginAttemptResponse,\n MfaMethod,\n MfaRequirementCheckResult,\n MfaSettings,\n checkIsMfaEnabled,\n getMfaSettings,\n updateUserPhoneNumber,\n removeUserPhoneNumber,\n sendPhoneNumberVerificationCode,\n verifyUserPhoneNumber,\n disableMfaMethod,\n setPreferredMfaMethod,\n setupMfaAuthenticatorApp,\n setupSmsMfa,\n generateMfaAuthenticatorAppQrCodeUrl,\n DEFAULT_MFA_SETTINGS,\n} from './services/cognito'\nimport { getRequest, postRequest, HTTPError } from './services/fetch'\nimport tenants from './tenants'\nimport { getUserToken, setUserToken } from './services/user-token'\nimport utilsService from './services/utils'\n\nexport {\n registerAuthListener,\n loginHostedUI,\n loginUsernamePassword,\n handleAuthentication,\n logoutHostedUI,\n changePassword,\n forgotPassword,\n isLoggedIn,\n getIdToken,\n getUserProfile,\n getFormsKeyId,\n setFormsKeyToken,\n getUserToken,\n setUserToken,\n getUserFriendlyName,\n checkIsMfaEnabled,\n getMfaSettings,\n updateUserPhoneNumber,\n removeUserPhoneNumber,\n sendPhoneNumberVerificationCode,\n verifyUserPhoneNumber,\n disableMfaMethod,\n setPreferredMfaMethod,\n setupMfaAuthenticatorApp,\n setupSmsMfa,\n generateMfaAuthenticatorAppQrCodeUrl,\n DEFAULT_MFA_SETTINGS,\n}\nexport type {\n LoginAttemptResponse,\n MfaMethod,\n MfaRequirementCheckResult,\n MfaSettings,\n}\nimport Sentry from './Sentry'\n\n/**\n * Log the current user out and remove an data stored locally by the user e.g.\n * drafts.\n *\n * #### Example\n *\n * ```js\n * await authService.logout()\n * ```\n */\nexport async function logout() {\n console.log('Logging out...')\n\n try {\n await utilsService.localForage.clear()\n } catch (error) {\n Sentry.captureException(error)\n console.warn('Could not clear localForage before logging out', error)\n }\n\n await logoutCognito()\n}\n\n/**\n * Initialize the service with required configuration. **This must be done\n * before using before some of the function in this service.**\n *\n * #### Example\n *\n * ```js\n * authService.init({\n * oAuthClientId: 'YOUR_OAUTH_CLIENT_ID',\n * })\n * ```\n *\n * @param options\n */\nexport function init({ oAuthClientId }: { oAuthClientId: string }) {\n initCognito({\n region: tenants.current.awsRegion,\n loginDomain: tenants.current.loginDomain,\n oAuthClientId,\n redirectUri: window.location.origin + '/callback',\n logoutUri: window.location.origin + '/logout',\n })\n\n const listener = () => {\n Sentry.setTag('username', getUsername() || undefined)\n }\n listener()\n registerAuthListener(listener)\n}\n\n/**\n * Determine if the current user is a OneBlink App User for a OneBlink Forms\n * App. Returns `false` if the current user is not logged in.\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const isAuthorised = await authService.isAuthorised(formsAppId)\n * if (!isAuthorised) {\n * // handle unauthorised user\n * }\n * ```\n *\n * @param formsAppId\n * @param abortSignal\n * @returns\n */\nexport async function isAuthorised(\n formsAppId: number,\n abortSignal?: AbortSignal,\n): Promise<boolean> {\n return getCurrentFormsAppUser(formsAppId, abortSignal)\n .then(() => true)\n .catch((error) => {\n if (error.status >= 400 && error.status < 500) {\n return false\n } else {\n Sentry.captureException(error)\n console.log(\n 'Could not determine if the current user has access to this forms app',\n error,\n )\n return false\n }\n })\n}\n\n/**\n * Get the current user's App User details for a OneBlink Forms App. Returns\n * `undefined` if the current user is not logged in.\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const formsAppUserDetails =\n * await authService.getCurrentFormsAppUser(formsAppId)\n * if (!formsAppUserDetails) {\n * // handle unauthorised user\n * }\n * ```\n *\n * @param formsAppId\n * @returns\n */\nexport async function getCurrentFormsAppUser(\n formsAppId: number,\n abortSignal?: AbortSignal,\n): Promise<\n | {\n userProfile?: MiscTypes.UserProfile\n formsAppId: number\n groups: string[]\n }\n | undefined\n> {\n if (getFormsKeyId()) {\n return {\n formsAppId,\n groups: [],\n }\n }\n\n const userProfile = getUserProfile()\n\n if (!userProfile) {\n return undefined\n }\n\n const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/my-forms-app-user`\n return await getRequest<{\n userProfile?: MiscTypes.UserProfile\n formsAppId: number\n groups: string[]\n }>(url, abortSignal)\n}\n\n/**\n * If the current user is not a Forms App User, this function will send a\n * request on behalf of the current user to the OneBlink Forms App\n * administrators to request access.\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * await authService.requestAccess(formsAppId)\n * // Display a message to user indicating a request has been sent to the application administrators\n * ```\n *\n * @param formsAppId\n */\nexport async function requestAccess(formsAppId: number): Promise<void> {\n if (!isLoggedIn()) {\n throw new OneBlinkAppsError(\n 'You must login before requesting access to this application',\n {\n requiresLogin: true,\n },\n )\n }\n\n try {\n const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/request-access`\n await postRequest(url)\n } catch (error) {\n Sentry.captureException(error)\n console.warn('Error while requesting access to forms app', error)\n\n throw new OneBlinkAppsError(\n 'Sorry, we could not request access automatically right now, please try again. If the problem persists, please contact your administrator yourself.',\n {\n originalError: error as Error,\n title: 'Error Requesting Access',\n httpStatusCode: (error as HTTPError).status,\n },\n )\n }\n}\n\n/**\n * Allow a user to sign up to a forms app.\n *\n * #### Example\n *\n * ```js\n * await authService.signUp({\n * formsAppId: 1,\n * email: 'test@oneblink.io',\n * firstName: 'first',\n * lastName: 'last',\n * })\n * ```\n *\n * @param {formsAppId, email, generatePassword, firstName, lastName}\n * @returns\n */\n\nexport async function signUp({\n formsAppId,\n email,\n firstName,\n lastName,\n}: {\n formsAppId: number\n email: string\n firstName?: string\n lastName?: string\n}): Promise<void> {\n try {\n const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/sign-up`\n return await postRequest(url, {\n email,\n firstName,\n lastName,\n })\n } catch (error) {\n Sentry.captureException(error)\n console.warn('Error while calling sign-up to forms app', error)\n\n throw new OneBlinkAppsError(\n 'Sorry, we could not create you a account right now, please try again. If the problem persists, please contact your administrator yourself.',\n {\n originalError: error as Error,\n title: 'Error Signing up',\n httpStatusCode: (error as HTTPError).status,\n },\n )\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"auth-service.js","sourceRoot":"","sources":["../../src/apps/auth-service.ts"],"names":[],"mappings":"AACA,OAAO,iBAAiB,MAAM,qCAAqC,CAAA;AACnE,OAAO,EACL,UAAU,EACV,aAAa,EACb,gBAAgB,GACjB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,IAAI,IAAI,WAAW,EACnB,oBAAoB,EACpB,UAAU,EACV,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,MAAM,IAAI,aAAa,EACvB,cAAc,EACd,WAAW,EACX,mBAAmB,GACpB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,UAAU,EAAE,WAAW,EAAa,MAAM,kBAAkB,CAAA;AACrE,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAClE,OAAO,YAAY,MAAM,kBAAkB,CAAA;AAE3C,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,cAAc,EACd,UAAU,EACV,UAAU,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,mBAAmB,GACpB,CAAA;AAED,OAAO,MAAM,MAAM,UAAU,CAAA;AAE7B;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,OAAO,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a,EAAE,KAAc;YAC7B,KAAK,EAAE,yBAAyB;YAChC,cAAc,EAAG,KAAmB,CAAC,MAAM;SAC5C,CACF,CAAA;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,EAC3B,UAAU,EACV,KAAK,EACL,SAAS,EACT,QAAQ,GAMT;IACC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,eAAe,UAAU,UAAU,CAAA;QAC3E,OAAO,MAAM,WAAW,CAAC,GAAG,EAAE;YAC5B,KAAK;YACL,SAAS;YACT,QAAQ;SACT,CAAC,CAAA;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;QAC9B,OAAO,CAAC,IAAI,CAAC,0CAA0C,EAAE,KAAK,CAAC,CAAA;QAE/D,MAAM,IAAI,iBAAiB,CACzB,4IAA4I,EAC5I;YACE,aAAa,EAAE,KAAc;YAC7B,KAAK,EAAE,kBAAkB;YACzB,cAAc,EAAG,KAAmB,CAAC,MAAM;SAC5C,CACF,CAAA;IACH,CAAC;AACH,CAAC","sourcesContent":["import { MiscTypes } from '@oneblink/types'\nimport OneBlinkAppsError from './services/errors/oneBlinkAppsError'\nimport {\n getIdToken,\n getFormsKeyId,\n setFormsKeyToken,\n} from './services/forms-key'\nimport {\n init as initCognito,\n registerAuthListener,\n isLoggedIn,\n loginHostedUI,\n loginUsernamePassword,\n changePassword,\n forgotPassword,\n handleAuthentication,\n logoutHostedUI,\n logout as logoutCognito,\n getUserProfile,\n getUsername,\n getUserFriendlyName,\n} from './services/cognito'\nimport { getRequest, postRequest, HTTPError } from './services/fetch'\nimport tenants from './tenants'\nimport { getUserToken, setUserToken } from './services/user-token'\nimport utilsService from './services/utils'\n\nexport {\n registerAuthListener,\n loginHostedUI,\n loginUsernamePassword,\n handleAuthentication,\n logoutHostedUI,\n changePassword,\n forgotPassword,\n isLoggedIn,\n getIdToken,\n getUserProfile,\n getFormsKeyId,\n setFormsKeyToken,\n getUserToken,\n setUserToken,\n getUserFriendlyName,\n}\nexport type { LoginAttemptResponse } from './services/cognito'\nimport Sentry from './Sentry'\n\n/**\n * Log the current user out and remove an data stored locally by the user e.g.\n * drafts.\n *\n * #### Example\n *\n * ```js\n * await authService.logout()\n * ```\n */\nexport async function logout() {\n console.log('Logging out...')\n\n try {\n await utilsService.localForage.clear()\n } catch (error) {\n Sentry.captureException(error)\n console.warn('Could not clear localForage before logging out', error)\n }\n\n await logoutCognito()\n}\n\n/**\n * Initialize the service with required configuration. **This must be done\n * before using before some of the function in this service.**\n *\n * #### Example\n *\n * ```js\n * authService.init({\n * oAuthClientId: 'YOUR_OAUTH_CLIENT_ID',\n * })\n * ```\n *\n * @param options\n */\nexport function init({ oAuthClientId }: { oAuthClientId: string }) {\n initCognito({\n region: tenants.current.awsRegion,\n loginDomain: tenants.current.loginDomain,\n oAuthClientId,\n redirectUri: window.location.origin + '/callback',\n logoutUri: window.location.origin + '/logout',\n })\n\n const listener = () => {\n Sentry.setTag('username', getUsername() || undefined)\n }\n listener()\n registerAuthListener(listener)\n}\n\n/**\n * Determine if the current user is a OneBlink App User for a OneBlink Forms\n * App. Returns `false` if the current user is not logged in.\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const isAuthorised = await authService.isAuthorised(formsAppId)\n * if (!isAuthorised) {\n * // handle unauthorised user\n * }\n * ```\n *\n * @param formsAppId\n * @param abortSignal\n * @returns\n */\nexport async function isAuthorised(\n formsAppId: number,\n abortSignal?: AbortSignal,\n): Promise<boolean> {\n return getCurrentFormsAppUser(formsAppId, abortSignal)\n .then(() => true)\n .catch((error) => {\n if (error.status >= 400 && error.status < 500) {\n return false\n } else {\n Sentry.captureException(error)\n console.log(\n 'Could not determine if the current user has access to this forms app',\n error,\n )\n return false\n }\n })\n}\n\n/**\n * Get the current user's App User details for a OneBlink Forms App. Returns\n * `undefined` if the current user is not logged in.\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const formsAppUserDetails =\n * await authService.getCurrentFormsAppUser(formsAppId)\n * if (!formsAppUserDetails) {\n * // handle unauthorised user\n * }\n * ```\n *\n * @param formsAppId\n * @returns\n */\nexport async function getCurrentFormsAppUser(\n formsAppId: number,\n abortSignal?: AbortSignal,\n): Promise<\n | {\n userProfile?: MiscTypes.UserProfile\n formsAppId: number\n groups: string[]\n }\n | undefined\n> {\n if (getFormsKeyId()) {\n return {\n formsAppId,\n groups: [],\n }\n }\n\n const userProfile = getUserProfile()\n\n if (!userProfile) {\n return undefined\n }\n\n const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/my-forms-app-user`\n return await getRequest<{\n userProfile?: MiscTypes.UserProfile\n formsAppId: number\n groups: string[]\n }>(url, abortSignal)\n}\n\n/**\n * If the current user is not a Forms App User, this function will send a\n * request on behalf of the current user to the OneBlink Forms App\n * administrators to request access.\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * await authService.requestAccess(formsAppId)\n * // Display a message to user indicating a request has been sent to the application administrators\n * ```\n *\n * @param formsAppId\n */\nexport async function requestAccess(formsAppId: number): Promise<void> {\n if (!isLoggedIn()) {\n throw new OneBlinkAppsError(\n 'You must login before requesting access to this application',\n {\n requiresLogin: true,\n },\n )\n }\n\n try {\n const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/request-access`\n await postRequest(url)\n } catch (error) {\n Sentry.captureException(error)\n console.warn('Error while requesting access to forms app', error)\n\n throw new OneBlinkAppsError(\n 'Sorry, we could not request access automatically right now, please try again. If the problem persists, please contact your administrator yourself.',\n {\n originalError: error as Error,\n title: 'Error Requesting Access',\n httpStatusCode: (error as HTTPError).status,\n },\n )\n }\n}\n\n/**\n * Allow a user to sign up to a forms app.\n *\n * #### Example\n *\n * ```js\n * await authService.signUp({\n * formsAppId: 1,\n * email: 'test@oneblink.io',\n * firstName: 'first',\n * lastName: 'last',\n * })\n * ```\n *\n * @param {formsAppId, email, generatePassword, firstName, lastName}\n * @returns\n */\n\nexport async function signUp({\n formsAppId,\n email,\n firstName,\n lastName,\n}: {\n formsAppId: number\n email: string\n firstName?: string\n lastName?: string\n}): Promise<void> {\n try {\n const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/sign-up`\n return await postRequest(url, {\n email,\n firstName,\n lastName,\n })\n } catch (error) {\n Sentry.captureException(error)\n console.warn('Error while calling sign-up to forms app', error)\n\n throw new OneBlinkAppsError(\n 'Sorry, we could not create you a account right now, please try again. If the problem persists, please contact your administrator yourself.',\n {\n originalError: error as Error,\n title: 'Error Signing up',\n httpStatusCode: (error as HTTPError).status,\n },\n )\n }\n}\n"]}
|
package/dist/apps/index.d.ts
CHANGED
|
@@ -21,6 +21,16 @@ export * as offlineService from './offline-service';
|
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
23
|
export * as authService from './auth-service';
|
|
24
|
+
/**
|
|
25
|
+
* ## MFA Service
|
|
26
|
+
*
|
|
27
|
+
* Helper functions for multi factor authentication and MFA requirements.
|
|
28
|
+
*
|
|
29
|
+
* ```js
|
|
30
|
+
* import { mfaService } from '@oneblink/apps-react'
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export * as mfaService from './mfa-service';
|
|
24
34
|
/**
|
|
25
35
|
* ## Draft Service
|
|
26
36
|
*
|
package/dist/apps/index.js
CHANGED
|
@@ -21,6 +21,16 @@ export * as offlineService from './offline-service';
|
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
23
|
export * as authService from './auth-service';
|
|
24
|
+
/**
|
|
25
|
+
* ## MFA Service
|
|
26
|
+
*
|
|
27
|
+
* Helper functions for multi factor authentication and MFA requirements.
|
|
28
|
+
*
|
|
29
|
+
* ```js
|
|
30
|
+
* import { mfaService } from '@oneblink/apps-react'
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export * as mfaService from './mfa-service';
|
|
24
34
|
/**
|
|
25
35
|
* ## Draft Service
|
|
26
36
|
*
|
package/dist/apps/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/apps/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,cAAc,MAAM,mBAAmB,CAAA;AACnD;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,WAAW,MAAM,gBAAgB,CAAA;AAC7C;;;;;;;;GAQG;AACH,OAAO,KAAK,YAAY,MAAM,iBAAiB,CAAA;AAC/C;;;;;;;;GAQG;AACH,OAAO,KAAK,cAAc,MAAM,mBAAmB,CAAA;AACnD;;;;;;;;GAQG;AACH,OAAO,KAAK,cAAc,MAAM,mBAAmB,CAAA;AACnD;;;;;;;;GAQG;AACH,OAAO,KAAK,iBAAiB,MAAM,sBAAsB,CAAA;AACzD;;;;;;;;GAQG;AACH,OAAO,KAAK,UAAU,MAAM,eAAe,CAAA;AAC3C;;;;;;;;GAQG;AACH,OAAO,KAAK,iBAAiB,MAAM,sBAAsB,CAAA;AACzD;;;;;;;;GAQG;AACH,OAAO,KAAK,eAAe,MAAM,qBAAqB,CAAA;AACtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,OAAO,KAAK,mBAAmB,MAAM,wBAAwB,CAAA;AAC7D;;;;;;;;GAQG;AACH,OAAO,KAAK,WAAW,MAAM,gBAAgB,CAAA;AAC7C;;;;;;;;GAQG;AACH,OAAO,KAAK,gBAAgB,MAAM,qBAAqB,CAAA;AACvD;;;;;;;;GAQG;AACH,OAAO,KAAK,eAAe,MAAM,qBAAqB,CAAA;AACtD;;;;;;;;GAQG;AACH,OAAO,KAAK,gBAAgB,MAAM,sBAAsB,CAAA;AACxD;;;;;;;;GAQG;AACH,OAAO,KAAK,mBAAmB,MAAM,wBAAwB,CAAA;AAC7D;;;;;;;;GAQG;AACH,OAAO,KAAK,kBAAkB,MAAM,uBAAuB,CAAA;AAC3D;;;;;;;;GAQG;AACH,OAAO,KAAK,qBAAqB,MAAM,2BAA2B,CAAA;AAClE;;;;;;;;GAQG;AACH,OAAO,KAAK,0BAA0B,MAAM,iCAAiC,CAAA;AAE7E,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qCAAqC,CAAA;AAClF,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAA;AAE5C,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,CAAA;AAC9D,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,WAAW,EAAE,CAAA;AAC5D,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,CAAA","sourcesContent":["/**\n * ## Offline Service\n *\n * Helper functions for offline handling\n *\n * ```js\n * import { offlineService } from '@oneblink/apps-react'\n * ```\n */\nexport * as offlineService from './offline-service'\n/**\n * ## Authentication/Authorisation Service\n *\n * Helper functions for handling user authentication and authorisation.\n *\n * **NOTE: `init()` must be called before using some of the functions in this\n * service.**\n *\n * ```js\n * import { authService } from '@oneblink/apps-react'\n * ```\n */\nexport * as authService from './auth-service'\n/**\n * ## Draft Service\n *\n * Helper functions for handling drafts.\n *\n * ```js\n * import { draftService } from '@oneblink/apps-react'\n * ```\n */\nexport * as draftService from './draft-service'\n/**\n * ## Prefill Service\n *\n * Helper functions for offline handling\n *\n * ```js\n * import { prefillService } from '@oneblink/apps-react'\n * ```\n */\nexport * as prefillService from './prefill-service'\n/**\n * ## Payment Service\n *\n * Helper functions for payment handling\n *\n * ```js\n * import { paymentService } from '@oneblink/apps-react'\n * ```\n */\nexport * as paymentService from './payment-service'\n/**\n * ## Scheduling Service\n *\n * Helper functions for scheduling booking handling\n *\n * ```js\n * import { schedulingService } from '@oneblink/apps-react'\n * ```\n */\nexport * as schedulingService from './scheduling-service'\n/**\n * ## Job Service\n *\n * Helper functions for job handling\n *\n * ```js\n * import { jobService } from '@oneblink/apps-react'\n * ```\n */\nexport * as jobService from './job-service'\n/**\n * ## Submission Service\n *\n * Helper functions for handling form submissions\n *\n * ```js\n * import { submissionService } from '@oneblink/apps-react'\n * ```\n */\nexport * as submissionService from './submission-service'\n/**\n * ## Auto Save Service\n *\n * Helper functions for handling data while user is completing form.\n *\n * ```js\n * import { autoSaveService } from '@oneblink/apps-react'\n * ```\n */\nexport * as autoSaveService from './auto-save-service'\n/**\n * ## Notification Service\n *\n * Helper functions for notification handling\n *\n * ```js\n * import { notificationService } from '@oneblink/apps-react'\n * ```\n *\n * ### Service Worker\n *\n * To display push notifications and allow them to be clicked to open the\n * application, add the following JavaScript to your service worker (we\n * recommend using\n * [offline-plugin](https://www.npmjs.com/package/offline-plugin)):\n *\n * #### Example\n *\n * ```js\n * self.addEventListener('push', (event) => {\n * console.log('push event', event)\n *\n * if (!event.data) {\n * console.log('Received push event without any data', event)\n * return\n * }\n * const notification = event.data.json()\n *\n * event.waitUntil(\n * clients.matchAll().then((c) => {\n * if (c.length === 0 || c.every((client) => !client.focused)) {\n * // Show notification\n * return self.registration.showNotification(\n * notification.title,\n * notification.options,\n * )\n * } else {\n * console.log('Application is already open!')\n * }\n * }),\n * )\n * })\n *\n * self.addEventListener('notificationclick', (event) => {\n * console.log('notification click event', event)\n *\n * const pathname =\n * event.notification.data && event.notification.data.pathname\n * ? event.notification.data.pathname\n * : '/'\n *\n * event.waitUntil(\n * clients.matchAll().then((clis) => {\n * const client = clis[0]\n * if (client === undefined) {\n * // there are no visible windows. Open one.\n * clients.openWindow(pathname)\n * } else {\n * client.navigate(pathname)\n * client.focus()\n * }\n *\n * return self.registration\n * .getNotifications()\n * .then((notifications) => {\n * notifications.forEach((notification) => {\n * notification.close()\n * })\n * })\n * }),\n * )\n * })\n * ```\n */\nexport * as notificationService from './notification-service'\n/**\n * ## Form Service\n *\n * Helper functions for form handling\n *\n * ```js\n * import { formService } from '@oneblink/apps-react'\n * ```\n */\nexport * as formService from './form-service'\n/**\n * ## Approvals Service\n *\n * Helper functions for handling approvals\n *\n * ```js\n * import { approvalsService } from '@oneblink/apps-react'\n * ```\n */\nexport * as approvalsService from './approvals-service'\n/**\n * ## Forms App Service\n *\n * Helper functions for forms apps\n *\n * ```js\n * import { formsAppService } from '@oneblink/apps-react'\n * ```\n */\nexport * as formsAppService from './forms-app-service'\n/**\n * ## Form Store Service\n *\n * Helper functions for handling Form Store Records\n *\n * ```js\n * import { formStoreService } from '@oneblink/apps-react'\n * ```\n */\nexport * as formStoreService from './form-store-service'\n/**\n * ## Localisation Service\n *\n * Helper functions for handling all things locale.\n *\n * ```js\n * import { localisationService } from '@oneblink/apps-react'\n * ```\n */\nexport * as localisationService from './localisation-service'\n/**\n * ## Attachments Service\n *\n * Helper functions for attachment handling\n *\n * ```js\n * import { attachmentsService } from '@oneblink/apps-react'\n * ```\n */\nexport * as attachmentsService from './attachments-service'\n/**\n * ## Scheduled Tasks Service\n *\n * Helper functions for scheduled tasks\n *\n * ```js\n * import { scheduledTasksService } from '@oneblink/apps-react'\n * ```\n */\nexport * as scheduledTasksService from './scheduled-tasks-service'\n/**\n * ## Forms App Environment Service\n *\n * Helper functions for forms app environments\n *\n * ```js\n * import { formsAppEnvironmentService } from '@oneblink/apps-react'\n * ```\n */\nexport * as formsAppEnvironmentService from './forms-app-environment-service'\n\nexport { default as OneBlinkAppsError } from './services/errors/oneBlinkAppsError'\nimport tenants from './tenants'\nexport { default as Sentry } from './Sentry'\n\nexport const useTenantCivicPlus = () => tenants.useCivicPlus()\nexport const useTenantOneBlink = () => tenants.useOneBlink()\nexport const useTenantOneBlinkUS = () => tenants.useOneBlinkUS()\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/apps/index.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AAO,KAAK,qBAAqB,MAAM,2BAA2B,CAAA;AAClE;;;;;;;;GAQG;AACH,OAAO,KAAK,0BAA0B,MAAM,iCAAiC,CAAA;AAE7E,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qCAAqC,CAAA;AAClF,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAA;AAE5C,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,CAAA;AAC9D,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,WAAW,EAAE,CAAA;AAC5D,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,CAAA","sourcesContent":["/**\n * ## Offline Service\n *\n * Helper functions for offline handling\n *\n * ```js\n * import { offlineService } from '@oneblink/apps-react'\n * ```\n */\nexport * as offlineService from './offline-service'\n/**\n * ## Authentication/Authorisation Service\n *\n * Helper functions for handling user authentication and authorisation.\n *\n * **NOTE: `init()` must be called before using some of the functions in this\n * service.**\n *\n * ```js\n * import { authService } from '@oneblink/apps-react'\n * ```\n */\nexport * as authService from './auth-service'\n/**\n * ## MFA Service\n *\n * Helper functions for multi factor authentication and MFA requirements.\n *\n * ```js\n * import { mfaService } from '@oneblink/apps-react'\n * ```\n */\nexport * as mfaService from './mfa-service'\n/**\n * ## Draft Service\n *\n * Helper functions for handling drafts.\n *\n * ```js\n * import { draftService } from '@oneblink/apps-react'\n * ```\n */\nexport * as draftService from './draft-service'\n/**\n * ## Prefill Service\n *\n * Helper functions for offline handling\n *\n * ```js\n * import { prefillService } from '@oneblink/apps-react'\n * ```\n */\nexport * as prefillService from './prefill-service'\n/**\n * ## Payment Service\n *\n * Helper functions for payment handling\n *\n * ```js\n * import { paymentService } from '@oneblink/apps-react'\n * ```\n */\nexport * as paymentService from './payment-service'\n/**\n * ## Scheduling Service\n *\n * Helper functions for scheduling booking handling\n *\n * ```js\n * import { schedulingService } from '@oneblink/apps-react'\n * ```\n */\nexport * as schedulingService from './scheduling-service'\n/**\n * ## Job Service\n *\n * Helper functions for job handling\n *\n * ```js\n * import { jobService } from '@oneblink/apps-react'\n * ```\n */\nexport * as jobService from './job-service'\n/**\n * ## Submission Service\n *\n * Helper functions for handling form submissions\n *\n * ```js\n * import { submissionService } from '@oneblink/apps-react'\n * ```\n */\nexport * as submissionService from './submission-service'\n/**\n * ## Auto Save Service\n *\n * Helper functions for handling data while user is completing form.\n *\n * ```js\n * import { autoSaveService } from '@oneblink/apps-react'\n * ```\n */\nexport * as autoSaveService from './auto-save-service'\n/**\n * ## Notification Service\n *\n * Helper functions for notification handling\n *\n * ```js\n * import { notificationService } from '@oneblink/apps-react'\n * ```\n *\n * ### Service Worker\n *\n * To display push notifications and allow them to be clicked to open the\n * application, add the following JavaScript to your service worker (we\n * recommend using\n * [offline-plugin](https://www.npmjs.com/package/offline-plugin)):\n *\n * #### Example\n *\n * ```js\n * self.addEventListener('push', (event) => {\n * console.log('push event', event)\n *\n * if (!event.data) {\n * console.log('Received push event without any data', event)\n * return\n * }\n * const notification = event.data.json()\n *\n * event.waitUntil(\n * clients.matchAll().then((c) => {\n * if (c.length === 0 || c.every((client) => !client.focused)) {\n * // Show notification\n * return self.registration.showNotification(\n * notification.title,\n * notification.options,\n * )\n * } else {\n * console.log('Application is already open!')\n * }\n * }),\n * )\n * })\n *\n * self.addEventListener('notificationclick', (event) => {\n * console.log('notification click event', event)\n *\n * const pathname =\n * event.notification.data && event.notification.data.pathname\n * ? event.notification.data.pathname\n * : '/'\n *\n * event.waitUntil(\n * clients.matchAll().then((clis) => {\n * const client = clis[0]\n * if (client === undefined) {\n * // there are no visible windows. Open one.\n * clients.openWindow(pathname)\n * } else {\n * client.navigate(pathname)\n * client.focus()\n * }\n *\n * return self.registration\n * .getNotifications()\n * .then((notifications) => {\n * notifications.forEach((notification) => {\n * notification.close()\n * })\n * })\n * }),\n * )\n * })\n * ```\n */\nexport * as notificationService from './notification-service'\n/**\n * ## Form Service\n *\n * Helper functions for form handling\n *\n * ```js\n * import { formService } from '@oneblink/apps-react'\n * ```\n */\nexport * as formService from './form-service'\n/**\n * ## Approvals Service\n *\n * Helper functions for handling approvals\n *\n * ```js\n * import { approvalsService } from '@oneblink/apps-react'\n * ```\n */\nexport * as approvalsService from './approvals-service'\n/**\n * ## Forms App Service\n *\n * Helper functions for forms apps\n *\n * ```js\n * import { formsAppService } from '@oneblink/apps-react'\n * ```\n */\nexport * as formsAppService from './forms-app-service'\n/**\n * ## Form Store Service\n *\n * Helper functions for handling Form Store Records\n *\n * ```js\n * import { formStoreService } from '@oneblink/apps-react'\n * ```\n */\nexport * as formStoreService from './form-store-service'\n/**\n * ## Localisation Service\n *\n * Helper functions for handling all things locale.\n *\n * ```js\n * import { localisationService } from '@oneblink/apps-react'\n * ```\n */\nexport * as localisationService from './localisation-service'\n/**\n * ## Attachments Service\n *\n * Helper functions for attachment handling\n *\n * ```js\n * import { attachmentsService } from '@oneblink/apps-react'\n * ```\n */\nexport * as attachmentsService from './attachments-service'\n/**\n * ## Scheduled Tasks Service\n *\n * Helper functions for scheduled tasks\n *\n * ```js\n * import { scheduledTasksService } from '@oneblink/apps-react'\n * ```\n */\nexport * as scheduledTasksService from './scheduled-tasks-service'\n/**\n * ## Forms App Environment Service\n *\n * Helper functions for forms app environments\n *\n * ```js\n * import { formsAppEnvironmentService } from '@oneblink/apps-react'\n * ```\n */\nexport * as formsAppEnvironmentService from './forms-app-environment-service'\n\nexport { default as OneBlinkAppsError } from './services/errors/oneBlinkAppsError'\nimport tenants from './tenants'\nexport { default as Sentry } from './Sentry'\n\nexport const useTenantCivicPlus = () => tenants.useCivicPlus()\nexport const useTenantOneBlink = () => tenants.useOneBlink()\nexport const useTenantOneBlinkUS = () => tenants.useOneBlinkUS()\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { checkIsMfaEnabled, getMfaSettings, updateUserPhoneNumber, removeUserPhoneNumber, sendPhoneNumberVerificationCode, verifyUserPhoneNumber, disableMfaMethod, setPreferredMfaMethod, setupMfaAuthenticatorApp, setupSmsMfa, generateMfaAuthenticatorAppQrCodeUrl, DEFAULT_MFA_SETTINGS, } from './services/cognito';
|
|
2
|
+
export type { MfaMethod, MfaRequirementCheckResult, MfaSettings, } from './services/cognito';
|
|
3
|
+
export { isMfaRequired, mfaRequirementToSelectedMethods, mfaSelectedMethodsToMfaRequirement, formatMfaRequirementLabel, formatMfaRequirementMethodLabel, userMeetsMfaRequirement, formatMfaSetupRequiredMessage, formatMfaMethodNotAcceptedMessage, } from '../utils/mfa-requirement';
|
|
4
|
+
export type { MfaRequirementMethod } from '../utils/mfa-requirement';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { checkIsMfaEnabled, getMfaSettings, updateUserPhoneNumber, removeUserPhoneNumber, sendPhoneNumberVerificationCode, verifyUserPhoneNumber, disableMfaMethod, setPreferredMfaMethod, setupMfaAuthenticatorApp, setupSmsMfa, generateMfaAuthenticatorAppQrCodeUrl, DEFAULT_MFA_SETTINGS, } from './services/cognito';
|
|
2
|
+
export { isMfaRequired, mfaRequirementToSelectedMethods, mfaSelectedMethodsToMfaRequirement, formatMfaRequirementLabel, formatMfaRequirementMethodLabel, userMeetsMfaRequirement, formatMfaSetupRequiredMessage, formatMfaMethodNotAcceptedMessage, } from '../utils/mfa-requirement';
|
|
3
|
+
//# sourceMappingURL=mfa-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mfa-service.js","sourceRoot":"","sources":["../../src/apps/mfa-service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,+BAA+B,EAC/B,qBAAqB,EACrB,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,EACxB,WAAW,EACX,oCAAoC,EACpC,oBAAoB,GACrB,MAAM,oBAAoB,CAAA;AAM3B,OAAO,EACL,aAAa,EACb,+BAA+B,EAC/B,kCAAkC,EAClC,yBAAyB,EACzB,+BAA+B,EAC/B,uBAAuB,EACvB,6BAA6B,EAC7B,iCAAiC,GAClC,MAAM,0BAA0B,CAAA","sourcesContent":["export {\r\n checkIsMfaEnabled,\r\n getMfaSettings,\r\n updateUserPhoneNumber,\r\n removeUserPhoneNumber,\r\n sendPhoneNumberVerificationCode,\r\n verifyUserPhoneNumber,\r\n disableMfaMethod,\r\n setPreferredMfaMethod,\r\n setupMfaAuthenticatorApp,\r\n setupSmsMfa,\r\n generateMfaAuthenticatorAppQrCodeUrl,\r\n DEFAULT_MFA_SETTINGS,\r\n} from './services/cognito'\r\nexport type {\r\n MfaMethod,\r\n MfaRequirementCheckResult,\r\n MfaSettings,\r\n} from './services/cognito'\r\nexport {\r\n isMfaRequired,\r\n mfaRequirementToSelectedMethods,\r\n mfaSelectedMethodsToMfaRequirement,\r\n formatMfaRequirementLabel,\r\n formatMfaRequirementMethodLabel,\r\n userMeetsMfaRequirement,\r\n formatMfaSetupRequiredMessage,\r\n formatMfaMethodNotAcceptedMessage,\r\n} from '../utils/mfa-requirement'\r\nexport type { MfaRequirementMethod } from '../utils/mfa-requirement'\r\n"]}
|
|
@@ -243,7 +243,7 @@ declare function getUserFriendlyName(): string | undefined;
|
|
|
243
243
|
*
|
|
244
244
|
* ```js
|
|
245
245
|
* const mfaAuthenticatorAppSetupQrCodeUrl =
|
|
246
|
-
*
|
|
246
|
+
* mfaService.generateMfaAuthenticatorAppQrCodeUrl()
|
|
247
247
|
* if (mfaAuthenticatorAppSetupQrCodeUrl) {
|
|
248
248
|
* // use mfaAuthenticatorAppSetupQrCodeUrl to display QR code to user
|
|
249
249
|
* }
|
|
@@ -259,7 +259,7 @@ declare function generateMfaAuthenticatorAppQrCodeUrl(mfaAuthenticatorAppSetup:
|
|
|
259
259
|
*
|
|
260
260
|
* ```js
|
|
261
261
|
* const { mfaSettings, userMeetsMfaRequirement } =
|
|
262
|
-
* await
|
|
262
|
+
* await mfaService.checkIsMfaEnabled('any')
|
|
263
263
|
* if (userMeetsMfaRequirement) {
|
|
264
264
|
* // User has met the MFA requirement
|
|
265
265
|
* } else {
|
|
@@ -291,7 +291,7 @@ declare function setPreferredMfaMethod(method: MfaMethod): Promise<void>;
|
|
|
291
291
|
*
|
|
292
292
|
* ```js
|
|
293
293
|
* const { secretCode, mfaCodeCallback } =
|
|
294
|
-
* await
|
|
294
|
+
* await mfaService.setupMfaAuthenticatorApp()
|
|
295
295
|
* // Prompt the user to enter an MFA code
|
|
296
296
|
* const code = prompt(
|
|
297
297
|
* `Please enter a one-time code from your MFA app after creating a new entry with secret: ${secretCode}.`,
|
|
@@ -363,7 +363,7 @@ function getUserFriendlyName() {
|
|
|
363
363
|
*
|
|
364
364
|
* ```js
|
|
365
365
|
* const mfaAuthenticatorAppSetupQrCodeUrl =
|
|
366
|
-
*
|
|
366
|
+
* mfaService.generateMfaAuthenticatorAppQrCodeUrl()
|
|
367
367
|
* if (mfaAuthenticatorAppSetupQrCodeUrl) {
|
|
368
368
|
* // use mfaAuthenticatorAppSetupQrCodeUrl to display QR code to user
|
|
369
369
|
* }
|
|
@@ -385,7 +385,7 @@ function generateMfaAuthenticatorAppQrCodeUrl(mfaAuthenticatorAppSetup) {
|
|
|
385
385
|
*
|
|
386
386
|
* ```js
|
|
387
387
|
* const { mfaSettings, userMeetsMfaRequirement } =
|
|
388
|
-
* await
|
|
388
|
+
* await mfaService.checkIsMfaEnabled('any')
|
|
389
389
|
* if (userMeetsMfaRequirement) {
|
|
390
390
|
* // User has met the MFA requirement
|
|
391
391
|
* } else {
|
|
@@ -458,7 +458,7 @@ async function setPreferredMfaMethod(method) {
|
|
|
458
458
|
*
|
|
459
459
|
* ```js
|
|
460
460
|
* const { secretCode, mfaCodeCallback } =
|
|
461
|
-
* await
|
|
461
|
+
* await mfaService.setupMfaAuthenticatorApp()
|
|
462
462
|
* // Prompt the user to enter an MFA code
|
|
463
463
|
* const code = prompt(
|
|
464
464
|
* `Please enter a one-time code from your MFA app after creating a new entry with secret: ${secretCode}.`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cognito.js","sourceRoot":"","sources":["../../../src/apps/services/cognito.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC,OAAO,gBAAgB,EAAE,EACvB,oBAAoB,GAKrB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,cAAc,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,EAAa,WAAW,EAAE,MAAM,SAAS,CAAA;AAChD,OAAO,OAAO,MAAM,YAAY,CAAA;AAChC,OAAO,iBAAiB,MAAM,4BAA4B,CAAA;AAU1D,MAAM,WAAW,GAAG,YAAY,CAAA;AAEhC,IAAI,gBAAgB,GAA4B,IAAI,CAAA;AAEpD,SAAS,IAAI,CAAC,kBAAsC;IAClD,OAAO,CAAC,GAAG,CAAC,2CAA2C,EAAE,kBAAkB,CAAC,CAAA;IAE5E,gBAAgB,GAAG,IAAI,gBAAgB,CAAC;QACtC,QAAQ,EAAE,kBAAkB,CAAC,aAAa;QAC1C,MAAM,EAAE,kBAAkB,CAAC,MAAM;QACjC,WAAW,EAAE,kBAAkB,CAAC,WAAW;QAC3C,WAAW,EAAE,kBAAkB,CAAC,WAAW;QAC3C,SAAS,EAAE,kBAAkB,CAAC,SAAS;KACxC,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAS,oBAAoB,CAAC,QAAuB;IACnD,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,mHAAmH,CACpH,CAAA;IACH,CAAC;IACD,OAAO,gBAAgB,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAA;AACpD,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CAAC,MAAiB;IACpD,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,4HAA4H,CAC7H,CAAA;IACH,CAAC;IAED,OAAO,MAAM,gBAAgB,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAA;AAC7D,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,KAAK,UAAU,wBAAwB,CAAC,OAAiC;IACvE,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,2HAA2H,CAC5H,CAAA;IACH,CAAC;IAED,OAAO,MAAM,gBAAgB,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAA;AACjE,CAAC;AAED,OAAO,EACL,IAAI,EACJ,oBAAoB,EACpB,qBAAqB,EACrB,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,cAAc,EACd,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,+BAA+B,EAC/B,qBAAqB,EACrB,gBAAgB,EAChB,qBAAqB,EACrB,WAAW,EACX,wBAAwB,EACxB,oCAAoC,EACpC,oBAAoB,GACrB,CAAA","sourcesContent":["import { jwtDecode } from 'jwt-decode'\n\nimport AWSCognitoClient, {\n DEFAULT_MFA_SETTINGS,\n LoginAttemptResponse,\n MfaMethod,\n MfaRequirementCheckResult,\n MfaSettings,\n} from './AWSCognitoClient'\n\nimport * as offlineService from '../offline-service'\nimport { userService } from '@oneblink/sdk-core'\nimport { MiscTypes } from '@oneblink/types'\nimport { HTTPError, postRequest } from './fetch'\nimport tenants from '../tenants'\nimport OneBlinkAppsError from './errors/oneBlinkAppsError'\n\ninterface CognitoServiceData {\n oAuthClientId: string\n loginDomain: string\n region: string\n redirectUri: string\n logoutUri: string\n}\n\nconst CONTINUE_TO = 'continueTo'\n\nlet awsCognitoClient: null | AWSCognitoClient = null\n\nfunction init(cognitoServiceData: CognitoServiceData) {\n console.log('Initiating CognitoIdentityServiceProvider', cognitoServiceData)\n\n awsCognitoClient = new AWSCognitoClient({\n clientId: cognitoServiceData.oAuthClientId,\n region: cognitoServiceData.region,\n loginDomain: cognitoServiceData.loginDomain,\n redirectUri: cognitoServiceData.redirectUri,\n logoutUri: cognitoServiceData.logoutUri,\n })\n}\n\n/**\n * Register a listener function that will be call when authentication tokens are\n * updated or removed.\n *\n * #### Example\n *\n * ```js\n * const listener = async () => {\n * // Check if the user is logged in still\n * const isLoggedIn = authService.isLoggedIn()\n * }\n * const deregister = await authService.registerAuthListener(listener)\n *\n * // When no longer needed, remember to deregister the listener\n * deregister()\n * ```\n *\n * @param listener\n * @returns\n */\nfunction registerAuthListener(listener: () => unknown): () => void {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to register a listener.',\n )\n }\n return awsCognitoClient.registerListener(listener)\n}\n\n/**\n * Create a session for a user by entering a username and password. If the user\n * requires a password reset, the \"resetPasswordCallback\" property will be\n * returned. This function should be called with the new password once entered\n * by the user. If the user requires an MFA token, the \"mfa\" property will be\n * returned. Its \"codeCallback\" should be called with the one-time token. The\n * functions returned are recursive and the result from each of them is the same\n * result from the loginUsernamePassword() function. Each time the response\n * includes a callback, you will need to begin the process again until all\n * callbacks are handled.\n *\n * #### Example\n *\n * ```js\n * async function handleLoginAttemptResponse({\n * resetPasswordCallback,\n * mfa,\n * }) {\n * // \"resetPasswordCallback\" will be undefined if a password reset was not required.\n * if (resetPasswordCallback) {\n * // Prompt the user to enter a new password\n * const newPassword = prompt(\n * 'The password you entered was only temporary, and must be reset for security purposes. Please enter your new password below to continue.',\n * )\n * const resetPasswordResponse =\n * await resetPasswordCallback(newPassword)\n * return await handleLoginAttemptResponse(resetPasswordResponse)\n * }\n *\n * // \"mfa\" will be undefined if MFA is not setup.\n * if (mfa) {\n * // Prompt the user to enter an MFA code\n * const code = prompt(\n * mfa.method === 'email'\n * ? 'Please enter the one-time code sent to your email.'\n * : 'Please enter a one-time code from your MFA app.',\n * )\n * const mfaCodeResponse = await mfa.codeCallback(code)\n * return await handleLoginAttemptResponse(mfaCodeResponse)\n * }\n * }\n *\n * const username = 'user@email.io'\n * const password = 'P@$5w0rd'\n *\n * const loginAttemptResponse = await authService.loginUsernamePassword(\n * username,\n * password,\n * )\n *\n * await handleLoginAttemptResponse(loginAttemptResponse)\n * ```\n *\n * @param username\n * @param password\n * @returns\n */\nasync function loginUsernamePassword(username: string, password: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to login.',\n )\n }\n console.log('Attempting sign using username', username)\n return awsCognitoClient.loginUsernamePassword(\n username.toLowerCase(),\n password,\n )\n}\n\n/**\n * Redirect the user to the login screen. Passing an `identityProvider` is\n * optionally, it will allow users to skip the login page and be directed\n * straight to that providers login page\n *\n * #### Example\n *\n * ```js\n * // OPtionally pass a\n * const identityProvider = 'Google'\n * await authService.loginHostedUI(identityProvider)\n * // User will be redirected to login page or promise will resolve\n * ```\n *\n * @param identityProviderName\n * @returns\n */\nasync function loginHostedUI(identityProviderName?: string): Promise<void> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to login.',\n )\n }\n const continueTo = `${window.location.pathname}${window.location.search}`\n localStorage.setItem(CONTINUE_TO, continueTo)\n\n return awsCognitoClient.loginHostedUI(identityProviderName)\n}\n\n/**\n * This function should be called when the user is redirected back to your app\n * after a login attempt. It will use the query string add the redirect URL to\n * create a session for the current user. It will return a URL as a `string`\n * that should be redirected to within your app.\n *\n * #### Example\n *\n * ```js\n * try {\n * const continueTo = await authService.handleAuthentication()\n * // Redirect the user back to where they were before attempting to login\n * window.location.href = continueTo\n * } catch (error) {\n * // handle failed login attempts here.\n * }\n * ```\n *\n * @returns\n */\nasync function handleAuthentication(): Promise<string> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to handle authentication in URL.',\n )\n }\n\n const continueTo = localStorage.getItem(CONTINUE_TO) || '/'\n if (isLoggedIn()) {\n console.log('Already authenticated, redirecting to:', continueTo)\n } else {\n await awsCognitoClient.handleAuthentication()\n }\n\n localStorage.removeItem(CONTINUE_TO)\n\n return continueTo\n}\n\n/**\n * Allow the currently logged in user to change their password by passing their\n * existing password and a new password.\n *\n * #### Example\n *\n * ```js\n * const currentPassword = 'P@$5w0rd'\n * const newPassword = 'P@$5w0rD'\n * await authService.changePassword(currentPassword, newPassword)\n * ```\n *\n * @param existingPassword\n * @param newPassword\n * @returns\n */\nasync function changePassword(existingPassword: string, newPassword: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to change passwords.',\n )\n }\n\n return await awsCognitoClient.changePassword(existingPassword, newPassword)\n}\n\n/**\n * Allow a user to start the forgot password process. The user will be emailed a\n * temporary code that must be passed with a new password to the function\n * returned.\n *\n * #### Example\n *\n * ```js\n * const username = 'user@email.io'\n * const finishForgotPassword = await authService.forgotPassword(username)\n *\n * // Prompt the user to enter the code and a new password\n * const code = prompt(\n * 'You have been emailed a verification code, please enter it here.',\n * )\n * const newPassword = prompt('Please enter a new password to continue.')\n * await finishForgotPassword(code, newPassword)\n * ```\n *\n * @param username\n * @param formsAppId Used to give the resulting email sent to the user\n * associated forms app branding and sending address\n * @returns\n */\nasync function forgotPassword(\n username: string,\n /**\n * Used to give the resulting email sent to the user associated forms app\n * branding and sending address\n */\n formsAppId?: number,\n): Promise<(code: string, password: string) => Promise<void>> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before starting the forgot password process.',\n )\n }\n\n try {\n const url = `${tenants.current.apiOrigin}/authentication/reset-password`\n await postRequest(url, {\n username,\n formsAppId,\n })\n } catch (err) {\n const error = err as HTTPError\n switch (error.status) {\n case 400: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n\n return async (code, password) => {\n await awsCognitoClient?.confirmForgotPassword({\n username,\n code,\n password,\n })\n }\n}\n\n/**\n * Redirect the user to the logout screen to clear the users session on the\n * hosted login page. User will then be redirected to `/logout`. After being\n * redirected back to the application, the `logout()` function should be called\n * to clear the session data from browser storage.\n *\n * #### Example\n *\n * ```js\n * authService.logoutHostedUI()\n * ```\n */\nfunction logoutHostedUI(): void {\n if (awsCognitoClient) {\n awsCognitoClient.logoutHostedUI()\n }\n}\n\nasync function logout() {\n if (awsCognitoClient) {\n await awsCognitoClient.logout()\n }\n}\n\n/**\n * Check if the user is currently logged in\n *\n * #### Example\n *\n * ```js\n * const isLoggedIn = authService.isLoggedIn()\n * // handle user being logged in or not\n * ```\n *\n * @returns\n */\nfunction isLoggedIn(): boolean {\n return !!(awsCognitoClient && awsCognitoClient._getRefreshToken())\n}\n\nasync function getCognitoIdToken(): Promise<string | undefined> {\n if (!awsCognitoClient) {\n return\n }\n\n if (offlineService.isOffline()) {\n return awsCognitoClient._getIdToken()\n }\n\n return await awsCognitoClient.getIdToken()\n}\n\n/**\n * Get current users profile based on there Id Token payload. This will return\n * `null` if the the current user is not logged in.\n *\n * #### Example\n *\n * ```js\n * const profile = authService.getUserProfile()\n * if (profile) {\n * // Use profile here\n * }\n * ```\n *\n * @returns\n */\nfunction getUserProfile(): MiscTypes.UserProfile | null {\n if (!awsCognitoClient) {\n return null\n }\n const idToken = awsCognitoClient._getIdToken()\n if (!idToken) {\n return null\n }\n\n const jwtToken = jwtDecode(idToken)\n return userService.parseUserProfile(jwtToken) || null\n}\n\nexport function getUsername(): string | undefined {\n const profile = getUserProfile()\n if (!profile) {\n return undefined\n }\n\n return profile.username\n}\n\n/**\n * A friendly `string` that represents the current user. Uses first name, last\n * name, full name and username. This will return `null` the current user is not\n * logged in.\n *\n * #### Example\n *\n * ```js\n * const name = authService.getUserFriendlyName()\n * if (name) {\n * // Display current user's name\n * }\n * ```\n *\n * @returns\n */\nfunction getUserFriendlyName(): string | undefined {\n const profile = getUserProfile()\n if (!profile) {\n return\n }\n\n return userService.getUserFriendlyName(profile)\n}\n\n/**\n * Generate a QR code link to display to a user after they have initiated\n * authenticator app MFA setup.\n *\n * #### Example\n *\n * ```js\n * const mfaAuthenticatorAppSetupQrCodeUrl =\n * authService.generateMfaAuthenticatorAppQrCodeUrl()\n * if (mfaAuthenticatorAppSetupQrCodeUrl) {\n * // use mfaAuthenticatorAppSetupQrCodeUrl to display QR code to user\n * }\n * ```\n *\n * @returns\n */\nfunction generateMfaAuthenticatorAppQrCodeUrl(\n mfaAuthenticatorAppSetup: Awaited<\n ReturnType<typeof setupMfaAuthenticatorApp>\n >,\n): string | undefined {\n const profile = getUserProfile()\n if (!profile || !mfaAuthenticatorAppSetup) {\n return\n }\n\n return `otpauth://totp/${tenants.current.productShortName}:${profile.email}?secret=${mfaAuthenticatorAppSetup.secretCode}&issuer=${tenants.current.productShortName}`\n}\n\n/**\n * Check if the current user meets an MFA requirement.\n *\n * #### Example\n *\n * ```js\n * const { mfaSettings, userMeetsMfaRequirement } =\n * await authService.checkIsMfaEnabled('any')\n * if (userMeetsMfaRequirement) {\n * // User has met the MFA requirement\n * } else {\n * // Prompt user to set up MFA\n * }\n * ```\n *\n * @returns\n */\nasync function checkIsMfaEnabled(\n mfaRequirement: MiscTypes.MfaRequirement | undefined,\n): Promise<MfaRequirementCheckResult> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before checking if the current user has MFA enabled.',\n )\n }\n\n return await awsCognitoClient.checkIsMfaEnabled(mfaRequirement)\n}\n\nasync function getMfaSettings(abortSignal?: AbortSignal) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before checking MFA settings.',\n )\n }\n\n return await awsCognitoClient.getMfaSettings(abortSignal)\n}\n\nasync function updateUserPhoneNumber(phoneNumber: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before updating the user phone number.',\n )\n }\n\n return await awsCognitoClient.updateUserPhoneNumber(phoneNumber)\n}\n\nasync function removeUserPhoneNumber() {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before removing the user phone number.',\n )\n }\n\n return await awsCognitoClient.removeUserPhoneNumber()\n}\n\nasync function sendPhoneNumberVerificationCode() {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before sending a phone number verification code.',\n )\n }\n\n return await awsCognitoClient.sendPhoneNumberVerificationCode()\n}\n\nasync function verifyUserPhoneNumber(code: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before verifying the user phone number.',\n )\n }\n\n return await awsCognitoClient.verifyUserPhoneNumber(code)\n}\n\nasync function setupSmsMfa(options?: { preferred?: boolean }) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to setup SMS MFA.',\n )\n }\n\n return await awsCognitoClient.setupSmsMfa(options)\n}\n\nasync function disableMfaMethod(method: MfaMethod) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to disable an MFA method.',\n )\n }\n\n return await awsCognitoClient.disableMfaMethod(method)\n}\n\nasync function setPreferredMfaMethod(method: MfaMethod) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to set the preferred MFA method.',\n )\n }\n\n return await awsCognitoClient.setPreferredMfaMethod(method)\n}\n\n/**\n * Setup authenticator app MFA for the current user. The result will include a\n * callback that should be called with the valid TOTP from an authenticator\n * app.\n *\n * #### Example\n *\n * ```js\n * const { secretCode, mfaCodeCallback } =\n * await authService.setupMfaAuthenticatorApp()\n * // Prompt the user to enter an MFA code\n * const code = prompt(\n * `Please enter a one-time code from your MFA app after creating a new entry with secret: ${secretCode}.`,\n * )\n * await mfaCodeCallback(code)\n * ```\n *\n * @returns\n */\nasync function setupMfaAuthenticatorApp(options?: { preferred?: boolean }) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to setup authenticator app MFA.',\n )\n }\n\n return await awsCognitoClient.setupMfaAuthenticatorApp(options)\n}\n\nexport {\n init,\n registerAuthListener,\n loginUsernamePassword,\n loginHostedUI,\n handleAuthentication,\n changePassword,\n forgotPassword,\n logoutHostedUI,\n logout,\n isLoggedIn,\n getCognitoIdToken,\n getUserProfile,\n getUserFriendlyName,\n checkIsMfaEnabled,\n getMfaSettings,\n updateUserPhoneNumber,\n removeUserPhoneNumber,\n sendPhoneNumberVerificationCode,\n verifyUserPhoneNumber,\n disableMfaMethod,\n setPreferredMfaMethod,\n setupSmsMfa,\n setupMfaAuthenticatorApp,\n generateMfaAuthenticatorAppQrCodeUrl,\n DEFAULT_MFA_SETTINGS,\n}\nexport type {\n LoginAttemptResponse,\n MfaMethod,\n MfaRequirementCheckResult,\n MfaSettings,\n}\n"]}
|
|
1
|
+
{"version":3,"file":"cognito.js","sourceRoot":"","sources":["../../../src/apps/services/cognito.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC,OAAO,gBAAgB,EAAE,EACvB,oBAAoB,GAKrB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,cAAc,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,EAAa,WAAW,EAAE,MAAM,SAAS,CAAA;AAChD,OAAO,OAAO,MAAM,YAAY,CAAA;AAChC,OAAO,iBAAiB,MAAM,4BAA4B,CAAA;AAU1D,MAAM,WAAW,GAAG,YAAY,CAAA;AAEhC,IAAI,gBAAgB,GAA4B,IAAI,CAAA;AAEpD,SAAS,IAAI,CAAC,kBAAsC;IA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A+B,EAC/B,qBAAqB,EACrB,gBAAgB,EAChB,qBAAqB,EACrB,WAAW,EACX,wBAAwB,EACxB,oCAAoC,EACpC,oBAAoB,GACrB,CAAA","sourcesContent":["import { jwtDecode } from 'jwt-decode'\n\nimport AWSCognitoClient, {\n DEFAULT_MFA_SETTINGS,\n LoginAttemptResponse,\n MfaMethod,\n MfaRequirementCheckResult,\n MfaSettings,\n} from './AWSCognitoClient'\n\nimport * as offlineService from '../offline-service'\nimport { userService } from '@oneblink/sdk-core'\nimport { MiscTypes } from '@oneblink/types'\nimport { HTTPError, postRequest } from './fetch'\nimport tenants from '../tenants'\nimport OneBlinkAppsError from './errors/oneBlinkAppsError'\n\ninterface CognitoServiceData {\n oAuthClientId: string\n loginDomain: string\n region: string\n redirectUri: string\n logoutUri: string\n}\n\nconst CONTINUE_TO = 'continueTo'\n\nlet awsCognitoClient: null | AWSCognitoClient = null\n\nfunction init(cognitoServiceData: CognitoServiceData) {\n console.log('Initiating CognitoIdentityServiceProvider', cognitoServiceData)\n\n awsCognitoClient = new AWSCognitoClient({\n clientId: cognitoServiceData.oAuthClientId,\n region: cognitoServiceData.region,\n loginDomain: cognitoServiceData.loginDomain,\n redirectUri: cognitoServiceData.redirectUri,\n logoutUri: cognitoServiceData.logoutUri,\n })\n}\n\n/**\n * Register a listener function that will be call when authentication tokens are\n * updated or removed.\n *\n * #### Example\n *\n * ```js\n * const listener = async () => {\n * // Check if the user is logged in still\n * const isLoggedIn = authService.isLoggedIn()\n * }\n * const deregister = await authService.registerAuthListener(listener)\n *\n * // When no longer needed, remember to deregister the listener\n * deregister()\n * ```\n *\n * @param listener\n * @returns\n */\nfunction registerAuthListener(listener: () => unknown): () => void {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to register a listener.',\n )\n }\n return awsCognitoClient.registerListener(listener)\n}\n\n/**\n * Create a session for a user by entering a username and password. If the user\n * requires a password reset, the \"resetPasswordCallback\" property will be\n * returned. This function should be called with the new password once entered\n * by the user. If the user requires an MFA token, the \"mfa\" property will be\n * returned. Its \"codeCallback\" should be called with the one-time token. The\n * functions returned are recursive and the result from each of them is the same\n * result from the loginUsernamePassword() function. Each time the response\n * includes a callback, you will need to begin the process again until all\n * callbacks are handled.\n *\n * #### Example\n *\n * ```js\n * async function handleLoginAttemptResponse({\n * resetPasswordCallback,\n * mfa,\n * }) {\n * // \"resetPasswordCallback\" will be undefined if a password reset was not required.\n * if (resetPasswordCallback) {\n * // Prompt the user to enter a new password\n * const newPassword = prompt(\n * 'The password you entered was only temporary, and must be reset for security purposes. Please enter your new password below to continue.',\n * )\n * const resetPasswordResponse =\n * await resetPasswordCallback(newPassword)\n * return await handleLoginAttemptResponse(resetPasswordResponse)\n * }\n *\n * // \"mfa\" will be undefined if MFA is not setup.\n * if (mfa) {\n * // Prompt the user to enter an MFA code\n * const code = prompt(\n * mfa.method === 'email'\n * ? 'Please enter the one-time code sent to your email.'\n * : 'Please enter a one-time code from your MFA app.',\n * )\n * const mfaCodeResponse = await mfa.codeCallback(code)\n * return await handleLoginAttemptResponse(mfaCodeResponse)\n * }\n * }\n *\n * const username = 'user@email.io'\n * const password = 'P@$5w0rd'\n *\n * const loginAttemptResponse = await authService.loginUsernamePassword(\n * username,\n * password,\n * )\n *\n * await handleLoginAttemptResponse(loginAttemptResponse)\n * ```\n *\n * @param username\n * @param password\n * @returns\n */\nasync function loginUsernamePassword(username: string, password: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to login.',\n )\n }\n console.log('Attempting sign using username', username)\n return awsCognitoClient.loginUsernamePassword(\n username.toLowerCase(),\n password,\n )\n}\n\n/**\n * Redirect the user to the login screen. Passing an `identityProvider` is\n * optionally, it will allow users to skip the login page and be directed\n * straight to that providers login page\n *\n * #### Example\n *\n * ```js\n * // OPtionally pass a\n * const identityProvider = 'Google'\n * await authService.loginHostedUI(identityProvider)\n * // User will be redirected to login page or promise will resolve\n * ```\n *\n * @param identityProviderName\n * @returns\n */\nasync function loginHostedUI(identityProviderName?: string): Promise<void> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to login.',\n )\n }\n const continueTo = `${window.location.pathname}${window.location.search}`\n localStorage.setItem(CONTINUE_TO, continueTo)\n\n return awsCognitoClient.loginHostedUI(identityProviderName)\n}\n\n/**\n * This function should be called when the user is redirected back to your app\n * after a login attempt. It will use the query string add the redirect URL to\n * create a session for the current user. It will return a URL as a `string`\n * that should be redirected to within your app.\n *\n * #### Example\n *\n * ```js\n * try {\n * const continueTo = await authService.handleAuthentication()\n * // Redirect the user back to where they were before attempting to login\n * window.location.href = continueTo\n * } catch (error) {\n * // handle failed login attempts here.\n * }\n * ```\n *\n * @returns\n */\nasync function handleAuthentication(): Promise<string> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to handle authentication in URL.',\n )\n }\n\n const continueTo = localStorage.getItem(CONTINUE_TO) || '/'\n if (isLoggedIn()) {\n console.log('Already authenticated, redirecting to:', continueTo)\n } else {\n await awsCognitoClient.handleAuthentication()\n }\n\n localStorage.removeItem(CONTINUE_TO)\n\n return continueTo\n}\n\n/**\n * Allow the currently logged in user to change their password by passing their\n * existing password and a new password.\n *\n * #### Example\n *\n * ```js\n * const currentPassword = 'P@$5w0rd'\n * const newPassword = 'P@$5w0rD'\n * await authService.changePassword(currentPassword, newPassword)\n * ```\n *\n * @param existingPassword\n * @param newPassword\n * @returns\n */\nasync function changePassword(existingPassword: string, newPassword: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to change passwords.',\n )\n }\n\n return await awsCognitoClient.changePassword(existingPassword, newPassword)\n}\n\n/**\n * Allow a user to start the forgot password process. The user will be emailed a\n * temporary code that must be passed with a new password to the function\n * returned.\n *\n * #### Example\n *\n * ```js\n * const username = 'user@email.io'\n * const finishForgotPassword = await authService.forgotPassword(username)\n *\n * // Prompt the user to enter the code and a new password\n * const code = prompt(\n * 'You have been emailed a verification code, please enter it here.',\n * )\n * const newPassword = prompt('Please enter a new password to continue.')\n * await finishForgotPassword(code, newPassword)\n * ```\n *\n * @param username\n * @param formsAppId Used to give the resulting email sent to the user\n * associated forms app branding and sending address\n * @returns\n */\nasync function forgotPassword(\n username: string,\n /**\n * Used to give the resulting email sent to the user associated forms app\n * branding and sending address\n */\n formsAppId?: number,\n): Promise<(code: string, password: string) => Promise<void>> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before starting the forgot password process.',\n )\n }\n\n try {\n const url = `${tenants.current.apiOrigin}/authentication/reset-password`\n await postRequest(url, {\n username,\n formsAppId,\n })\n } catch (err) {\n const error = err as HTTPError\n switch (error.status) {\n case 400: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n\n return async (code, password) => {\n await awsCognitoClient?.confirmForgotPassword({\n username,\n code,\n password,\n })\n }\n}\n\n/**\n * Redirect the user to the logout screen to clear the users session on the\n * hosted login page. User will then be redirected to `/logout`. After being\n * redirected back to the application, the `logout()` function should be called\n * to clear the session data from browser storage.\n *\n * #### Example\n *\n * ```js\n * authService.logoutHostedUI()\n * ```\n */\nfunction logoutHostedUI(): void {\n if (awsCognitoClient) {\n awsCognitoClient.logoutHostedUI()\n }\n}\n\nasync function logout() {\n if (awsCognitoClient) {\n await awsCognitoClient.logout()\n }\n}\n\n/**\n * Check if the user is currently logged in\n *\n * #### Example\n *\n * ```js\n * const isLoggedIn = authService.isLoggedIn()\n * // handle user being logged in or not\n * ```\n *\n * @returns\n */\nfunction isLoggedIn(): boolean {\n return !!(awsCognitoClient && awsCognitoClient._getRefreshToken())\n}\n\nasync function getCognitoIdToken(): Promise<string | undefined> {\n if (!awsCognitoClient) {\n return\n }\n\n if (offlineService.isOffline()) {\n return awsCognitoClient._getIdToken()\n }\n\n return await awsCognitoClient.getIdToken()\n}\n\n/**\n * Get current users profile based on there Id Token payload. This will return\n * `null` if the the current user is not logged in.\n *\n * #### Example\n *\n * ```js\n * const profile = authService.getUserProfile()\n * if (profile) {\n * // Use profile here\n * }\n * ```\n *\n * @returns\n */\nfunction getUserProfile(): MiscTypes.UserProfile | null {\n if (!awsCognitoClient) {\n return null\n }\n const idToken = awsCognitoClient._getIdToken()\n if (!idToken) {\n return null\n }\n\n const jwtToken = jwtDecode(idToken)\n return userService.parseUserProfile(jwtToken) || null\n}\n\nexport function getUsername(): string | undefined {\n const profile = getUserProfile()\n if (!profile) {\n return undefined\n }\n\n return profile.username\n}\n\n/**\n * A friendly `string` that represents the current user. Uses first name, last\n * name, full name and username. This will return `null` the current user is not\n * logged in.\n *\n * #### Example\n *\n * ```js\n * const name = authService.getUserFriendlyName()\n * if (name) {\n * // Display current user's name\n * }\n * ```\n *\n * @returns\n */\nfunction getUserFriendlyName(): string | undefined {\n const profile = getUserProfile()\n if (!profile) {\n return\n }\n\n return userService.getUserFriendlyName(profile)\n}\n\n/**\n * Generate a QR code link to display to a user after they have initiated\n * authenticator app MFA setup.\n *\n * #### Example\n *\n * ```js\n * const mfaAuthenticatorAppSetupQrCodeUrl =\n * mfaService.generateMfaAuthenticatorAppQrCodeUrl()\n * if (mfaAuthenticatorAppSetupQrCodeUrl) {\n * // use mfaAuthenticatorAppSetupQrCodeUrl to display QR code to user\n * }\n * ```\n *\n * @returns\n */\nfunction generateMfaAuthenticatorAppQrCodeUrl(\n mfaAuthenticatorAppSetup: Awaited<\n ReturnType<typeof setupMfaAuthenticatorApp>\n >,\n): string | undefined {\n const profile = getUserProfile()\n if (!profile || !mfaAuthenticatorAppSetup) {\n return\n }\n\n return `otpauth://totp/${tenants.current.productShortName}:${profile.email}?secret=${mfaAuthenticatorAppSetup.secretCode}&issuer=${tenants.current.productShortName}`\n}\n\n/**\n * Check if the current user meets an MFA requirement.\n *\n * #### Example\n *\n * ```js\n * const { mfaSettings, userMeetsMfaRequirement } =\n * await mfaService.checkIsMfaEnabled('any')\n * if (userMeetsMfaRequirement) {\n * // User has met the MFA requirement\n * } else {\n * // Prompt user to set up MFA\n * }\n * ```\n *\n * @returns\n */\nasync function checkIsMfaEnabled(\n mfaRequirement: MiscTypes.MfaRequirement | undefined,\n): Promise<MfaRequirementCheckResult> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before checking if the current user has MFA enabled.',\n )\n }\n\n return await awsCognitoClient.checkIsMfaEnabled(mfaRequirement)\n}\n\nasync function getMfaSettings(abortSignal?: AbortSignal) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before checking MFA settings.',\n )\n }\n\n return await awsCognitoClient.getMfaSettings(abortSignal)\n}\n\nasync function updateUserPhoneNumber(phoneNumber: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before updating the user phone number.',\n )\n }\n\n return await awsCognitoClient.updateUserPhoneNumber(phoneNumber)\n}\n\nasync function removeUserPhoneNumber() {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before removing the user phone number.',\n )\n }\n\n return await awsCognitoClient.removeUserPhoneNumber()\n}\n\nasync function sendPhoneNumberVerificationCode() {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before sending a phone number verification code.',\n )\n }\n\n return await awsCognitoClient.sendPhoneNumberVerificationCode()\n}\n\nasync function verifyUserPhoneNumber(code: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before verifying the user phone number.',\n )\n }\n\n return await awsCognitoClient.verifyUserPhoneNumber(code)\n}\n\nasync function setupSmsMfa(options?: { preferred?: boolean }) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to setup SMS MFA.',\n )\n }\n\n return await awsCognitoClient.setupSmsMfa(options)\n}\n\nasync function disableMfaMethod(method: MfaMethod) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to disable an MFA method.',\n )\n }\n\n return await awsCognitoClient.disableMfaMethod(method)\n}\n\nasync function setPreferredMfaMethod(method: MfaMethod) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to set the preferred MFA method.',\n )\n }\n\n return await awsCognitoClient.setPreferredMfaMethod(method)\n}\n\n/**\n * Setup authenticator app MFA for the current user. The result will include a\n * callback that should be called with the valid TOTP from an authenticator\n * app.\n *\n * #### Example\n *\n * ```js\n * const { secretCode, mfaCodeCallback } =\n * await mfaService.setupMfaAuthenticatorApp()\n * // Prompt the user to enter an MFA code\n * const code = prompt(\n * `Please enter a one-time code from your MFA app after creating a new entry with secret: ${secretCode}.`,\n * )\n * await mfaCodeCallback(code)\n * ```\n *\n * @returns\n */\nasync function setupMfaAuthenticatorApp(options?: { preferred?: boolean }) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to setup authenticator app MFA.',\n )\n }\n\n return await awsCognitoClient.setupMfaAuthenticatorApp(options)\n}\n\nexport {\n init,\n registerAuthListener,\n loginUsernamePassword,\n loginHostedUI,\n handleAuthentication,\n changePassword,\n forgotPassword,\n logoutHostedUI,\n logout,\n isLoggedIn,\n getCognitoIdToken,\n getUserProfile,\n getUserFriendlyName,\n checkIsMfaEnabled,\n getMfaSettings,\n updateUserPhoneNumber,\n removeUserPhoneNumber,\n sendPhoneNumberVerificationCode,\n verifyUserPhoneNumber,\n disableMfaMethod,\n setPreferredMfaMethod,\n setupSmsMfa,\n setupMfaAuthenticatorApp,\n generateMfaAuthenticatorAppQrCodeUrl,\n DEFAULT_MFA_SETTINGS,\n}\nexport type {\n LoginAttemptResponse,\n MfaMethod,\n MfaRequirementCheckResult,\n MfaSettings,\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { QRCodeSVG } from 'qrcode.react';
|
|
4
4
|
import { Box, Collapse, Dialog, Grid, Link, Typography, DialogContent, DialogActions, Button, DialogTitle, } from '@mui/material';
|
|
5
|
-
import {
|
|
5
|
+
import { mfaService } from '../../apps';
|
|
6
6
|
import useBooleanState from '../../hooks/useBooleanState';
|
|
7
7
|
import useMfa from '../../hooks/useMfa';
|
|
8
8
|
import { CopyToClipBoardIconButton } from '../CopyToClipboardIconButton';
|
|
@@ -13,7 +13,7 @@ function MfaAuthenticatorAppDialog() {
|
|
|
13
13
|
const [isShowingSecretCode, showSecretCode, hideSecretCode] = useBooleanState(false);
|
|
14
14
|
const qrcodeValue = React.useMemo(() => {
|
|
15
15
|
if (mfaAuthenticatorAppSetup) {
|
|
16
|
-
return
|
|
16
|
+
return mfaService.generateMfaAuthenticatorAppQrCodeUrl(mfaAuthenticatorAppSetup);
|
|
17
17
|
}
|
|
18
18
|
}, [mfaAuthenticatorAppSetup]);
|
|
19
19
|
const [isSaving, startSaving, stopSaving] = useBooleanState(false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MfaAuthenticatorAppDialog.js","sourceRoot":"","sources":["../../../src/components/mfa/MfaAuthenticatorAppDialog.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EACL,GAAG,EACH,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,aAAa,EACb,aAAa,EACb,MAAM,EACN,WAAW,GACZ,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,eAAe,MAAM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AAU,EAClB,KAAK,EAAE,IAAI,EACX,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;oCAClB,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAA;oCACnC,QAAQ,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAA;gCAC1B,CAAC,EACD,QAAQ,EAAE,QAAQ,kBACL,4BAA4B,GACzC,IACY,EAChB,MAAC,aAAa,eACZ,KAAC,MAAM,IACL,IAAI,EAAC,QAAQ,EACb,OAAO,EAAE,8BAA8B,EACvC,QAAQ,EAAE,QAAQ,uBAGX,EACT,KAAC,MAAM,IACL,IAAI,EAAC,QAAQ,EACb,OAAO,EAAC,WAAW,EACnB,KAAK,EAAC,SAAS,EACf,QAAQ,EAAE,CAAC,IAAI,IAAI,QAAQ,qBAGpB,IACK,IACX,GACA,GACM,CAClB,CAAA;AACH,CAAC;AAED;;;;;;;GAOG;AACH,eAAe,KAAK,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport { QRCodeSVG } from 'qrcode.react'\nimport {\n Box,\n Collapse,\n Dialog,\n Grid,\n Link,\n Typography,\n DialogContent,\n DialogActions,\n Button,\n DialogTitle,\n} from '@mui/material'\nimport { authService } from '../../apps'\nimport useBooleanState from '../../hooks/useBooleanState'\nimport useMfa from '../../hooks/useMfa'\nimport { CopyToClipBoardIconButton } from '../CopyToClipboardIconButton'\nimport InputField from '../InputField'\n\nfunction MfaAuthenticatorAppDialog() {\n const {\n mfaAuthenticatorAppSetup,\n cancelMfaAuthenticatorAppSetup,\n completeMfaAuthenticatorAppSetup,\n } = useMfa()\n\n const [code, setState] = React.useState('')\n const [isShowingSecretCode, showSecretCode, hideSecretCode] =\n useBooleanState(false)\n\n const qrcodeValue = React.useMemo(() => {\n if (mfaAuthenticatorAppSetup) {\n return authService.generateMfaAuthenticatorAppQrCodeUrl(\n mfaAuthenticatorAppSetup,\n )\n }\n }, [mfaAuthenticatorAppSetup])\n\n const [isSaving, startSaving, stopSaving] = useBooleanState(false)\n const handleSubmit = React.useCallback(\n async (event: React.SubmitEvent<HTMLFormElement>) => {\n event.preventDefault()\n\n if (!code || !mfaAuthenticatorAppSetup || isSaving) {\n return\n }\n\n startSaving()\n try {\n await mfaAuthenticatorAppSetup.mfaCodeCallback(code)\n await completeMfaAuthenticatorAppSetup()\n } finally {\n stopSaving()\n }\n },\n [\n code,\n completeMfaAuthenticatorAppSetup,\n isSaving,\n mfaAuthenticatorAppSetup,\n startSaving,\n stopSaving,\n ],\n )\n\n return (\n <React.Fragment>\n <Dialog\n open={!!mfaAuthenticatorAppSetup}\n onClose={cancelMfaAuthenticatorAppSetup}\n title=\"Complete MFA Setup\"\n >\n <form onSubmit={handleSubmit}>\n <DialogTitle>Authenticator App Setup</DialogTitle>\n <DialogContent dividers>\n <Typography variant=\"body2\" component=\"p\" sx={{ mb: 2 }}>\n Authenticator apps like{' '}\n <Link\n href=\"https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Google Authenticator\n </Link>{' '}\n and{' '}\n <Link\n href=\"https://www.microsoft.com/en-us/security/mobile-authenticator-app\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Microsoft Authenticator\n </Link>{' '}\n generate one-time passwords that are used as a second factor to\n verify your identity when prompted during sign-in.\n </Typography>\n <Typography variant=\"subtitle2\" gutterBottom>\n Scan the QR code\n </Typography>\n <Typography variant=\"body2\" sx={{ mb: 2 }}>\n Use an authenticator app or browser extension to scan the QR code\n below.\n </Typography>\n\n <Box marginBottom={2}>\n <Grid container spacing={2} alignItems=\"center\">\n <Grid>\n <Box\n border={1}\n padding={2}\n borderRadius={1}\n borderColor=\"divider\"\n display=\"inline-block\"\n lineHeight={0}\n >\n <QRCodeSVG value={qrcodeValue || ''} />\n </Box>\n </Grid>\n <Grid size={{ xs: 'grow' }}>\n <Typography variant=\"caption\" color=\"text.secondary\">\n Having trouble scanning the QR code?{' '}\n <Link\n type=\"button\"\n onClick={showSecretCode}\n component=\"button\"\n >\n Click here\n </Link>{' '}\n to display the setup key which can be manually entered in\n your authenticator app.\n </Typography>\n </Grid>\n </Grid>\n </Box>\n\n <Collapse in={isShowingSecretCode}>\n <Box marginBottom={2}>\n <InputField\n label=\"Setup Key\"\n value={mfaAuthenticatorAppSetup?.secretCode || ''}\n variant=\"filled\"\n focused={false}\n sx={{\n input: {\n cursor: 'default !important',\n },\n }}\n fullWidth\n slotProps={{\n input: {\n readOnly: true,\n endAdornment: (\n <CopyToClipBoardIconButton\n text={mfaAuthenticatorAppSetup?.secretCode || ''}\n />\n ),\n },\n }}\n helperText={\n <>\n <Link\n type=\"button\"\n onClick={hideSecretCode}\n component=\"button\"\n >\n Click here\n </Link>{' '}\n to hide the setup key\n </>\n }\n />\n </Box>\n </Collapse>\n\n <Typography variant=\"subtitle2\" gutterBottom>\n Verify App\n </Typography>\n <Typography variant=\"body2\" sx={{ mb: 2 }}>\n Enter the 6-digit code found in your authenticator app.\n </Typography>\n\n <InputField\n autoFocus\n margin=\"none\"\n name=\"code\"\n label=\"Code\"\n fullWidth\n placeholder=\"XXXXXX\"\n variant=\"outlined\"\n value={code}\n onChange={(event) => {\n const newValue = event.target.value\n setState(() => newValue)\n }}\n disabled={isSaving}\n data-cypress=\"mfa-authenticator-app-code\"\n />\n </DialogContent>\n <DialogActions>\n <Button\n type=\"button\"\n onClick={cancelMfaAuthenticatorAppSetup}\n disabled={isSaving}\n >\n Cancel\n </Button>\n <Button\n type=\"submit\"\n variant=\"contained\"\n color=\"primary\"\n disabled={!code || isSaving}\n >\n Save\n </Button>\n </DialogActions>\n </form>\n </Dialog>\n </React.Fragment>\n )\n}\n\n/**\n * React Component that guides users through authenticator app MFA setup,\n * including QR code scanning and verification code entry. Typically rendered by\n * `<MultiFactorAuthentication />` within an\n * `<MfaProvider />` tree.\n *\n * @returns\n */\nexport default React.memo(MfaAuthenticatorAppDialog)\n"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IACH,IAAI,EAAC,QAAQ,EACb,OAAO,EAAE,cAAc,EACvB,SAAS,EAAC,QAAQ,2BAGb,EAAC,GAAG,6BAEV,GAEL,GACE,GACG,EAEX,KAAC,UAAU,IAAC,OAAO,EAAC,WAAW,EAAC,YAAY,iCAE/B,EACb,KAAC,UAAU,IAAC,OAAO,EAAC,OAAO,EAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,wEAE5B,EAEb,KAAC,UAAU,IACT,SAAS,QACT,MAAM,EAAC,MAAM,EACb,IAAI,EAAC,MAAM,EACX,KAAK,EAAC,MAAM,EACZ,SAAS,QACT,WAAW,EAAC,QAAQ,EACpB,OAAO,EAAC,UAAU,EAClB,KAAK,EAAE,IAAI,EACX,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;oCAClB,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAA;oCACnC,QAAQ,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAA;gCAC1B,CAAC,EACD,QAAQ,EAAE,QAAQ,kBACL,4BAA4B,GACzC,IACY,EAChB,MAAC,aAAa,eACZ,KAAC,MAAM,IACL,IAAI,EAAC,QAAQ,EACb,OAAO,EAAE,8BAA8B,EACvC,QAAQ,EAAE,QAAQ,uBAGX,EACT,KAAC,MAAM,IACL,IAAI,EAAC,QAAQ,EACb,OAAO,EAAC,WAAW,EACnB,KAAK,EAAC,SAAS,EACf,QAAQ,EAAE,CAAC,IAAI,IAAI,QAAQ,qBAGpB,IACK,IACX,GACA,GACM,CAClB,CAAA;AACH,CAAC;AAED;;;;;;;GAOG;AACH,eAAe,KAAK,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport { QRCodeSVG } from 'qrcode.react'\nimport {\n Box,\n Collapse,\n Dialog,\n Grid,\n Link,\n Typography,\n DialogContent,\n DialogActions,\n Button,\n DialogTitle,\n} from '@mui/material'\nimport { mfaService } from '../../apps'\nimport useBooleanState from '../../hooks/useBooleanState'\nimport useMfa from '../../hooks/useMfa'\nimport { CopyToClipBoardIconButton } from '../CopyToClipboardIconButton'\nimport InputField from '../InputField'\n\nfunction MfaAuthenticatorAppDialog() {\n const {\n mfaAuthenticatorAppSetup,\n cancelMfaAuthenticatorAppSetup,\n completeMfaAuthenticatorAppSetup,\n } = useMfa()\n\n const [code, setState] = React.useState('')\n const [isShowingSecretCode, showSecretCode, hideSecretCode] =\n useBooleanState(false)\n\n const qrcodeValue = React.useMemo(() => {\n if (mfaAuthenticatorAppSetup) {\n return mfaService.generateMfaAuthenticatorAppQrCodeUrl(\n mfaAuthenticatorAppSetup,\n )\n }\n }, [mfaAuthenticatorAppSetup])\n\n const [isSaving, startSaving, stopSaving] = useBooleanState(false)\n const handleSubmit = React.useCallback(\n async (event: React.SubmitEvent<HTMLFormElement>) => {\n event.preventDefault()\n\n if (!code || !mfaAuthenticatorAppSetup || isSaving) {\n return\n }\n\n startSaving()\n try {\n await mfaAuthenticatorAppSetup.mfaCodeCallback(code)\n await completeMfaAuthenticatorAppSetup()\n } finally {\n stopSaving()\n }\n },\n [\n code,\n completeMfaAuthenticatorAppSetup,\n isSaving,\n mfaAuthenticatorAppSetup,\n startSaving,\n stopSaving,\n ],\n )\n\n return (\n <React.Fragment>\n <Dialog\n open={!!mfaAuthenticatorAppSetup}\n onClose={cancelMfaAuthenticatorAppSetup}\n title=\"Complete MFA Setup\"\n >\n <form onSubmit={handleSubmit}>\n <DialogTitle>Authenticator App Setup</DialogTitle>\n <DialogContent dividers>\n <Typography variant=\"body2\" component=\"p\" sx={{ mb: 2 }}>\n Authenticator apps like{' '}\n <Link\n href=\"https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Google Authenticator\n </Link>{' '}\n and{' '}\n <Link\n href=\"https://www.microsoft.com/en-us/security/mobile-authenticator-app\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Microsoft Authenticator\n </Link>{' '}\n generate one-time passwords that are used as a second factor to\n verify your identity when prompted during sign-in.\n </Typography>\n <Typography variant=\"subtitle2\" gutterBottom>\n Scan the QR code\n </Typography>\n <Typography variant=\"body2\" sx={{ mb: 2 }}>\n Use an authenticator app or browser extension to scan the QR code\n below.\n </Typography>\n\n <Box marginBottom={2}>\n <Grid container spacing={2} alignItems=\"center\">\n <Grid>\n <Box\n border={1}\n padding={2}\n borderRadius={1}\n borderColor=\"divider\"\n display=\"inline-block\"\n lineHeight={0}\n >\n <QRCodeSVG value={qrcodeValue || ''} />\n </Box>\n </Grid>\n <Grid size={{ xs: 'grow' }}>\n <Typography variant=\"caption\" color=\"text.secondary\">\n Having trouble scanning the QR code?{' '}\n <Link\n type=\"button\"\n onClick={showSecretCode}\n component=\"button\"\n >\n Click here\n </Link>{' '}\n to display the setup key which can be manually entered in\n your authenticator app.\n </Typography>\n </Grid>\n </Grid>\n </Box>\n\n <Collapse in={isShowingSecretCode}>\n <Box marginBottom={2}>\n <InputField\n label=\"Setup Key\"\n value={mfaAuthenticatorAppSetup?.secretCode || ''}\n variant=\"filled\"\n focused={false}\n sx={{\n input: {\n cursor: 'default !important',\n },\n }}\n fullWidth\n slotProps={{\n input: {\n readOnly: true,\n endAdornment: (\n <CopyToClipBoardIconButton\n text={mfaAuthenticatorAppSetup?.secretCode || ''}\n />\n ),\n },\n }}\n helperText={\n <>\n <Link\n type=\"button\"\n onClick={hideSecretCode}\n component=\"button\"\n >\n Click here\n </Link>{' '}\n to hide the setup key\n </>\n }\n />\n </Box>\n </Collapse>\n\n <Typography variant=\"subtitle2\" gutterBottom>\n Verify App\n </Typography>\n <Typography variant=\"body2\" sx={{ mb: 2 }}>\n Enter the 6-digit code found in your authenticator app.\n </Typography>\n\n <InputField\n autoFocus\n margin=\"none\"\n name=\"code\"\n label=\"Code\"\n fullWidth\n placeholder=\"XXXXXX\"\n variant=\"outlined\"\n value={code}\n onChange={(event) => {\n const newValue = event.target.value\n setState(() => newValue)\n }}\n disabled={isSaving}\n data-cypress=\"mfa-authenticator-app-code\"\n />\n </DialogContent>\n <DialogActions>\n <Button\n type=\"button\"\n onClick={cancelMfaAuthenticatorAppSetup}\n disabled={isSaving}\n >\n Cancel\n </Button>\n <Button\n type=\"submit\"\n variant=\"contained\"\n color=\"primary\"\n disabled={!code || isSaving}\n >\n Save\n </Button>\n </DialogActions>\n </form>\n </Dialog>\n </React.Fragment>\n )\n}\n\n/**\n * React Component that guides users through authenticator app MFA setup,\n * including QR code scanning and verification code entry. Typically rendered by\n * `<MultiFactorAuthentication />` within an\n * `<MfaProvider />` tree.\n *\n * @returns\n */\nexport default React.memo(MfaAuthenticatorAppDialog)\n"]}
|
|
@@ -8,12 +8,13 @@ type Props = {
|
|
|
8
8
|
title: string;
|
|
9
9
|
description: string;
|
|
10
10
|
detail?: string;
|
|
11
|
+
mfaRequirementMessage?: string;
|
|
11
12
|
cypressPrefix: string;
|
|
12
13
|
extraButtons?: React.ReactNode;
|
|
13
14
|
onSetup: () => void;
|
|
14
15
|
onDisable: () => void;
|
|
15
16
|
onSetPreferred: () => void;
|
|
16
17
|
};
|
|
17
|
-
declare function MfaMethodRow({ isEnabled, isPreferred, isSettingUp, isSettingPreferredMfaMethod, isSetupDisabled, showSetupErrorTooltip, title, description, detail, cypressPrefix, extraButtons, onSetup, onDisable, onSetPreferred, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
declare function MfaMethodRow({ isEnabled, isPreferred, isSettingUp, isSettingPreferredMfaMethod, isSetupDisabled, showSetupErrorTooltip, title, description, detail, mfaRequirementMessage, cypressPrefix, extraButtons, onSetup, onDisable, onSetPreferred, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
18
19
|
declare const _default: import("react").MemoExoticComponent<typeof MfaMethodRow>;
|
|
19
20
|
export default _default;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { memo } from 'react';
|
|
3
|
-
import { Box, Button, Chip, Grid, Tooltip, Typography } from '@mui/material';
|
|
4
|
-
function MfaMethodRow({ isEnabled, isPreferred, isSettingUp, isSettingPreferredMfaMethod, isSetupDisabled, showSetupErrorTooltip, title, description, detail, cypressPrefix, extraButtons, onSetup, onDisable, onSetPreferred, }) {
|
|
5
|
-
return (_jsx(Box, { "data-cypress": `${cypressPrefix}-method-row`, children: _jsxs(Grid, { container: true, spacing: 2, alignItems: "center", children: [_jsxs(Grid, { size: { xs: 'grow' }, children: [_jsxs(Box, { sx: { mb: 1 }, children: [_jsx(Typography, { variant: "subtitle1", component: "span", children: title }), isEnabled && (_jsx(Chip, { size: "small", label: "Enabled", color: "info", sx: { ml: 1 }, "data-cypress": `${cypressPrefix}-status-chip` })), isPreferred && (_jsx(Chip, { size: "small", label: "Preferred", color: "success", sx: { ml: 1 }, "data-cypress": `${cypressPrefix}-preferred-chip` }))] }), _jsx(Typography, { variant: "body2", color: "text.secondary", children: description }), !!detail && (_jsx(Typography, { variant: "body2", color: "text.secondary", sx: { mt: 1 }, children: detail }))] }), _jsx(Grid, { size: "auto", children: _jsxs(Box, { display: "flex", gap: 1, flexWrap: "wrap", justifyContent: "flex-end", children: [extraButtons, isEnabled ? (_jsxs(_Fragment, { children: [!isPreferred && (_jsx(Button, { size: "small", variant: "outlined", loading: isSettingPreferredMfaMethod, disabled: isSettingPreferredMfaMethod, onClick: onSetPreferred, "data-cypress": `${cypressPrefix}-set-preferred-button`, children: "Set as Preferred" })), _jsx(Button, { size: "small", variant: "outlined", onClick: onDisable, "data-cypress": `${cypressPrefix}-disable-button`, children: "Disable" })] })) : (_jsx(Tooltip, { title: showSetupErrorTooltip
|
|
3
|
+
import { Alert, Box, Button, Chip, Grid, Tooltip, Typography, } from '@mui/material';
|
|
4
|
+
function MfaMethodRow({ isEnabled, isPreferred, isSettingUp, isSettingPreferredMfaMethod, isSetupDisabled, showSetupErrorTooltip, title, description, detail, mfaRequirementMessage, cypressPrefix, extraButtons, onSetup, onDisable, onSetPreferred, }) {
|
|
5
|
+
return (_jsx(Box, { "data-cypress": `${cypressPrefix}-method-row`, children: _jsxs(Grid, { container: true, spacing: 2, alignItems: "center", children: [_jsxs(Grid, { size: { xs: 'grow' }, children: [_jsxs(Box, { sx: { mb: 1 }, children: [_jsx(Typography, { variant: "subtitle1", component: "span", children: title }), isEnabled && (_jsx(Chip, { size: "small", label: "Enabled", color: "info", sx: { ml: 1 }, "data-cypress": `${cypressPrefix}-status-chip` })), isPreferred && (_jsx(Chip, { size: "small", label: "Preferred", color: "success", sx: { ml: 1 }, "data-cypress": `${cypressPrefix}-preferred-chip` }))] }), _jsx(Typography, { variant: "body2", color: "text.secondary", children: description }), !!detail && (_jsx(Typography, { variant: "body2", color: "text.secondary", sx: { mt: 1 }, children: detail })), !!mfaRequirementMessage && (_jsx(Alert, { severity: isEnabled && isPreferred ? 'warning' : 'info', sx: { mt: 1 }, "data-cypress": `${cypressPrefix}-mfa-requirement-message`, children: mfaRequirementMessage }))] }), _jsx(Grid, { size: "auto", children: _jsxs(Box, { display: "flex", gap: 1, flexWrap: "wrap", justifyContent: "flex-end", children: [extraButtons, isEnabled ? (_jsxs(_Fragment, { children: [!isPreferred && (_jsx(Button, { size: "small", variant: "outlined", loading: isSettingPreferredMfaMethod, disabled: isSettingPreferredMfaMethod, onClick: onSetPreferred, "data-cypress": `${cypressPrefix}-set-preferred-button`, children: "Set as Preferred" })), _jsx(Button, { size: "small", variant: "outlined", onClick: onDisable, "data-cypress": `${cypressPrefix}-disable-button`, children: "Disable" })] })) : (_jsx(Tooltip, { title: showSetupErrorTooltip
|
|
6
6
|
? 'We are unable to load your MFA status. Please try again by clicking the reload button on the chip above.'
|
|
7
7
|
: '', children: _jsx("span", { children: _jsx(Button, { size: "small", variant: "contained", loading: isSettingUp, disabled: isSetupDisabled, onClick: onSetup, "data-cypress": `${cypressPrefix}-setup-button`, children: "Setup" }) }) }))] }) })] }) }));
|
|
8
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MfaMethodRow.js","sourceRoot":"","sources":["../../../src/components/mfa/MfaMethodRow.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAC5B,OAAO,
|
|
1
|
+
{"version":3,"file":"MfaMethodRow.js","sourceRoot":"","sources":["../../../src/components/mfa/MfaMethodRow.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAC5B,OAAO,EACL,KAAK,EACL,GAAG,EACH,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,UAAU,GACX,MAAM,eAAe,CAAA;AAoBtB,SAAS,YAAY,CAAC,EACpB,SAAS,EACT,WAAW,EACX,WAAW,EACX,2BAA2B,EAC3B,eAAe,EACf,qBAAqB,EACrB,KAAK,EACL,WAAW,EACX,MAAM,EACN,qBAAqB,EACrB,aAAa,EACb,YAAY,EACZ,OAAO,EACP,SAAS,EACT,cAAc,GACR;IACN,OAAO,CACL,KAAC,GAAG,oBAAe,GAAG,aAAa,aAAa,YAC9C,MAAC,IAAI,IAAC,SAAS,QAAC,OAAO,EAAE,CAAC,EAAE,UAAU,EAAC,QAAQ,aAC7C,MAAC,IAAI,IAAC,IAAI,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,aACxB,MAAC,GAAG,IAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,aAChB,KAAC,UAAU,IAAC,OAAO,EAAC,WAAW,EAAC,SAAS,EAAC,MAAM,YAC7C,KAAK,GACK,EACZ,SAAS,IAAI,CACZ,KAAC,IAAI,IACH,IAAI,EAAC,OAAO,EACZ,KAAK,EAAC,SAAS,EACf,KAAK,EAAC,MAAM,EACZ,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,kBACC,GAAG,aAAa,cAAc,GAC5C,CACH,EACA,WAAW,IAAI,CACd,KAAC,IAAI,IACH,I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,KAAK,EACH,qBAAqB;oCACnB,CAAC,CAAC,0GAA0G;oCAC5G,CAAC,CAAC,EAAE,YAGR,yBACE,KAAC,MAAM,IACL,IAAI,EAAC,OAAO,EACZ,OAAO,EAAC,WAAW,EACnB,OAAO,EAAE,WAAW,EACpB,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,OAAO,kBACF,GAAG,aAAa,eAAe,sBAGtC,GACJ,GACC,CACX,IACG,GACD,IACF,GACH,CACP,CAAA;AACH,CAAC;AAED,eAAe,IAAI,CAAC,YAAY,CAAC,CAAA","sourcesContent":["import { memo } from 'react'\nimport {\n Alert,\n Box,\n Button,\n Chip,\n Grid,\n Tooltip,\n Typography,\n} from '@mui/material'\n\ntype Props = {\n isEnabled: boolean\n isPreferred: boolean\n isSettingUp: boolean\n isSettingPreferredMfaMethod: boolean\n isSetupDisabled: boolean\n showSetupErrorTooltip?: boolean\n title: string\n description: string\n detail?: string\n mfaRequirementMessage?: string\n cypressPrefix: string\n extraButtons?: React.ReactNode\n onSetup: () => void\n onDisable: () => void\n onSetPreferred: () => void\n}\n\nfunction MfaMethodRow({\n isEnabled,\n isPreferred,\n isSettingUp,\n isSettingPreferredMfaMethod,\n isSetupDisabled,\n showSetupErrorTooltip,\n title,\n description,\n detail,\n mfaRequirementMessage,\n cypressPrefix,\n extraButtons,\n onSetup,\n onDisable,\n onSetPreferred,\n}: Props) {\n return (\n <Box data-cypress={`${cypressPrefix}-method-row`}>\n <Grid container spacing={2} alignItems=\"center\">\n <Grid size={{ xs: 'grow' }}>\n <Box sx={{ mb: 1 }}>\n <Typography variant=\"subtitle1\" component=\"span\">\n {title}\n </Typography>\n {isEnabled && (\n <Chip\n size=\"small\"\n label=\"Enabled\"\n color=\"info\"\n sx={{ ml: 1 }}\n data-cypress={`${cypressPrefix}-status-chip`}\n />\n )}\n {isPreferred && (\n <Chip\n size=\"small\"\n label=\"Preferred\"\n color=\"success\"\n sx={{ ml: 1 }}\n data-cypress={`${cypressPrefix}-preferred-chip`}\n />\n )}\n </Box>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {description}\n </Typography>\n {!!detail && (\n <Typography variant=\"body2\" color=\"text.secondary\" sx={{ mt: 1 }}>\n {detail}\n </Typography>\n )}\n {!!mfaRequirementMessage && (\n <Alert\n severity={isEnabled && isPreferred ? 'warning' : 'info'}\n sx={{ mt: 1 }}\n data-cypress={`${cypressPrefix}-mfa-requirement-message`}\n >\n {mfaRequirementMessage}\n </Alert>\n )}\n </Grid>\n <Grid size=\"auto\">\n <Box display=\"flex\" gap={1} flexWrap=\"wrap\" justifyContent=\"flex-end\">\n {extraButtons}\n {isEnabled ? (\n <>\n {!isPreferred && (\n <Button\n size=\"small\"\n variant=\"outlined\"\n loading={isSettingPreferredMfaMethod}\n disabled={isSettingPreferredMfaMethod}\n onClick={onSetPreferred}\n data-cypress={`${cypressPrefix}-set-preferred-button`}\n >\n Set as Preferred\n </Button>\n )}\n <Button\n size=\"small\"\n variant=\"outlined\"\n onClick={onDisable}\n data-cypress={`${cypressPrefix}-disable-button`}\n >\n Disable\n </Button>\n </>\n ) : (\n <Tooltip\n title={\n showSetupErrorTooltip\n ? 'We are unable to load your MFA status. Please try again by clicking the reload button on the chip above.'\n : ''\n }\n >\n <span>\n <Button\n size=\"small\"\n variant=\"contained\"\n loading={isSettingUp}\n disabled={isSetupDisabled}\n onClick={onSetup}\n data-cypress={`${cypressPrefix}-setup-button`}\n >\n Setup\n </Button>\n </span>\n </Tooltip>\n )}\n </Box>\n </Grid>\n </Grid>\n </Box>\n )\n}\n\nexport default memo(MfaMethodRow)\n"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { MiscTypes } from '@oneblink/types';
|
|
1
2
|
type Props = {
|
|
2
|
-
|
|
3
|
+
mfaRequirement: MiscTypes.MfaRequirement | undefined;
|
|
4
|
+
ssoSetupUrl?: string;
|
|
3
5
|
};
|
|
4
6
|
/**
|
|
5
7
|
* React Component that provides a mechanism for app users to configure Multi
|
|
@@ -16,26 +18,25 @@ type Props = {
|
|
|
16
18
|
* } from '@oneblink/apps-react'
|
|
17
19
|
*
|
|
18
20
|
* function Component() {
|
|
19
|
-
* return <MultiFactorAuthentication />
|
|
21
|
+
* return <MultiFactorAuthentication mfaRequirement={undefined} />
|
|
20
22
|
* }
|
|
21
23
|
*
|
|
22
|
-
* function
|
|
24
|
+
* function AppWithMfaRequirement({ mfaRequirement }) {
|
|
23
25
|
* return (
|
|
24
26
|
* <MfaProvider>
|
|
25
|
-
* <
|
|
27
|
+
* <MultiFactorAuthentication mfaRequirement={mfaRequirement} />
|
|
26
28
|
* </MfaProvider>
|
|
27
29
|
* )
|
|
28
30
|
* }
|
|
29
|
-
*
|
|
30
|
-
* const root = document.getElementById('root')
|
|
31
|
-
* if (root) {
|
|
32
|
-
* ReactDOM.render(<App />, root)
|
|
33
|
-
* }
|
|
34
31
|
* ```
|
|
35
32
|
*
|
|
36
33
|
* @param props
|
|
34
|
+
* @param props.mfaRequirement - The MFA methods allowed by your administrator
|
|
35
|
+
* for using this app. Pass `undefined` when the app has no MFA requirement.
|
|
36
|
+
* Users can still enable other methods, but will be warned when their
|
|
37
|
+
* configuration does not meet this requirement.
|
|
37
38
|
* @returns
|
|
38
39
|
* @group Components
|
|
39
40
|
*/
|
|
40
|
-
export default function MultiFactorAuthentication({ ssoSetupUrl }: Props): import("react/jsx-runtime").JSX.Element;
|
|
41
|
+
export default function MultiFactorAuthentication({ mfaRequirement, ssoSetupUrl, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
41
42
|
export {};
|