@@ -89,13 +89,11 @@ export class DefaultDPoPProvider implements DPoPProvider {
8989 try {
9090 const jwt = await this . plugin . signWithDPoPPrivateKey ( kid , payload ) ;
9191 return jwt ;
92- } catch ( _ : unknown ) {
93- // Generate a new key if the original key cannot be used for any reason
94- kid = await this . plugin . generateUUID ( ) ;
95- await this . plugin . createDPoPPrivateKey ( kid ) ;
96- await this . sharedStorage . setDPoPKeyID ( this . getNamespace ( ) , kid ) ;
97- const jwt = await this . plugin . signWithDPoPPrivateKey ( kid , payload ) ;
98- return jwt ;
92+ } catch ( e : unknown ) {
93+ // Clear the existing key ID if the key cannot be used for any reason
94+ await this . sharedStorage . delDPoPKeyID ( this . getNamespace ( ) ) ;
95+ // rethrow the error so we know there is some error occurred
96+ throw e ;
9997 }
10098 }
10199
@@ -106,21 +104,21 @@ export class DefaultDPoPProvider implements DPoPProvider {
106104 const existingKeyId = await this . sharedStorage . getDPoPKeyID (
107105 this . getNamespace ( )
108106 ) ;
109- let kid : string | null = null ;
110- if ( existingKeyId != null ) {
111- const existingKeyOK = await this . plugin . checkDPoPPrivateKey (
112- existingKeyId
113- ) ;
114- if ( existingKeyOK ) {
115- kid = existingKeyId ;
116- }
117- }
107+ let kid : string | null = existingKeyId ;
118108 if ( kid == null ) {
119109 kid = await this . plugin . generateUUID ( ) ;
120110 await this . plugin . createDPoPPrivateKey ( kid ) ;
121111 await this . sharedStorage . setDPoPKeyID ( this . getNamespace ( ) , kid ) ;
122112 }
123- const jkt = await this . plugin . computeDPoPJKT ( kid ) ;
124- return jkt ;
113+
114+ try {
115+ const jkt = await this . plugin . computeDPoPJKT ( kid ) ;
116+ return jkt ;
117+ } catch ( e : unknown ) {
118+ // Clear the existing key ID if the key cannot be used for any reason
119+ await this . sharedStorage . delDPoPKeyID ( this . getNamespace ( ) ) ;
120+ // rethrow the error so we know there is some error occurred
121+ throw e ;
122+ }
125123 }
126124}
0 commit comments