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

realm: Add session room property to realm JWTs #2058

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions packages/matrix/tests/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ test.describe('Login', () => {
let claims = jwt.verify(token, REALM_SECRET_SEED) as {
user: string;
realm: string;
sessionRoom: string;
permissions: ('read' | 'write' | 'realm-owner')[];
};
expect(claims.user).toStrictEqual('@user1:localhost');
expect(claims.realm).toStrictEqual(`${appURL}/`);
expect(claims.sessionRoom).toMatch(/!\w*:localhost/);
expect(claims.permissions).toMatchObject(['read', 'write']);

// reload to page to show that the access token persists
Expand Down
10 changes: 9 additions & 1 deletion packages/realm-server/tests/realm-server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ let createJWT = (
user: string,
permissions: RealmPermissions['user'] = [],
) => {
return realm.createJWT({ user, realm: realm.url, permissions }, '7d');
return realm.createJWT(
{
user,
realm: realm.url,
permissions,
sessionRoom: `test-session-room-for-${user}`,
},
'7d',
);
};

module(basename(__filename), function () {
Expand Down
4 changes: 3 additions & 1 deletion packages/runtime-common/realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export interface FileRef {
export interface TokenClaims {
user: string;
realm: string;
sessionRoom: string;
permissions: RealmPermissions['user'];
}

Expand Down Expand Up @@ -654,7 +655,7 @@ export class Realm {
requestContext,
});
},
createJWT: async (user: string) => {
createJWT: async (user: string, sessionRoom: string) => {
let permissions = requestContext.permissions;

let userPermissions = await new RealmPermissionChecker(
Expand All @@ -666,6 +667,7 @@ export class Realm {
{
user,
realm: this.url,
sessionRoom,
permissions: userPermissions,
},
'7d',
Expand Down
Loading