@@ -96,7 +96,25 @@ export class EdgeClient extends AbstractClient {
96
96
const [ as , client ] = await this . getClient ( ) ;
97
97
98
98
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
+ } ) ;
100
118
const result = await oauth . processPushedAuthorizationResponse ( as , client , response ) ;
101
119
if ( oauth . isOAuth2Error ( result ) ) {
102
120
throw new IdentityProviderError ( {
@@ -163,7 +181,14 @@ export class EdgeClient extends AbstractClient {
163
181
checks . code_verifier as string ,
164
182
{
165
183
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
+ } ) ,
167
192
...this . httpOptions ( )
168
193
}
169
194
) ;
@@ -233,8 +258,25 @@ export class EdgeClient extends AbstractClient {
233
258
234
259
async refresh ( refreshToken : string , extras : { exchangeBody : Record < string , any > } ) : Promise < TokenEndpointResponse > {
235
260
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
+
236
270
const res = await oauth . refreshTokenGrantRequest ( as , client , refreshToken , {
237
271
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
+ } ) ,
238
280
...this . httpOptions ( )
239
281
} ) ;
240
282
const result = await oauth . processRefreshTokenResponse ( as , client , res ) ;
0 commit comments