Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(clerk-js, clerk-react,types): Rename assurance to reverification #4268

Merged
merged 7 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/purple-goats-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@clerk/clerk-js": minor
"@clerk/shared": minor
"@clerk/clerk-react": minor
"@clerk/types": minor
---

Rename `__experimental_assurance` to `__experimental_reverification`.

- Supported levels are now are `firstFactor`, `secondFactor`, `multiFactor`.
- Support maxAge is now replaced by maxAgeMinutes and afterMinutes depending on usage.
- Introduced `____experimental_SessionVerificationTypes` that abstracts away the level and maxAge
- Allowed values 'veryStrict' | 'strict' | 'moderate' | 'lax'
2 changes: 1 addition & 1 deletion packages/clerk-js/bundlewatch.config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"files": [
{ "path": "./dist/clerk.browser.js", "maxSize": "65kB" },
{ "path": "./dist/clerk.browser.js", "maxSize": "64.5kB" },
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be working on UI components, and i want to closely monitor this change. Lowering the limit will help with that.

{ "path": "./dist/clerk.headless.js", "maxSize": "43kB" },
{ "path": "./dist/ui-common*.js", "maxSize": "86KB" },
{ "path": "./dist/vendors*.js", "maxSize": "70KB" },
Expand Down
4 changes: 2 additions & 2 deletions packages/clerk-js/src/core/resources/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ export class Session extends BaseResource implements SessionResource {

__experimental_startVerification = async ({
level,
maxAge,
maxAgeMinutes,
}: __experimental_SessionVerifyCreateParams): Promise<__experimental_SessionVerificationResource> => {
const json = (
await BaseResource._fetch({
method: 'POST',
path: `/client/sessions/${this.id}/verify`,
body: {
level,
maxAge,
maxAgeMinutes,
} as any,
})
)?.response as unknown as __experimental_SessionVerificationJSON;
Expand Down
172 changes: 101 additions & 71 deletions packages/clerk-js/src/core/resources/__tests__/Session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ describe('Session', () => {

const isAuthorized = session.checkAuthorization({
permission: 'org:sys_profile:delete',
__experimental_assurance: {
level: 'L2.secondFactor',
maxAge: 'A1.10min',
__experimental_reverification: {
level: 'multiFactor',
afterMinutes: 10,
},
});

Expand All @@ -338,9 +338,9 @@ describe('Session', () => {

const isAuthorized = session.checkAuthorization({
permission: 'org:sys_profile:delete',
__experimental_assurance: {
level: 'L2.secondFactor',
maxAge: 'A1.10min',
__experimental_reverification: {
level: 'multiFactor',
afterMinutes: 10,
},
});

Expand All @@ -362,9 +362,9 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
level: 'L2.secondFactor',
maxAge: 'A1.10min',
__experimental_reverification: {
level: 'multiFactor',
afterMinutes: 10,
},
});

Expand All @@ -386,9 +386,9 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
level: 'L2.secondFactor',
maxAge: 'A1.10min',
__experimental_reverification: {
level: 'multiFactor',
afterMinutes: 10,
},
});

Expand All @@ -410,9 +410,9 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
level: 'L1.firstFactor',
maxAge: 'A1.10min',
__experimental_reverification: {
level: 'multiFactor',
afterMinutes: 10,
},
});

Expand All @@ -434,9 +434,9 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
level: 'L1.firstFactor',
maxAge: 'A1.10min',
__experimental_reverification: {
level: 'multiFactor',
afterMinutes: 10,
},
});

Expand All @@ -458,9 +458,9 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
level: 'L2.secondFactor',
maxAge: 'A1.10min',
__experimental_reverification: {
level: 'multiFactor',
afterMinutes: 10,
},
});

Expand All @@ -482,10 +482,7 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
level: 'L2.secondFactor',
maxAge: 'A1.10min',
},
__experimental_reverification: 'strict',
});

expect(isAuthorized).toBe(false);
Expand All @@ -506,10 +503,7 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
level: 'L3.multiFactor',
maxAge: 'A1.10min',
},
__experimental_reverification: 'veryStrict',
});

expect(isAuthorized).toBe(true);
Expand All @@ -530,9 +524,9 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
level: 'L3.multiFactor',
maxAge: 'A1.10min',
__experimental_reverification: {
level: 'multiFactor',
afterMinutes: 10,
},
});

Expand All @@ -554,9 +548,9 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
level: 'L3.multiFactor',
maxAge: 'A1.10min',
__experimental_reverification: {
level: 'multiFactor',
afterMinutes: 10,
},
});

Expand All @@ -578,9 +572,9 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
level: 'L3.multiFactor',
maxAge: 'A1.10min',
__experimental_reverification: {
level: 'multiFactor',
afterMinutes: 10,
},
});

Expand All @@ -602,9 +596,9 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
level: 'L3.multiFactor',
maxAge: 'A1.10min',
__experimental_reverification: {
level: 'multiFactor',
afterMinutes: 10,
},
});

Expand All @@ -626,9 +620,9 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
level: 'L3.multiFactor',
maxAge: 'A1.10min',
__experimental_reverification: {
level: 'multiFactor',
afterMinutes: 10,
},
});

Expand All @@ -650,9 +644,9 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
level: 'L1.firstFactor',
maxAge: 'A1.10min',
__experimental_reverification: {
level: 'firstFactor',
afterMinutes: 10,
},
});

Expand All @@ -674,10 +668,7 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
level: 'L2.secondFactor',
maxAge: 'A1.10min',
},
__experimental_reverification: 'strict',
});

expect(isAuthorized).toBe(false);
Expand All @@ -686,7 +677,7 @@ describe('Session', () => {
/**
* Test for invalid input
*/
it('incorrect params for __experimental_assurance', async () => {
it('incorrect params for __experimental_reverification', async () => {
const session = new Session({
status: 'active',
id: 'session_1',
Expand All @@ -701,17 +692,17 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
__experimental_reverification: {
//@ts-expect-error
level: 'any level',
maxAge: 'A1.10min',
afterMinutes: 10,
},
});

expect(isAuthorized).toBe(false);
});

it('incorrect params for __experimental_assurance', async () => {
it('incorrect params for __experimental_reverification', async () => {
const session = new Session({
status: 'active',
id: 'session_1',
Expand All @@ -726,18 +717,39 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
__experimental_reverification: {
//@ts-expect-error
level: 'any level',
//@ts-expect-error
maxAge: 'som-value',
afterMinutes: 'some-value',
},
});

expect(isAuthorized).toBe(false);
});

it('incorrect params for __experimental_assurance', async () => {
it('incorrect params for __experimental_reverification', async () => {
const session = new Session({
status: 'active',
id: 'session_1',
object: 'session',
user: createUser(),
last_active_organization_id: null,
last_active_token: { object: 'token', jwt: mockJwt },
actor: null,
created_at: new Date().getTime(),
updated_at: new Date().getTime(),
factor_verification_age: [0, 0],
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_reverification: 'invalid-value',
});

expect(isAuthorized).toBe(false);
});

it('incorrect params for __experimental_reverification', async () => {
const session = new Session({
status: 'active',
id: 'session_1',
Expand All @@ -752,10 +764,31 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
level: 'L1.firstFactor',
__experimental_reverification: 123,
});

expect(isAuthorized).toBe(false);
});

it('incorrect params for __experimental_reverification', async () => {
const session = new Session({
status: 'active',
id: 'session_1',
object: 'session',
user: createUser(),
last_active_organization_id: null,
last_active_token: { object: 'token', jwt: mockJwt },
actor: null,
created_at: new Date().getTime(),
updated_at: new Date().getTime(),
factor_verification_age: [0, 0],
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_reverification: {
level: 'firstFactor',
//@ts-expect-error
maxAge: 100,
afterMinutes: '10',
},
});

Expand All @@ -780,9 +813,9 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
level: 'L3.multiFactor',
maxAge: 'A1.10min',
__experimental_reverification: {
level: 'multiFactor',
afterMinutes: 10,
},
});

Expand All @@ -804,9 +837,9 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
level: 'L1.firstFactor',
maxAge: 'A1.10min',
__experimental_reverification: {
level: 'firstFactor',
afterMinutes: 10,
},
});

Expand All @@ -828,10 +861,7 @@ describe('Session', () => {
} as SessionJSON);

const isAuthorized = session.checkAuthorization({
__experimental_assurance: {
level: 'L2.secondFactor',
maxAge: 'A1.10min',
},
__experimental_reverification: 'strict',
});

expect(isAuthorized).toBe(true);
Expand Down
Loading
Loading