Skip to content

Commit 3c128ac

Browse files
Propagate DPoP error
ref DEV-3091
2 parents c651b4e + 87dec16 commit 3c128ac

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

packages/authgear-capacitor/android/src/main/java/com/authgear/capacitor/AuthgearPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ private Integer readColorInt(PluginCall call, String key) {
493493
}
494494

495495
private void reject(PluginCall call, Exception e) {
496-
call.reject(e.getMessage(), e.getClass().getName(), e);
496+
call.reject(e.getLocalizedMessage(), e.getClass().getName(), e);
497497
}
498498

499499
private void rejectWithCancel(PluginCall call) {

packages/authgear-capacitor/src/error.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ export function _wrapError(e: unknown): unknown {
173173
return err;
174174
}
175175
}
176-
const err = new AuthgearError();
176+
const message = typeof e === "object" ? (e as any).message : "";
177+
const err = new AuthgearError(message);
177178
err.underlyingError = e;
178179
return err;
179180
}

packages/authgear-core/src/dpop.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)