-
Notifications
You must be signed in to change notification settings - Fork 474
feat(backend): expose the normalized act claim on verified OAuth access tokens #9929
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clerk/backend': minor | ||
| --- | ||
|
|
||
| Verified OAuth access tokens now expose `act`, the RFC 8693 actor chain, when the token was issued by an OAuth 2.0 Token Exchange. It is available on the `IdPOAuthAccessToken` returned for both opaque and JWT access tokens. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -280,6 +280,69 @@ describe('tokens.verifyMachineAuthToken(token, options)', () => { | |
| expect(data.aud).toEqual(aud); | ||
| }); | ||
|
|
||
| describe.each(['opaque', 'at+jwt', 'application/at+jwt'] as const)('%s OAuth token actor', format => { | ||
| const chainedAct = { | ||
| iss: 'https://clerk.oauth.example.test', | ||
| sub: 'client_exchanging', | ||
| act: { iss: 'https://clerk.oauth.example.test', sub: 'client_subject' }, | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| vi.setSystemTime(new Date(mockOAuthAccessTokenJwtPayload.iat * 1000)); | ||
| }); | ||
|
|
||
| async function verifyWithAct(act: unknown) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value Declare the helper’s return type. Set the return type of 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| let token: string; | ||
| if (format === 'opaque') { | ||
| token = 'oat_8XOIucKvqHVr5tYP123456789abcdefghij'; | ||
| server.use( | ||
| http.post('https://api.clerk.test/oauth_applications/access_tokens/verify', () => | ||
| HttpResponse.json({ | ||
| object: 'clerk_idp_oauth_access_token', | ||
| ...mockVerificationResults.oauth_token, | ||
| ...(act === undefined ? {} : { act }), | ||
| }), | ||
| ), | ||
| ); | ||
| } else { | ||
| server.use(http.get('https://api.clerk.test/v1/jwks', () => HttpResponse.json(mockJwks))); | ||
| token = await createSignedOAuthJwt({ ...mockOAuthAccessTokenJwtPayload, act }, format); | ||
| } | ||
|
|
||
| const result = await verifyMachineAuthToken(token, { | ||
| apiUrl: 'https://api.clerk.test', | ||
| secretKey: 'a-valid-key', | ||
| }); | ||
|
|
||
| expect(result.errors).toBeUndefined(); | ||
| return (result.data as IdPOAuthAccessToken).act; | ||
| } | ||
|
|
||
| it.each([{ act: undefined }, { act: { sub: 'client_exchanging' } }, { act: chainedAct }])( | ||
| 'returns act=$act', | ||
| async ({ act }) => { | ||
| expect(await verifyWithAct(act)).toEqual(act); | ||
| }, | ||
| ); | ||
|
|
||
| it('keeps only iss, sub, and one nested actor', async () => { | ||
| const act = await verifyWithAct({ | ||
| ...chainedAct, | ||
| extra: 'dropped', | ||
| act: { ...chainedAct.act, extra: 'dropped', act: { sub: 'client_deeper' } }, | ||
| }); | ||
|
|
||
| expect(act).toStrictEqual(chainedAct); | ||
| }); | ||
|
|
||
| it.each([{ act: 'client_exchanging' }, { act: { iss: 'https://clerk.oauth.example.test' } }, { act: { sub: 42 } }])( | ||
| 'drops malformed act=$act', | ||
| async ({ act }) => { | ||
| expect(await verifyWithAct(act)).toBeUndefined(); | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| describe.each(['opaque', 'at+jwt', 'application/at+jwt'] as const)('%s OAuth token audience verification', format => { | ||
| const audience = 'https://resource.example.com'; | ||
| const otherAudience = 'https://other.example.com'; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
Declare the new public property explicitly.
Add
publicto theactparameter property. As per coding guidelines, “Usepublicexplicitly for clarity in public APIs.”🤖 Prompt for AI Agents
Source: Coding guidelines