Skip to content

Commit 3921759

Browse files
authored
Add entitlements to claims available from access token (#32)
1 parent c214c3a commit 3921759

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ export const loader = (args: LoaderFunctionArgs) => authkitLoader(args);
8282
export function App() {
8383

8484
// Retrieves the user from the session or returns `null` if no user is signed in
85-
// Other supported values include sessionId, accessToken, organizationId, role, permissions, impersonator and oauthTokens
85+
// Other supported values include sessionId, accessToken, organizationId,
86+
// role, permissions, entitlements, impersonator and oauthTokens
8687
const { user, signInUrl, signUpUrl } = useLoaderData<typeof loader>();
8788

8889
return (

src/interfaces.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface AccessToken {
2323
org_id?: string;
2424
role?: string;
2525
permissions?: string[];
26+
entitlements?: string[];
2627
}
2728

2829
export interface GetAuthURLOptions {
@@ -42,6 +43,7 @@ export interface AuthorizedData {
4243
organizationId: string | null;
4344
role: string | null;
4445
permissions: string[];
46+
entitlements: string[];
4547
impersonator: Impersonator | null;
4648
oauthTokens: OauthTokens | null;
4749
sealedSession: string;
@@ -54,6 +56,7 @@ export interface UnauthorizedData {
5456
organizationId: null;
5557
role: null;
5658
permissions: null;
59+
entitlements: null;
5760
impersonator: null;
5861
oauthTokens: null;
5962
sealedSession: null;

src/session.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ async function authkitLoader<Data = unknown>(
133133
oauthTokens: null,
134134
organizationId: null,
135135
permissions: null,
136+
entitlements: null,
136137
role: null,
137138
sessionId: null,
138139
sealedSession: null,
@@ -146,6 +147,7 @@ async function authkitLoader<Data = unknown>(
146147
organizationId = null,
147148
role = null,
148149
permissions = [],
150+
entitlements = [],
149151
} = getClaimsFromAccessToken(session.accessToken);
150152

151153
const cookieSession = await getSession(request.headers.get('Cookie'));
@@ -157,6 +159,7 @@ async function authkitLoader<Data = unknown>(
157159
organizationId,
158160
role,
159161
permissions,
162+
entitlements,
160163
impersonator: session.impersonator ?? null,
161164
oauthTokens: session.oauthTokens ?? null,
162165
sealedSession: cookieSession.get('jwt'),
@@ -227,13 +230,20 @@ async function terminateSession(request: Request) {
227230
}
228231

229232
function getClaimsFromAccessToken(accessToken: string) {
230-
const { sid: sessionId, org_id: organizationId, role, permissions } = decodeJwt<AccessToken>(accessToken);
233+
const {
234+
sid: sessionId,
235+
org_id: organizationId,
236+
role,
237+
permissions,
238+
entitlements,
239+
} = decodeJwt<AccessToken>(accessToken);
231240

232241
return {
233242
sessionId,
234243
organizationId,
235244
role,
236245
permissions,
246+
entitlements,
237247
};
238248
}
239249

0 commit comments

Comments
 (0)