fix(oauth): correct OAuth implementation to match bunq documentation

This commit is contained in:
2025-07-22 21:56:10 +00:00
parent 739e781cfb
commit 93dddf6181
7 changed files with 51 additions and 70 deletions

View File

@@ -10,20 +10,12 @@ export class BunqHttpClient {
private crypto: BunqCrypto;
private context: IBunqApiContext;
private requestCounter: number = 0;
private isOAuthMode: boolean = false;
constructor(crypto: BunqCrypto, context: IBunqApiContext) {
this.crypto = crypto;
this.context = context;
}
/**
* Set OAuth mode
*/
public setOAuthMode(isOAuth: boolean): void {
this.isOAuthMode = isOAuth;
}
/**
* Update the API context (used after getting session token)
*/
@@ -44,20 +36,13 @@ export class BunqHttpClient {
const body = options.body ? JSON.stringify(options.body) : undefined;
// Add signature if required
// Skip signing for OAuth tokens or if explicitly disabled
if (options.useSigning !== false && !this.isOAuthMode) {
try {
const privateKey = this.crypto.getPrivateKey();
headers['X-Bunq-Client-Signature'] = this.crypto.createSignatureHeader(
options.method,
options.endpoint,
headers,
body || ''
);
} catch (error) {
// If no private key is available (e.g., OAuth mode), skip signing
// This is expected for OAuth tokens
}
if (options.useSigning !== false && this.crypto.getPrivateKey()) {
headers['X-Bunq-Client-Signature'] = this.crypto.createSignatureHeader(
options.method,
options.endpoint,
headers,
body || ''
);
}
// Make the request
@@ -81,8 +66,7 @@ export class BunqHttpClient {
const response = await plugins.smartrequest.request(url, requestOptions);
// Verify response signature if we have server public key
// Skip verification for OAuth tokens as they don't have installation keys
if (this.context.serverPublicKey && !this.isOAuthMode) {
if (this.context.serverPublicKey) {
// Convert headers to string-only format
const stringHeaders: { [key: string]: string } = {};
for (const [key, value] of Object.entries(response.headers)) {