Skip to content

Commit

Permalink
fix: tenant id in get global claim validators (#634)
Browse files Browse the repository at this point in the history
* fix: tenant id in global claim validators

* fix: pr comments
  • Loading branch information
sattvikc authored Jul 12, 2023
1 parent e0ab26e commit 040e0f2
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/build/recipe/session/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default class SessionWrapper {
}
>;
static validateClaimsInJWTPayload(
tenantId: string,
userId: string,
jwtPayload: JSONObject,
overrideGlobalClaimValidators?: (
Expand Down
6 changes: 4 additions & 2 deletions lib/build/recipe/session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ class SessionWrapper {
.getInstanceOrThrowError()
.getClaimValidatorsAddedByOtherRecipes();
const globalClaimValidators = yield recipeImpl.getGlobalClaimValidators({
userId: sessionInfo === null || sessionInfo === void 0 ? void 0 : sessionInfo.userId,
userId: sessionInfo.userId,
tenantId: sessionInfo.tenantId,
claimValidatorsAddedByOtherRecipes,
userContext,
});
Expand Down Expand Up @@ -161,13 +162,14 @@ class SessionWrapper {
};
});
}
static validateClaimsInJWTPayload(userId, jwtPayload, overrideGlobalClaimValidators, userContext = {}) {
static validateClaimsInJWTPayload(tenantId, userId, jwtPayload, overrideGlobalClaimValidators, userContext = {}) {
return __awaiter(this, void 0, void 0, function* () {
const recipeImpl = recipe_1.default.getInstanceOrThrowError().recipeInterfaceImpl;
const claimValidatorsAddedByOtherRecipes = recipe_1.default
.getInstanceOrThrowError()
.getClaimValidatorsAddedByOtherRecipes();
const globalClaimValidators = yield recipeImpl.getGlobalClaimValidators({
tenantId,
userId,
claimValidatorsAddedByOtherRecipes,
userContext,
Expand Down
1 change: 1 addition & 0 deletions lib/build/recipe/session/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export declare type RecipeInterface = {
userContext: any;
}): Promise<SessionContainerInterface>;
getGlobalClaimValidators(input: {
tenantId: string;
userId: string;
claimValidatorsAddedByOtherRecipes: SessionClaimValidator[];
userContext: any;
Expand Down
1 change: 1 addition & 0 deletions lib/build/recipe/session/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ function getRequiredClaimValidators(session, overrideGlobalClaimValidators, user
.getInstanceOrThrowError()
.recipeInterfaceImpl.getGlobalClaimValidators({
userId: session.getUserId(),
tenantId: session.getTenantId(),
claimValidatorsAddedByOtherRecipes,
userContext,
});
Expand Down
5 changes: 4 additions & 1 deletion lib/ts/recipe/session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ export default class SessionWrapper {

const claimValidatorsAddedByOtherRecipes = Recipe.getInstanceOrThrowError().getClaimValidatorsAddedByOtherRecipes();
const globalClaimValidators: SessionClaimValidator[] = await recipeImpl.getGlobalClaimValidators({
userId: sessionInfo?.userId,
userId: sessionInfo.userId,
tenantId: sessionInfo.tenantId,
claimValidatorsAddedByOtherRecipes,
userContext,
});
Expand Down Expand Up @@ -167,6 +168,7 @@ export default class SessionWrapper {
}

static async validateClaimsInJWTPayload(
tenantId: string,
userId: string,
jwtPayload: JSONObject,
overrideGlobalClaimValidators?: (
Expand All @@ -183,6 +185,7 @@ export default class SessionWrapper {

const claimValidatorsAddedByOtherRecipes = Recipe.getInstanceOrThrowError().getClaimValidatorsAddedByOtherRecipes();
const globalClaimValidators: SessionClaimValidator[] = await recipeImpl.getGlobalClaimValidators({
tenantId,
userId,
claimValidatorsAddedByOtherRecipes,
userContext,
Expand Down
1 change: 1 addition & 0 deletions lib/ts/recipe/session/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export type RecipeInterface = {
}): Promise<SessionContainerInterface>;

getGlobalClaimValidators(input: {
tenantId: string;
userId: string;
claimValidatorsAddedByOtherRecipes: SessionClaimValidator[];
userContext: any;
Expand Down
1 change: 1 addition & 0 deletions lib/ts/recipe/session/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export async function getRequiredClaimValidators(
const globalClaimValidators: SessionClaimValidator[] = await SessionRecipe.getInstanceOrThrowError().recipeInterfaceImpl.getGlobalClaimValidators(
{
userId: session.getUserId(),
tenantId: session.getTenantId(),
claimValidatorsAddedByOtherRecipes,
userContext,
}
Expand Down
5 changes: 3 additions & 2 deletions test/with-typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1359,12 +1359,13 @@ Session.validateClaimsForSessionHandle(
{ test: 1 }
);

Session.validateClaimsInJWTPayload("userId", {});
Session.validateClaimsInJWTPayload("userId", {}, (globalClaimValidators) => [
Session.validateClaimsInJWTPayload("public", "userId", {});
Session.validateClaimsInJWTPayload("public", "userId", {}, (globalClaimValidators) => [
...globalClaimValidators,
boolClaim.validators.isTrue(),
]);
Session.validateClaimsInJWTPayload(
"public",
"userId",
{},
(globalClaimValidators, userId) => [...globalClaimValidators, stringClaim.validators.startsWith(userId)],
Expand Down

0 comments on commit 040e0f2

Please sign in to comment.