Skip to content

Commit bc08a13

Browse files
frederikprijckpanvatusharpandey13
committed
refactor: use a single client assertion audience (#2024)
Co-authored-by: Filip Skokan <[email protected]> Co-authored-by: Tushar Pandey <[email protected]> Co-authored-by: Tushar Pandey <[email protected]>
1 parent f0292ec commit bc08a13

File tree

3 files changed

+59
-16
lines changed

3 files changed

+59
-16
lines changed

package-lock.json

Lines changed: 13 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@
125125
"debug": "^4.3.4",
126126
"joi": "^17.6.0",
127127
"jose": "^4.15.5",
128-
"oauth4webapi": "^2.3.0",
129-
"openid-client": "^5.6.5",
128+
"oauth4webapi": "^2.17.0",
129+
"openid-client": "^5.7.1",
130130
"tslib": "^2.4.0",
131131
"url-join": "^4.0.1"
132132
},

src/auth0-session/client/edge-client.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,25 @@ export class EdgeClient extends AbstractClient {
9696
const [as, client] = await this.getClient();
9797

9898
if (this.config.pushedAuthorizationRequests) {
99-
const response = await oauth.pushedAuthorizationRequest(as, client, parameters as Record<string, string>);
99+
const { clientAssertionSigningKey, clientAssertionSigningAlg } = this.config;
100+
101+
let clientPrivateKey = clientAssertionSigningKey as CryptoKey | undefined;
102+
/* c8 ignore next 3 */
103+
if (clientPrivateKey && !(clientPrivateKey instanceof CryptoKey)) {
104+
clientPrivateKey = await jose.importPKCS8<CryptoKey>(clientPrivateKey, clientAssertionSigningAlg || 'RS256');
105+
}
106+
107+
const response = await oauth.pushedAuthorizationRequest(as, client, parameters as Record<string, string>, {
108+
...(clientPrivateKey && {
109+
clientPrivateKey,
110+
[oauth.modifyAssertion](_header: Record<string, oauth.JsonValue>, payload: Record<string, oauth.JsonValue>) {
111+
if (Array.isArray(payload.aud)) {
112+
payload.aud = as.issuer;
113+
}
114+
}
115+
}),
116+
...this.httpOptions()
117+
});
100118
const result = await oauth.processPushedAuthorizationResponse(as, client, response);
101119
if (oauth.isOAuth2Error(result)) {
102120
throw new IdentityProviderError({
@@ -163,7 +181,14 @@ export class EdgeClient extends AbstractClient {
163181
checks.code_verifier as string,
164182
{
165183
additionalParameters: extras.exchangeBody,
166-
...(clientPrivateKey && { clientPrivateKey }),
184+
...(clientPrivateKey && {
185+
clientPrivateKey,
186+
[oauth.modifyAssertion](_header: Record<string, oauth.JsonValue>, payload: Record<string, oauth.JsonValue>) {
187+
if (Array.isArray(payload.aud)) {
188+
payload.aud = as.issuer;
189+
}
190+
}
191+
}),
167192
...this.httpOptions()
168193
}
169194
);
@@ -233,8 +258,25 @@ export class EdgeClient extends AbstractClient {
233258

234259
async refresh(refreshToken: string, extras: { exchangeBody: Record<string, any> }): Promise<TokenEndpointResponse> {
235260
const [as, client] = await this.getClient();
261+
262+
const { clientAssertionSigningKey, clientAssertionSigningAlg } = this.config;
263+
264+
let clientPrivateKey = clientAssertionSigningKey as CryptoKey | undefined;
265+
/* c8 ignore next 3 */
266+
if (clientPrivateKey && !(clientPrivateKey instanceof CryptoKey)) {
267+
clientPrivateKey = await jose.importPKCS8<CryptoKey>(clientPrivateKey, clientAssertionSigningAlg || 'RS256');
268+
}
269+
236270
const res = await oauth.refreshTokenGrantRequest(as, client, refreshToken, {
237271
additionalParameters: extras.exchangeBody,
272+
...(clientPrivateKey && {
273+
clientPrivateKey,
274+
[oauth.modifyAssertion](_header: Record<string, oauth.JsonValue>, payload: Record<string, oauth.JsonValue>) {
275+
if (Array.isArray(payload.aud)) {
276+
payload.aud = as.issuer;
277+
}
278+
}
279+
}),
238280
...this.httpOptions()
239281
});
240282
const result = await oauth.processRefreshTokenResponse(as, client, res);

0 commit comments

Comments
 (0)