-
Notifications
You must be signed in to change notification settings - Fork 467
fix(shared): type JWT aud as string or string array #9585
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
5f57241
4cef528
0c52c1b
0f9e706
0769cad
91cdb88
b40da6d
0d3bfad
8c62389
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,6 @@ | ||
| --- | ||
| '@clerk/shared': minor | ||
| '@clerk/backend': minor | ||
| --- | ||
|
|
||
| Type the JWT `aud` claim as an optional `string | string[]` per RFC 7519 and expose it on verified OAuth JWT access tokens. Clerk-issued OAuth access tokens may include a single RFC 8707 resource URI as a string. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -962,6 +962,7 @@ export interface IdPOAuthAccessTokenJSON extends ClerkResourceJSON { | |
| expiration: number | null; | ||
| created_at: number; | ||
| updated_at: number; | ||
| aud?: string | string[]; | ||
|
Member
Author
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. 👀 This type change could use a second pair of eyes. |
||
| } | ||
|
|
||
| export interface BillingPayerJSON extends ClerkResourceJSON { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,6 +105,21 @@ describe('M2MToken', () => { | |
| expect(token.scopes).toEqual(['scope1', 'scope2', 'scope3']); | ||
| }); | ||
|
|
||
| it('seeds scopes from a string aud claim', () => { | ||
|
Member
Author
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. This is backfilling coverage from existing behavior |
||
| const payload = { | ||
| sub: 'mch_test', | ||
| exp: 1666648550, | ||
| iat: 1666648250, | ||
| jti: 'mt_test', | ||
| aud: 'https://my-resource.example.com', | ||
| }; | ||
|
|
||
| const token = M2MToken.fromJwtPayload(payload); | ||
|
|
||
| expect(token.scopes).toEqual(['https://my-resource.example.com']); | ||
| expect(token.claims).toEqual({ aud: 'https://my-resource.example.com' }); | ||
| }); | ||
|
|
||
| it('returns empty scopes when neither aud nor scopes present', () => { | ||
| const payload = { | ||
| sub: 'mch_test', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,6 +77,11 @@ export interface ClerkJWTClaims { | |
| */ | ||
| azp?: string; | ||
|
|
||
| /** | ||
| * JWT Audience - [RFC7519#section-4.1.3](https://tools.ietf.org/html/rfc7519#section-4.1.3). | ||
| */ | ||
| aud?: string | string[]; | ||
|
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. [MEDIUM] The absent- (The actual sink is — Comment generated with Claude with @dominic-clerk's supervision |
||
|
|
||
| /** | ||
| * JWT Actor - [RFC8693](https://www.rfc-editor.org/rfc/rfc8693.html#name-act-actor-claim). | ||
| */ | ||
|
|
||
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.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: clerk/javascript
Length of output: 32777
🏁 Script executed:
Repository: clerk/javascript
Length of output: 50373
🏁 Script executed:
Repository: clerk/javascript
Length of output: 50373
🏁 Script executed:
Repository: clerk/javascript
Length of output: 50373
Preserve
audinIdPOAuthAccessToken.fromJSON.IdPOAuthAccessTokenApi.verify()hydratesidp_oauth_access_tokenresponses throughIdPOAuthAccessToken.fromJSON(). That method omitsdata.aud, so scalar or array audiences are lost. Addaud?: string | string[]toIdPOAuthAccessTokenJSONand passdata.audto the constructor.🤖 Prompt for AI Agents