Skip to content

Commit

Permalink
Add support for fetching permissions JWT claim (#53)
Browse files Browse the repository at this point in the history
Add permissions support.
  • Loading branch information
mattgd authored Jul 15, 2024
1 parent 6166ec4 commit 2c31be5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface UserInfo {
sessionId: string;
organizationId?: string;
role?: string;
permissions?: string[];
impersonator?: Impersonator;
accessToken: string;
}
Expand All @@ -36,6 +37,7 @@ export interface AccessToken {
sid: string;
org_id?: string;
role?: string;
permissions?: string[];
}

export interface GetAuthURLOptions {
Expand Down
5 changes: 3 additions & 2 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,14 @@ async function getUser({ ensureSignedIn = false } = {}) {
return { user: null };
}

const { sid: sessionId, org_id: organizationId, role } = decodeJwt<AccessToken>(session.accessToken);
const { sid: sessionId, org_id: organizationId, role, permissions } = decodeJwt<AccessToken>(session.accessToken);

return {
sessionId,
user: session.user,
organizationId,
role,
permissions,
impersonator: session.impersonator,
accessToken: session.accessToken,
};
Expand Down Expand Up @@ -205,4 +206,4 @@ async function getSessionFromHeader(caller: string): Promise<Session | undefined
return unsealData<Session>(authHeader, { password: WORKOS_COOKIE_PASSWORD });
}

export { encryptSession, updateSession, getUser, terminateSession };
export { encryptSession, getUser, terminateSession, updateSession };

0 comments on commit 2c31be5

Please sign in to comment.