Skip to content

Commit

Permalink
feat: update based on review discussions
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Oct 5, 2023
1 parent e8ac972 commit 7f25f68
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 30 deletions.
11 changes: 7 additions & 4 deletions lib/build/framework/fastify/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
// @ts-nocheck
/// <reference types="node" />
export type { SessionRequest } from "./framework";
export declare const plugin: import("fastify").FastifyPluginCallback<Record<never, never>, import("http").Server>;
export declare const plugin: import("fastify").FastifyPluginCallback<
Record<never, never>,
import("fastify").RawServerDefault
>;
export declare const errorHandler: () => (
err: any,
req: import("fastify").FastifyRequest<
import("fastify/types/route").RouteGenericInterface,
import("http").Server,
import("fastify").RawServerDefault,
import("http").IncomingMessage
>,
res: import("fastify").FastifyReply<
import("http").Server,
import("fastify").RawServerDefault,
import("http").IncomingMessage,
import("http").ServerResponse,
import("http").ServerResponse<import("http").IncomingMessage>,
import("fastify/types/route").RouteGenericInterface,
unknown
>
Expand Down
2 changes: 1 addition & 1 deletion lib/build/framework/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export declare function setCookieForServerResponse(
expires: number,
path: string,
sameSite: "strict" | "lax" | "none"
): ServerResponse;
): ServerResponse<IncomingMessage>;
export declare function getCookieValueToSetInHeader(
prev: string | string[] | undefined,
val: string | string[],
Expand Down
1 change: 1 addition & 0 deletions lib/build/recipe/multifactorauth/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default class Wrapper {
static init: typeof Recipe.init;
static MultiFactorAuthClaim: import("./multiFactorAuthClaim").MultiFactorAuthClaimClass;
static enableFactorForUser(
tenantId: string,
userId: string,
factorId: string,
userContext?: any
Expand Down
3 changes: 2 additions & 1 deletion lib/build/recipe/multifactorauth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ Object.defineProperty(exports, "MultiFactorAuthClaim", {
},
});
class Wrapper {
static async enableFactorForUser(userId, factorId, userContext) {
static async enableFactorForUser(tenantId, userId, factorId, userContext) {
const recipeInstance = recipe_1.default.getInstanceOrThrowError();
return recipeInstance.recipeInterfaceImpl.enableFactorForUser({
userId,
factorId,
tenantId,
userContext: userContext === undefined ? {} : userContext,
});
}
Expand Down
5 changes: 4 additions & 1 deletion lib/build/recipe/multifactorauth/recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,13 @@ class Recipe extends recipeModule_1.default {
Object.assign({}, currentValue === null || currentValue === void 0 ? void 0 : currentValue.c),
{ [factor]: Math.floor(Date.now() / 1000) }
);
const requirements = await this.config.getMFARequirementsForSession(
const requirements = await this.config.getGlobalMFARequirements(
session.getUserId(),
session.getRecipeUserId(),
session.getTenantId(),
session,
[], // TODO: this should call getEnabledFactorsForX
completed,
userContext
);
const next = multiFactorAuthClaim_1.MultiFactorAuthClaim.buildNextArray(completed, requirements);
Expand Down
23 changes: 14 additions & 9 deletions lib/build/recipe/multifactorauth/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SessionContainerInterface } from "../session/types";
export declare type MFARequirement =
| {
id: string;
params?: any;
maxAgeInSeconds?: number;
}
| string;
export declare type MFARequirementList = (
Expand All @@ -26,16 +26,18 @@ export declare type MFAClaimValue = {
};
export declare type TypeInput = {
firstFactors?: string[];
getMFARequirementsForSession?: (
getGlobalMFARequirements?: (
userId: string,
recipeUserId: RecipeUserId,
tenantId: string | undefined,
tenantId: string,
session: SessionContainer | undefined,
enabledFactors: string[],
completedFactors: Record<string, number>,
userContext: any
) => Promise<MFARequirementList> | MFARequirementList;
getMFARequirementsForFactorSetup?: (
factorId: string,
session: SessionContainer,
tenantId: string | undefined,
userContext: any
) => Promise<MFARequirementList> | MFARequirementList;
override?: {
Expand All @@ -48,16 +50,18 @@ export declare type TypeInput = {
};
export declare type TypeNormalisedInput = {
firstFactors?: string[];
getMFARequirementsForSession: (
getGlobalMFARequirements: (
userId: string,
recipeUserId: RecipeUserId,
tenantId: string | undefined,
tenantId: string,
session: SessionContainer | undefined,
enabledFactors: string[],
completedFactors: Record<string, number>,
userContext: any
) => Promise<MFARequirementList> | MFARequirementList;
getMFARequirementsForFactorSetup: (
factorId: string,
session: SessionContainer,
tenantId: string | undefined,
userContext: any
) => Promise<MFARequirementList> | MFARequirementList;
override: {
Expand All @@ -69,15 +73,15 @@ export declare type TypeNormalisedInput = {
};
};
export declare type RecipeInterface = {
getFirstFactors: (input: { tenantId: string }) => Promise<string[]>;
isAllowedToSetupFactor: (input: {
tenantId: string;
session: SessionContainerInterface;
factorId: string;
userContext: any;
}) => Promise<boolean>;
getFactorsSetupForUser: (input: { userId: string; userContext: any }) => Promise<string[]>;
getFactorsSetupForUser: (input: { userId: string; tenantId: string; userContext: any }) => Promise<string[]>;
enableFactorForUser: (input: {
tenantId: string;
userId: string;
factorId: string;
userContext: any;
Expand All @@ -95,6 +99,7 @@ export declare type RecipeInterface = {
}>;
getEnabledFactorsForUser: (input: {
userId: string;
tenantId: string;
userContext: any;
}) => Promise<{
status: "OK";
Expand Down
4 changes: 2 additions & 2 deletions lib/build/recipe/multifactorauth/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ function validateAndNormaliseUserInput(config) {
// TODO: the default should be 2FA if any secondary factors are set up, otherwise we only require the first factor to be completed
return [];
},
getMFARequirementsForSession:
(_b = config === null || config === void 0 ? void 0 : config.getMFARequirementsForSession) !== null &&
getGlobalMFARequirements:
(_b = config === null || config === void 0 ? void 0 : config.getGlobalMFARequirements) !== null &&
_b !== void 0
? _b
: () => {
Expand Down
2 changes: 2 additions & 0 deletions lib/ts/recipe/multifactorauth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default class Wrapper {
static MultiFactorAuthClaim = MultiFactorAuthClaim;

static async enableFactorForUser(
tenantId: string,
userId: string,
factorId: string,
userContext?: any
Expand All @@ -32,6 +33,7 @@ export default class Wrapper {
return recipeInstance.recipeInterfaceImpl.enableFactorForUser({
userId,
factorId,
tenantId,
userContext: userContext === undefined ? {} : userContext,
});
}
Expand Down
5 changes: 4 additions & 1 deletion lib/ts/recipe/multifactorauth/recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,13 @@ export default class Recipe extends RecipeModule {
[factor]: Math.floor(Date.now() / 1000),
};

const requirements = await this.config.getMFARequirementsForSession(
const requirements = await this.config.getGlobalMFARequirements(
session.getUserId(),
session.getRecipeUserId(),
session.getTenantId(),
session,
[], // TODO: this should call getEnabledFactorsForX
completed,
userContext
);
const next = MultiFactorAuthClaim.buildNextArray(completed, requirements);
Expand Down
23 changes: 14 additions & 9 deletions lib/ts/recipe/multifactorauth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { SessionContainerInterface } from "../session/types";
export type MFARequirement =
| {
id: string;
params?: any;
maxAgeInSeconds?: number;
}
| string;

Expand All @@ -45,16 +45,18 @@ export type MFAClaimValue = {
export type TypeInput = {
firstFactors?: string[];

getMFARequirementsForSession?: (
getGlobalMFARequirements?: (
userId: string,
recipeUserId: RecipeUserId,
tenantId: string | undefined,
tenantId: string,
session: SessionContainer | undefined,
enabledFactors: string[],
completedFactors: Record<string, number>,
userContext: any
) => Promise<MFARequirementList> | MFARequirementList;
getMFARequirementsForFactorSetup?: (
factorId: string,
session: SessionContainer,
tenantId: string | undefined,
userContext: any
) => Promise<MFARequirementList> | MFARequirementList;

Expand All @@ -70,16 +72,18 @@ export type TypeInput = {
export type TypeNormalisedInput = {
firstFactors?: string[];

getMFARequirementsForSession: (
getGlobalMFARequirements: (
userId: string,
recipeUserId: RecipeUserId,
tenantId: string | undefined,
tenantId: string,
session: SessionContainer | undefined,
enabledFactors: string[],
completedFactors: Record<string, number>,
userContext: any
) => Promise<MFARequirementList> | MFARequirementList;
getMFARequirementsForFactorSetup: (
factorId: string,
session: SessionContainer,
tenantId: string | undefined,
userContext: any
) => Promise<MFARequirementList> | MFARequirementList;

Expand All @@ -93,16 +97,16 @@ export type TypeNormalisedInput = {
};

export type RecipeInterface = {
getFirstFactors: (input: { tenantId: string }) => Promise<string[]>;
isAllowedToSetupFactor: (input: {
tenantId: string;
session: SessionContainerInterface;
factorId: string;
userContext: any;
}) => Promise<boolean>;
getFactorsSetupForUser: (input: { userId: string; userContext: any }) => Promise<string[]>;
getFactorsSetupForUser: (input: { userId: string; tenantId: string; userContext: any }) => Promise<string[]>;

enableFactorForUser: (input: {
tenantId: string;
userId: string;
factorId: string;
userContext: any;
Expand All @@ -114,6 +118,7 @@ export type RecipeInterface = {
}) => Promise<{ status: "OK"; newEnabledFactors: string[] }>;
getEnabledFactorsForUser: (input: {
userId: string;
tenantId: string;
userContext: any;
}) => Promise<{ status: "OK"; enabledFactors: string[] }>;
getEnabledFactorsForTenant: (input: {
Expand Down
4 changes: 2 additions & 2 deletions lib/ts/recipe/multifactorauth/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export function validateAndNormaliseUserInput(config?: TypeInput): TypeNormalise
// TODO: the default should be 2FA if any secondary factors are set up, otherwise we only require the first factor to be completed
return [];
}),
getMFARequirementsForSession:
config?.getMFARequirementsForSession ??
getGlobalMFARequirements:
config?.getGlobalMFARequirements ??
(() => {
// TODO: the default should be 2FA (so any 2 factors)
return [];
Expand Down

0 comments on commit 7f25f68

Please sign in to comment.