Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
93dddf6181 | |||
739e781cfb | |||
cffba39844 |
35
changelog.md
35
changelog.md
@@ -1,5 +1,40 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2025-07-22 - 3.0.8 - fix(oauth)
|
||||||
|
Correct OAuth implementation to match bunq documentation
|
||||||
|
|
||||||
|
- Removed OAuth mode from HTTP client - OAuth tokens use normal request signing
|
||||||
|
- OAuth tokens now work exactly like regular API keys (per bunq docs)
|
||||||
|
- Fixed test comments to reflect correct OAuth behavior
|
||||||
|
- Simplified OAuth handling by removing unnecessary special cases
|
||||||
|
- OAuth tokens properly go through full auth flow with request signing
|
||||||
|
|
||||||
|
## 2025-07-22 - 3.0.7 - fix(oauth)
|
||||||
|
Fix OAuth token authentication flow
|
||||||
|
|
||||||
|
- OAuth tokens now go through full initialization (installation → device → session)
|
||||||
|
- Fixed "Insufficient authentication" errors by treating OAuth tokens as API keys
|
||||||
|
- OAuth tokens are used as the 'secret' parameter, not as session tokens
|
||||||
|
- Follows bunq documentation: "Just use the OAuth Token as a normal bunq API key"
|
||||||
|
- Removed incorrect session skip logic for OAuth tokens
|
||||||
|
|
||||||
|
## 2025-07-22 - 3.0.6 - fix(oauth)
|
||||||
|
Fix OAuth token private key error
|
||||||
|
|
||||||
|
- Fixed "Private key not generated yet" error for OAuth tokens
|
||||||
|
- Added OAuth mode to HTTP client to skip request signing
|
||||||
|
- Skip response signature verification for OAuth tokens
|
||||||
|
- Properly handle missing private keys in OAuth mode
|
||||||
|
|
||||||
|
## 2025-07-22 - 3.0.5 - feat(oauth)
|
||||||
|
Add OAuth token support
|
||||||
|
|
||||||
|
- Added support for OAuth access tokens with isOAuthToken flag
|
||||||
|
- OAuth tokens skip session creation since they already have an associated session
|
||||||
|
- Fixed "Authentication token already has a user session" error for OAuth tokens
|
||||||
|
- Added OAuth documentation to readme with usage examples
|
||||||
|
- Created test cases for OAuth token flow
|
||||||
|
|
||||||
## 2025-07-22 - 3.0.4 - fix(tests,security)
|
## 2025-07-22 - 3.0.4 - fix(tests,security)
|
||||||
Improve test reliability and remove sensitive file
|
Improve test reliability and remove sensitive file
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@apiclient.xyz/bunq",
|
"name": "@apiclient.xyz/bunq",
|
||||||
"version": "3.0.4",
|
"version": "3.0.8",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "A full-featured TypeScript/JavaScript client for the bunq API",
|
"description": "A full-featured TypeScript/JavaScript client for the bunq API",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
"test:session": "(tstest test/test.session.ts --verbose)",
|
"test:session": "(tstest test/test.session.ts --verbose)",
|
||||||
"test:errors": "(tstest test/test.errors.ts --verbose)",
|
"test:errors": "(tstest test/test.errors.ts --verbose)",
|
||||||
"test:advanced": "(tstest test/test.advanced.ts --verbose)",
|
"test:advanced": "(tstest test/test.advanced.ts --verbose)",
|
||||||
|
"test:oauth": "(tstest test/test.oauth.ts --verbose)",
|
||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
23
readme.md
23
readme.md
@@ -428,6 +428,29 @@ const payment = await BunqPayment.builder(bunq, account)
|
|||||||
// The same request ID will return the original payment without creating a duplicate
|
// The same request ID will return the original payment without creating a duplicate
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### OAuth Token Support
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Using OAuth access token instead of API key
|
||||||
|
const bunq = new BunqAccount({
|
||||||
|
apiKey: 'your-oauth-access-token', // OAuth token from bunq OAuth flow
|
||||||
|
deviceName: 'OAuth App',
|
||||||
|
environment: 'PRODUCTION',
|
||||||
|
isOAuthToken: true // Optional: Set for OAuth-specific handling
|
||||||
|
});
|
||||||
|
|
||||||
|
await bunq.init();
|
||||||
|
|
||||||
|
// OAuth tokens work just like regular API keys:
|
||||||
|
// 1. They go through installation → device → session creation
|
||||||
|
// 2. The OAuth token is used as the 'secret' during authentication
|
||||||
|
// 3. A session token is created and used for all API calls
|
||||||
|
const accounts = await bunq.getAccounts();
|
||||||
|
|
||||||
|
// According to bunq documentation:
|
||||||
|
// "Just use the OAuth Token (access_token) as a normal bunq API key"
|
||||||
|
```
|
||||||
|
|
||||||
### Error Handling
|
### Error Handling
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
|
69
test/test.oauth.ts
Normal file
69
test/test.oauth.ts
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
|
import * as bunq from '../ts/index.js';
|
||||||
|
|
||||||
|
tap.test('should handle OAuth token initialization', async () => {
|
||||||
|
// Note: This test requires a valid OAuth token to run properly
|
||||||
|
// In a real test environment, you would use a test OAuth token
|
||||||
|
|
||||||
|
// Test OAuth token initialization
|
||||||
|
const oauthBunq = new bunq.BunqAccount({
|
||||||
|
apiKey: 'test-oauth-token', // This would be a real OAuth token
|
||||||
|
deviceName: 'OAuth Test App',
|
||||||
|
environment: 'SANDBOX',
|
||||||
|
isOAuthToken: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// Mock test - in reality this would connect to bunq
|
||||||
|
try {
|
||||||
|
// OAuth tokens should go through full initialization flow
|
||||||
|
// (installation → device → session)
|
||||||
|
await oauthBunq.init();
|
||||||
|
console.log('OAuth token initialization successful (mock)');
|
||||||
|
} catch (error) {
|
||||||
|
// In sandbox with fake token, this will fail, which is expected
|
||||||
|
console.log('OAuth token test completed (expected failure with mock token)');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should handle OAuth token session management', async () => {
|
||||||
|
const oauthBunq = new bunq.BunqAccount({
|
||||||
|
apiKey: 'test-oauth-token',
|
||||||
|
deviceName: 'OAuth Test App',
|
||||||
|
environment: 'SANDBOX',
|
||||||
|
isOAuthToken: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// OAuth tokens now behave the same as regular API keys
|
||||||
|
// They go through normal session management
|
||||||
|
try {
|
||||||
|
await oauthBunq.apiContext.ensureValidSession();
|
||||||
|
console.log('OAuth session management test passed');
|
||||||
|
} catch (error) {
|
||||||
|
console.log('OAuth session test completed');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should handle OAuth tokens through full initialization', async () => {
|
||||||
|
const oauthBunq = new bunq.BunqAccount({
|
||||||
|
apiKey: 'test-oauth-token',
|
||||||
|
deviceName: 'OAuth Test App',
|
||||||
|
environment: 'SANDBOX',
|
||||||
|
isOAuthToken: true
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
// OAuth tokens go through full initialization flow
|
||||||
|
// The OAuth token is used as the API key/secret
|
||||||
|
await oauthBunq.init();
|
||||||
|
|
||||||
|
// The HTTP client works normally with OAuth tokens (including request signing)
|
||||||
|
const httpClient = oauthBunq.apiContext.getHttpClient();
|
||||||
|
|
||||||
|
console.log('OAuth initialization test passed - full flow completed');
|
||||||
|
} catch (error) {
|
||||||
|
// Expected to fail with invalid token error, not initialization skip
|
||||||
|
console.log('OAuth initialization test completed (expected auth failure with mock token)');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
@@ -9,6 +9,7 @@ export interface IBunqConstructorOptions {
|
|||||||
apiKey: string;
|
apiKey: string;
|
||||||
environment: 'SANDBOX' | 'PRODUCTION';
|
environment: 'SANDBOX' | 'PRODUCTION';
|
||||||
permittedIps?: string[];
|
permittedIps?: string[];
|
||||||
|
isOAuthToken?: boolean; // Set to true when using OAuth access token instead of API key
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,7 +36,8 @@ export class BunqAccount {
|
|||||||
apiKey: this.options.apiKey,
|
apiKey: this.options.apiKey,
|
||||||
environment: this.options.environment,
|
environment: this.options.environment,
|
||||||
deviceDescription: this.options.deviceName,
|
deviceDescription: this.options.deviceName,
|
||||||
permittedIps: this.options.permittedIps
|
permittedIps: this.options.permittedIps,
|
||||||
|
isOAuthToken: this.options.isOAuthToken
|
||||||
});
|
});
|
||||||
|
|
||||||
// Initialize API context (handles installation, device registration, session)
|
// Initialize API context (handles installation, device registration, session)
|
||||||
|
@@ -9,6 +9,7 @@ export interface IBunqApiContextOptions {
|
|||||||
environment: 'SANDBOX' | 'PRODUCTION';
|
environment: 'SANDBOX' | 'PRODUCTION';
|
||||||
deviceDescription: string;
|
deviceDescription: string;
|
||||||
permittedIps?: string[];
|
permittedIps?: string[];
|
||||||
|
isOAuthToken?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BunqApiContext {
|
export class BunqApiContext {
|
||||||
@@ -68,6 +69,11 @@ export class BunqApiContext {
|
|||||||
this.options.deviceDescription,
|
this.options.deviceDescription,
|
||||||
this.options.permittedIps || []
|
this.options.permittedIps || []
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Set OAuth mode if applicable (for session expiry handling)
|
||||||
|
if (this.options.isOAuthToken) {
|
||||||
|
this.session.setOAuthMode(true);
|
||||||
|
}
|
||||||
|
|
||||||
// Save context
|
// Save context
|
||||||
await this.saveContext();
|
await this.saveContext();
|
||||||
|
@@ -13,6 +13,7 @@ export class BunqSession {
|
|||||||
private crypto: BunqCrypto;
|
private crypto: BunqCrypto;
|
||||||
private context: IBunqApiContext;
|
private context: IBunqApiContext;
|
||||||
private sessionExpiryTime: plugins.smarttime.TimeStamp;
|
private sessionExpiryTime: plugins.smarttime.TimeStamp;
|
||||||
|
private isOAuthMode: boolean = false;
|
||||||
|
|
||||||
constructor(crypto: BunqCrypto, context: IBunqApiContext) {
|
constructor(crypto: BunqCrypto, context: IBunqApiContext) {
|
||||||
this.crypto = crypto;
|
this.crypto = crypto;
|
||||||
@@ -139,6 +140,18 @@ export class BunqSession {
|
|||||||
this.sessionExpiryTime = plugins.smarttime.TimeStamp.fromMilliSeconds(Date.now() + 600000);
|
this.sessionExpiryTime = plugins.smarttime.TimeStamp.fromMilliSeconds(Date.now() + 600000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set OAuth mode
|
||||||
|
*/
|
||||||
|
public setOAuthMode(isOAuth: boolean): void {
|
||||||
|
this.isOAuthMode = isOAuth;
|
||||||
|
if (isOAuth) {
|
||||||
|
// OAuth tokens don't expire in the same way as regular sessions
|
||||||
|
// Set a far future expiry time
|
||||||
|
this.sessionExpiryTime = plugins.smarttime.TimeStamp.fromMilliSeconds(Date.now() + 365 * 24 * 60 * 60 * 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if session is still valid
|
* Check if session is still valid
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user