@@ -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