Skip to content

Commit

Permalink
PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
anku255 committed Jan 22, 2024
1 parent 5f52287 commit 95f0d03
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 49 deletions.
2 changes: 1 addition & 1 deletion bundle/bundle.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions lib/build/claims/primitiveArrayClaim.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/claims/primitiveClaim.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/fetch.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions lib/build/recipeImplementation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/types.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/build/utils/dateProvider/defaultImplementation.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/build/utils/dateProvider/defaultImplementation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/build/utils/dateProvider/types.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions lib/ts/claims/primitiveArrayClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class PrimitiveArrayClaim<ValueType> {
id?: string
): SessionClaimValidator => {
const DateProvider = DateProviderReference.getReferenceOrThrow().dateProvider;
if (maxAgeInSeconds && maxAgeInSeconds < DateProvider.getThresholdInSeconds()) {
if (maxAgeInSeconds !== undefined && maxAgeInSeconds < DateProvider.getThresholdInSeconds()) {
throw new Error(
`maxAgeInSeconds must be greater than the DateProvider threshold value -> ${DateProvider.getThresholdInSeconds()}`
);
Expand Down Expand Up @@ -80,7 +80,7 @@ export class PrimitiveArrayClaim<ValueType> {
id?: string
): SessionClaimValidator => {
const DateProvider = DateProviderReference.getReferenceOrThrow().dateProvider;
if (maxAgeInSeconds && maxAgeInSeconds < DateProvider.getThresholdInSeconds()) {
if (maxAgeInSeconds !== undefined && maxAgeInSeconds < DateProvider.getThresholdInSeconds()) {
throw new Error(
`maxAgeInSeconds must be greater than the DateProvider threshold value -> ${DateProvider.getThresholdInSeconds()}`
);
Expand Down Expand Up @@ -131,7 +131,7 @@ export class PrimitiveArrayClaim<ValueType> {
id?: string
): SessionClaimValidator => {
const DateProvider = DateProviderReference.getReferenceOrThrow().dateProvider;
if (maxAgeInSeconds && maxAgeInSeconds < DateProvider.getThresholdInSeconds()) {
if (maxAgeInSeconds !== undefined && maxAgeInSeconds < DateProvider.getThresholdInSeconds()) {
throw new Error(
`maxAgeInSeconds must be greater than the DateProvider threshold value -> ${DateProvider.getThresholdInSeconds()}`
);
Expand Down Expand Up @@ -179,7 +179,7 @@ export class PrimitiveArrayClaim<ValueType> {
id?: string
): SessionClaimValidator => {
const DateProvider = DateProviderReference.getReferenceOrThrow().dateProvider;
if (maxAgeInSeconds && maxAgeInSeconds < DateProvider.getThresholdInSeconds()) {
if (maxAgeInSeconds !== undefined && maxAgeInSeconds < DateProvider.getThresholdInSeconds()) {
throw new Error(
`maxAgeInSeconds must be greater than the DateProvider threshold value -> ${DateProvider.getThresholdInSeconds()}`
);
Expand Down Expand Up @@ -231,7 +231,7 @@ export class PrimitiveArrayClaim<ValueType> {
id?: string
): SessionClaimValidator => {
const DateProvider = DateProviderReference.getReferenceOrThrow().dateProvider;
if (maxAgeInSeconds && maxAgeInSeconds < DateProvider.getThresholdInSeconds()) {
if (maxAgeInSeconds !== undefined && maxAgeInSeconds < DateProvider.getThresholdInSeconds()) {
throw new Error(
`maxAgeInSeconds must be greater than the DateProvider threshold value -> ${DateProvider.getThresholdInSeconds()}`
);
Expand Down
2 changes: 1 addition & 1 deletion lib/ts/claims/primitiveClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class PrimitiveClaim<ValueType> {
id?: string
): SessionClaimValidator => {
const DateProvider = DateProviderReference.getReferenceOrThrow().dateProvider;
if (maxAgeInSeconds && maxAgeInSeconds < DateProvider.getThresholdInSeconds()) {
if (maxAgeInSeconds !== undefined && maxAgeInSeconds < DateProvider.getThresholdInSeconds()) {
throw new Error(
`maxAgeInSeconds must be greater than the DateProvider threshold value -> ${DateProvider.getThresholdInSeconds()}`
);
Expand Down
2 changes: 1 addition & 1 deletion lib/ts/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ export const updateClockSkewUsingFrontToken = ({
}

const frontTokenPayload = parseFrontToken(frontToken);
const clockSkewInMillis = AuthHttpRequest.recipeImpl.getClockSkewInMillis({
const clockSkewInMillis = AuthHttpRequest.recipeImpl.calculateClockSkewInMillis({
accessTokenPayload: frontTokenPayload.up,
responseHeaders
});
Expand Down
8 changes: 4 additions & 4 deletions lib/ts/recipeImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,25 +311,25 @@ export default function RecipeImplementation(recipeImplInput: {
}
},

getClockSkewInMillis: function ({
calculateClockSkewInMillis: function ({
accessTokenPayload
}: {
accessTokenPayload: any;
responseHeaders: Headers;
}): number {
logDebugMessage("getClockSkewInMillis: called");
logDebugMessage("calculateClockSkewInMillis: called");

const tokenIssuedAt = accessTokenPayload?.iat;
if (tokenIssuedAt === undefined || typeof tokenIssuedAt !== "number") {
logDebugMessage(
`getClockSkewInMillis: payload iat is undefined or not a number. This may happen due to an unsupported backend sdk. Returning 0`
`calculateClockSkewInMillis: payload iat is undefined or not a number. This may happen due to an unsupported backend sdk. Returning 0`
);
return 0;
}

const estimatedServerTimeNow = tokenIssuedAt * 1000;
const clockSkewInMillis = estimatedServerTimeNow - Date.now();
logDebugMessage("getClockSkewInMillis: returning " + clockSkewInMillis);
logDebugMessage("calculateClockSkewInMillis: returning " + clockSkewInMillis);

return clockSkewInMillis;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export type RecipeInterface = {
sessionTokenBackendDomain: string | undefined
): boolean;

getClockSkewInMillis(params: { accessTokenPayload: any; responseHeaders: Headers }): number;
calculateClockSkewInMillis(params: { accessTokenPayload: any; responseHeaders: Headers }): number;
};

export type ClaimValidationResult = { isValid: true } | { isValid: false; reason?: any };
Expand Down
4 changes: 4 additions & 0 deletions lib/ts/utils/dateProvider/defaultImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export class DateProvider {
return this.thresholdInSeconds;
}

setThresholdInSeconds(thresholdInSeconds: number): void {
this.thresholdInSeconds = thresholdInSeconds;
}

setClientClockSkewInMillis(clockSkewInMillis: number): void {
this.clockSkewInMillis = Math.abs(clockSkewInMillis) > this.thresholdInSeconds * 1000 ? clockSkewInMillis : 0;
const localStorage = WindowHandlerReference.getReferenceOrThrow().windowHandler.localStorage;
Expand Down
1 change: 1 addition & 0 deletions lib/ts/utils/dateProvider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

export interface DateProviderInterface {
getThresholdInSeconds(): number;
setThresholdInSeconds(thresholdInSeconds: number): void;
now(): number;
setClientClockSkewInMillis(clockSkewInMillis: number): void;
getClientClockSkewInMillis(): number;
Expand Down
7 changes: 3 additions & 4 deletions test/interception.claims.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ addGenericTestCases((name, transferMethod, setupFunc, setupArgs = []) => {
{
// enableDebugLogs: true,
// This isn't used in all tests but it only produces some extra logs
override: ["log_getClockSkewInMillis"]
override: ["log_calculateClockSkewInMillis"]
},
...setupArgs
);
Expand Down Expand Up @@ -338,13 +338,12 @@ addGenericTestCases((name, transferMethod, setupFunc, setupArgs = []) => {
}
});

it("should call getClockSkewInMillis with appropriate headers", async function () {
it("should call calculateClockSkewInMillis with appropriate headers", async function () {
await startST();
let clockSkewParams = [];
page.on("console", ev => {
const text = ev.text();
// console.log(text);
const key = "TEST_getClockSkewInMillis$";
const key = "TEST_calculateClockSkewInMillis$";
if (text.startsWith(key)) {
clockSkewParams.push(JSON.parse(text.substr(key.length)));
}
Expand Down
Loading

0 comments on commit 95f0d03

Please sign in to comment.