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

fix(core): issue organization_id claim for client credentials #6170

Merged
merged 1 commit into from
Jul 3, 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
4 changes: 3 additions & 1 deletion packages/core/src/oidc/extra-token-claims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
return;
}

const isAccessToken = token instanceof ctx.oidc.provider.AccessToken;
const isAccessToken =
token instanceof ctx.oidc.provider.AccessToken ||
token instanceof ctx.oidc.provider.ClientCredentials;

Check warning on line 39 in packages/core/src/oidc/extra-token-claims.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/oidc/extra-token-claims.ts#L37-L39

Added lines #L37 - L39 were not covered by tests

// Only handle access tokens
if (!isAccessToken) {
Expand Down Expand Up @@ -115,7 +117,7 @@
? { tokenType: LogtoJwtTokenKeyType.ClientCredentials }
: {
tokenType: LogtoJwtTokenKeyType.AccessToken,
// TODO (LOG-8555): the newly added `UserProfile` type includes undefined fields and can not be directly assigned to `Json` type. And the `undefined` fields should be removed by zod guard.

Check warning on line 120 in packages/core/src/oidc/extra-token-claims.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/core/src/oidc/extra-token-claims.ts#L120

[no-warning-comments] Unexpected 'todo' comment: 'TODO (LOG-8555): the newly added...'.
// `context` parameter is only eligible for user's access token for now.
// eslint-disable-next-line no-restricted-syntax
context: { user: logtoUserInfo as Record<string, Json> },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ describe('client credentials grant', () => {
expect(returnedScope).toBe(`${scope1.name} ${scope2.name}`);

const verified = await jwtVerify(accessToken, jwkSet, { audience: resource.indicator });
expect(verified.payload.organization_id).toBe(organization.id);
expect(verified.payload.scope).toBe(`${scope1.name} ${scope2.name}`);
});

Expand Down Expand Up @@ -271,6 +272,7 @@ describe('client credentials grant', () => {
expect(returnedScope1).toBe(scope1.name);

const verified1 = await jwtVerify(accessToken1, jwkSet, { audience: resource.indicator });
expect(verified1.payload.organization_id).toBe(organization.id);
expect(verified1.payload.scope).toBe(scope1.name);

const { access_token: accessToken2, scope: returnedScope2 } = await post({
Expand All @@ -281,6 +283,7 @@ describe('client credentials grant', () => {
expect(returnedScope2).toBe(undefined);

const verified2 = await jwtVerify(accessToken2, jwkSet, { audience: resource.indicator });
expect(verified1.payload.organization_id).toBe(organization.id);
expect(verified2.payload.scope).toBe(undefined);
});
});
Expand Down
Loading