Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
9011390dc4 | |||
76c6b95f3d | |||
1ffe02df16 | |||
93dddf6181 |
38
changelog.md
38
changelog.md
@@ -1,5 +1,43 @@
|
||||
# Changelog
|
||||
|
||||
## 2025-07-22 - 3.1.1 - fix(oauth)
|
||||
Fix OAuth token authentication flow for existing installations
|
||||
|
||||
- Fixed initWithExistingInstallation to properly create new sessions with existing installation/device
|
||||
- OAuth tokens now correctly skip installation/device steps when they already exist
|
||||
- Session creation still uses OAuth token as the secret parameter
|
||||
- Properly handles "Superfluous authentication" errors by reusing existing installation
|
||||
- Renamed initWithExistingSession to initWithExistingInstallation for clarity
|
||||
|
||||
## 2025-07-22 - 3.1.0 - feat(oauth)
|
||||
Add OAuth session caching to prevent multiple authentication attempts
|
||||
|
||||
- Implemented static OAuth session cache in BunqAccount class
|
||||
- Added automatic session reuse for OAuth tokens across multiple instances
|
||||
- Added handling for "Superfluous authentication" and "Authentication token already has a user session" errors
|
||||
- Added initWithExistingSession() method to reuse OAuth tokens as session tokens
|
||||
- Added cache management methods: clearOAuthCache(), clearOAuthCacheForToken(), getOAuthCacheSize()
|
||||
- Added hasValidSession() method to check session validity
|
||||
- OAuth tokens now properly cache and reuse sessions to prevent authentication conflicts
|
||||
|
||||
## 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
|
||||
|
||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@apiclient.xyz/bunq",
|
||||
"version": "3.0.1",
|
||||
"version": "3.0.9",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@apiclient.xyz/bunq",
|
||||
"version": "3.0.1",
|
||||
"version": "3.0.9",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@bunq-community/bunq-js-client": "^1.1.2",
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@apiclient.xyz/bunq",
|
||||
"version": "3.0.6",
|
||||
"version": "3.1.1",
|
||||
"private": false,
|
||||
"description": "A full-featured TypeScript/JavaScript client for the bunq API",
|
||||
"type": "module",
|
||||
|
41
readme.md
41
readme.md
@@ -436,17 +436,48 @@ const bunq = new BunqAccount({
|
||||
apiKey: 'your-oauth-access-token', // OAuth token from bunq OAuth flow
|
||||
deviceName: 'OAuth App',
|
||||
environment: 'PRODUCTION',
|
||||
isOAuthToken: true // Important: Set this flag for OAuth tokens
|
||||
isOAuthToken: true // Optional: Set for OAuth-specific handling
|
||||
});
|
||||
|
||||
await bunq.init();
|
||||
|
||||
// OAuth tokens already have an associated session from the OAuth flow,
|
||||
// so the library will skip session creation and use the token directly
|
||||
// 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();
|
||||
|
||||
// Note: OAuth tokens have their own expiry mechanism managed by bunq's OAuth server
|
||||
// The library will not attempt to refresh OAuth tokens
|
||||
// According to bunq documentation:
|
||||
// "Just use the OAuth Token (access_token) as a normal bunq API key"
|
||||
|
||||
// OAuth Session Caching (v3.0.9+)
|
||||
// The library automatically caches OAuth sessions to prevent multiple authentication attempts
|
||||
|
||||
// Multiple instances with the same OAuth token will reuse the cached session
|
||||
const bunq1 = new BunqAccount({
|
||||
apiKey: 'your-oauth-access-token',
|
||||
deviceName: 'OAuth App Instance 1',
|
||||
environment: 'PRODUCTION',
|
||||
isOAuthToken: true
|
||||
});
|
||||
|
||||
const bunq2 = new BunqAccount({
|
||||
apiKey: 'your-oauth-access-token', // Same token
|
||||
deviceName: 'OAuth App Instance 2',
|
||||
environment: 'PRODUCTION',
|
||||
isOAuthToken: true
|
||||
});
|
||||
|
||||
await bunq1.init(); // Creates new session
|
||||
await bunq2.init(); // Reuses cached session from bunq1
|
||||
|
||||
// This prevents "Superfluous authentication" errors when multiple instances
|
||||
// try to authenticate with the same OAuth token
|
||||
|
||||
// Cache management methods
|
||||
BunqAccount.clearOAuthCache(); // Clear all cached OAuth sessions
|
||||
BunqAccount.clearOAuthCacheForToken('token', 'PRODUCTION'); // Clear specific token
|
||||
const cacheSize = BunqAccount.getOAuthCacheSize(); // Get current cache size
|
||||
```
|
||||
|
||||
### Error Handling
|
||||
|
105
test/test.oauth.caching.ts
Normal file
105
test/test.oauth.caching.ts
Normal file
@@ -0,0 +1,105 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as bunq from '../ts/index.js';
|
||||
|
||||
tap.test('should cache and reuse OAuth sessions', async () => {
|
||||
// Create first OAuth account instance
|
||||
const oauthBunq1 = new bunq.BunqAccount({
|
||||
apiKey: 'test-oauth-token-cache',
|
||||
deviceName: 'OAuth Test App 1',
|
||||
environment: 'SANDBOX',
|
||||
isOAuthToken: true
|
||||
});
|
||||
|
||||
// Create second OAuth account instance with same token
|
||||
const oauthBunq2 = new bunq.BunqAccount({
|
||||
apiKey: 'test-oauth-token-cache',
|
||||
deviceName: 'OAuth Test App 2',
|
||||
environment: 'SANDBOX',
|
||||
isOAuthToken: true
|
||||
});
|
||||
|
||||
try {
|
||||
// Initialize first instance
|
||||
await oauthBunq1.init();
|
||||
console.log('First OAuth instance initialized');
|
||||
|
||||
// Check cache size
|
||||
const cacheSize1 = bunq.BunqAccount.getOAuthCacheSize();
|
||||
console.log(`Cache size after first init: ${cacheSize1}`);
|
||||
|
||||
// Initialize second instance - should reuse cached session
|
||||
await oauthBunq2.init();
|
||||
console.log('Second OAuth instance should have reused cached session');
|
||||
|
||||
// Both instances should share the same API context
|
||||
expect(oauthBunq1.apiContext).toEqual(oauthBunq2.apiContext);
|
||||
|
||||
// Cache size should still be 1
|
||||
const cacheSize2 = bunq.BunqAccount.getOAuthCacheSize();
|
||||
expect(cacheSize2).toEqual(1);
|
||||
|
||||
} catch (error) {
|
||||
// Expected to fail with invalid token, but we can test the caching logic
|
||||
console.log('OAuth caching test completed (expected auth failure with mock token)');
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should handle OAuth session cache clearing', async () => {
|
||||
// Create OAuth account instance
|
||||
const oauthBunq = new bunq.BunqAccount({
|
||||
apiKey: 'test-oauth-token-clear',
|
||||
deviceName: 'OAuth Test App',
|
||||
environment: 'SANDBOX',
|
||||
isOAuthToken: true
|
||||
});
|
||||
|
||||
try {
|
||||
await oauthBunq.init();
|
||||
} catch (error) {
|
||||
// Expected failure with mock token
|
||||
}
|
||||
|
||||
// Clear specific token from cache
|
||||
bunq.BunqAccount.clearOAuthCacheForToken('test-oauth-token-clear', 'SANDBOX');
|
||||
|
||||
// Clear all OAuth cache
|
||||
bunq.BunqAccount.clearOAuthCache();
|
||||
|
||||
// Cache should be empty
|
||||
const cacheSize = bunq.BunqAccount.getOAuthCacheSize();
|
||||
expect(cacheSize).toEqual(0);
|
||||
|
||||
console.log('OAuth cache clearing test passed');
|
||||
});
|
||||
|
||||
tap.test('should handle different OAuth tokens separately', async () => {
|
||||
const oauthBunq1 = new bunq.BunqAccount({
|
||||
apiKey: 'test-oauth-token-1',
|
||||
deviceName: 'OAuth Test App 1',
|
||||
environment: 'SANDBOX',
|
||||
isOAuthToken: true
|
||||
});
|
||||
|
||||
const oauthBunq2 = new bunq.BunqAccount({
|
||||
apiKey: 'test-oauth-token-2',
|
||||
deviceName: 'OAuth Test App 2',
|
||||
environment: 'SANDBOX',
|
||||
isOAuthToken: true
|
||||
});
|
||||
|
||||
try {
|
||||
await oauthBunq1.init();
|
||||
await oauthBunq2.init();
|
||||
} catch (error) {
|
||||
// Expected failures with mock tokens
|
||||
}
|
||||
|
||||
// Should have 2 different cached sessions
|
||||
const cacheSize = bunq.BunqAccount.getOAuthCacheSize();
|
||||
console.log(`Cache size with different tokens: ${cacheSize}`);
|
||||
|
||||
// Clear cache for cleanup
|
||||
bunq.BunqAccount.clearOAuthCache();
|
||||
});
|
||||
|
||||
tap.start();
|
@@ -15,7 +15,8 @@ tap.test('should handle OAuth token initialization', async () => {
|
||||
|
||||
// Mock test - in reality this would connect to bunq
|
||||
try {
|
||||
// The init should skip session creation for OAuth tokens
|
||||
// OAuth tokens should go through full initialization flow
|
||||
// (installation → device → session)
|
||||
await oauthBunq.init();
|
||||
console.log('OAuth token initialization successful (mock)');
|
||||
} catch (error) {
|
||||
@@ -24,7 +25,7 @@ tap.test('should handle OAuth token initialization', async () => {
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should not attempt session refresh for OAuth tokens', async () => {
|
||||
tap.test('should handle OAuth token session management', async () => {
|
||||
const oauthBunq = new bunq.BunqAccount({
|
||||
apiKey: 'test-oauth-token',
|
||||
deviceName: 'OAuth Test App',
|
||||
@@ -32,7 +33,8 @@ tap.test('should not attempt session refresh for OAuth tokens', async () => {
|
||||
isOAuthToken: true
|
||||
});
|
||||
|
||||
// Test that ensureValidSession doesn't try to refresh OAuth tokens
|
||||
// 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');
|
||||
@@ -41,7 +43,7 @@ tap.test('should not attempt session refresh for OAuth tokens', async () => {
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should handle OAuth tokens without private key errors', async () => {
|
||||
tap.test('should handle OAuth tokens through full initialization', async () => {
|
||||
const oauthBunq = new bunq.BunqAccount({
|
||||
apiKey: 'test-oauth-token',
|
||||
deviceName: 'OAuth Test App',
|
||||
@@ -50,21 +52,17 @@ tap.test('should handle OAuth tokens without private key errors', async () => {
|
||||
});
|
||||
|
||||
try {
|
||||
// Initialize (should skip session creation)
|
||||
// OAuth tokens go through full initialization flow
|
||||
// The OAuth token is used as the API key/secret
|
||||
await oauthBunq.init();
|
||||
|
||||
// Try to make a request (should skip signing)
|
||||
// This would have thrown "Private key not generated yet" before the fix
|
||||
// The HTTP client works normally with OAuth tokens (including request signing)
|
||||
const httpClient = oauthBunq.apiContext.getHttpClient();
|
||||
|
||||
// Test that HTTP client is in OAuth mode and won't try to sign
|
||||
console.log('OAuth HTTP client test passed - no private key errors');
|
||||
console.log('OAuth initialization test passed - full flow completed');
|
||||
} catch (error) {
|
||||
// Expected to fail with network/auth error, not private key error
|
||||
if (error.message && error.message.includes('Private key not generated')) {
|
||||
throw new Error('OAuth mode should not require private keys');
|
||||
}
|
||||
console.log('OAuth private key test completed (expected network failure)');
|
||||
// Expected to fail with invalid token error, not initialization skip
|
||||
console.log('OAuth initialization test completed (expected auth failure with mock token)');
|
||||
}
|
||||
});
|
||||
|
||||
|
@@ -2,6 +2,7 @@ import * as plugins from './bunq.plugins.js';
|
||||
import { BunqApiContext } from './bunq.classes.apicontext.js';
|
||||
import { BunqMonetaryAccount } from './bunq.classes.monetaryaccount.js';
|
||||
import { BunqUser } from './bunq.classes.user.js';
|
||||
import { BunqApiError } from './bunq.classes.httpclient.js';
|
||||
import type { IBunqSessionServerResponse } from './bunq.interfaces.js';
|
||||
|
||||
export interface IBunqConstructorOptions {
|
||||
@@ -16,6 +17,9 @@ export interface IBunqConstructorOptions {
|
||||
* the main bunq account
|
||||
*/
|
||||
export class BunqAccount {
|
||||
// Static cache for OAuth token sessions to prevent multiple authentication attempts
|
||||
private static oauthSessionCache = new Map<string, BunqApiContext>();
|
||||
|
||||
public options: IBunqConstructorOptions;
|
||||
public apiContext: BunqApiContext;
|
||||
public userId: number;
|
||||
@@ -31,7 +35,17 @@ export class BunqAccount {
|
||||
* Initialize the bunq account
|
||||
*/
|
||||
public async init() {
|
||||
// Create API context
|
||||
// For OAuth tokens, check if we already have a cached session
|
||||
if (this.options.isOAuthToken) {
|
||||
const cacheKey = `${this.options.apiKey}_${this.options.environment}`;
|
||||
const cachedContext = BunqAccount.oauthSessionCache.get(cacheKey);
|
||||
|
||||
if (cachedContext && cachedContext.hasValidSession()) {
|
||||
// Reuse existing session
|
||||
this.apiContext = cachedContext;
|
||||
console.log('Reusing existing OAuth session from cache');
|
||||
} else {
|
||||
// Create new context and cache it
|
||||
this.apiContext = new BunqApiContext({
|
||||
apiKey: this.options.apiKey,
|
||||
environment: this.options.environment,
|
||||
@@ -40,8 +54,41 @@ export class BunqAccount {
|
||||
isOAuthToken: this.options.isOAuthToken
|
||||
});
|
||||
|
||||
// Initialize API context (handles installation, device registration, session)
|
||||
try {
|
||||
await this.apiContext.init();
|
||||
// Cache the successfully initialized context
|
||||
BunqAccount.oauthSessionCache.set(cacheKey, this.apiContext);
|
||||
} catch (error) {
|
||||
// Handle "Superfluous authentication" or "Authentication token already has a user session" errors
|
||||
if (error instanceof BunqApiError) {
|
||||
const errorMessages = error.errors.map(e => e.error_description).join(' ');
|
||||
if (errorMessages.includes('Superfluous authentication') ||
|
||||
errorMessages.includes('Authentication token already has a user session')) {
|
||||
console.log('OAuth token already has installation/device, attempting to create new session...');
|
||||
// Try to create a new session with existing installation/device
|
||||
await this.apiContext.initWithExistingInstallation();
|
||||
// Cache the context with new session
|
||||
BunqAccount.oauthSessionCache.set(cacheKey, this.apiContext);
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Regular API key flow
|
||||
this.apiContext = new BunqApiContext({
|
||||
apiKey: this.options.apiKey,
|
||||
environment: this.options.environment,
|
||||
deviceDescription: this.options.deviceName,
|
||||
permittedIps: this.options.permittedIps,
|
||||
isOAuthToken: this.options.isOAuthToken
|
||||
});
|
||||
|
||||
await this.apiContext.init();
|
||||
}
|
||||
|
||||
// Create user instance
|
||||
this.bunqUser = new BunqUser(this.apiContext);
|
||||
@@ -160,4 +207,28 @@ export class BunqAccount {
|
||||
this.apiContext = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the OAuth session cache
|
||||
*/
|
||||
public static clearOAuthCache(): void {
|
||||
BunqAccount.oauthSessionCache.clear();
|
||||
console.log('OAuth session cache cleared');
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear a specific OAuth token from the cache
|
||||
*/
|
||||
public static clearOAuthCacheForToken(apiKey: string, environment: 'SANDBOX' | 'PRODUCTION'): void {
|
||||
const cacheKey = `${apiKey}_${environment}`;
|
||||
BunqAccount.oauthSessionCache.delete(cacheKey);
|
||||
console.log(`OAuth session cache cleared for token in ${environment} environment`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current size of the OAuth cache
|
||||
*/
|
||||
public static getOAuthCacheSize(): number {
|
||||
return BunqAccount.oauthSessionCache.size;
|
||||
}
|
||||
}
|
||||
|
@@ -44,15 +44,6 @@ export class BunqApiContext {
|
||||
* Initialize the API context (installation, device, session)
|
||||
*/
|
||||
public async init(): Promise<void> {
|
||||
// If using OAuth token, skip session creation
|
||||
if (this.options.isOAuthToken) {
|
||||
// OAuth tokens already have an associated session
|
||||
this.context.sessionToken = this.options.apiKey;
|
||||
this.session = new BunqSession(this.crypto, this.context);
|
||||
this.session.setOAuthMode(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Try to load existing context
|
||||
const existingContext = await this.loadContext();
|
||||
|
||||
@@ -79,6 +70,11 @@ export class BunqApiContext {
|
||||
this.options.permittedIps || []
|
||||
);
|
||||
|
||||
// Set OAuth mode if applicable (for session expiry handling)
|
||||
if (this.options.isOAuthToken) {
|
||||
this.session.setOAuthMode(true);
|
||||
}
|
||||
|
||||
// Save context
|
||||
await this.saveContext();
|
||||
}
|
||||
@@ -135,11 +131,6 @@ export class BunqApiContext {
|
||||
* Refresh session if needed
|
||||
*/
|
||||
public async ensureValidSession(): Promise<void> {
|
||||
// OAuth tokens don't need session refresh
|
||||
if (this.options.isOAuthToken) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.session.refreshSession();
|
||||
await this.saveContext();
|
||||
}
|
||||
@@ -171,4 +162,58 @@ export class BunqApiContext {
|
||||
public getBaseUrl(): string {
|
||||
return this.context.baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the context has a valid session
|
||||
*/
|
||||
public hasValidSession(): boolean {
|
||||
return this.session && this.session.isSessionValid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize with existing installation and device (for OAuth tokens that already completed these steps)
|
||||
*/
|
||||
public async initWithExistingInstallation(): Promise<void> {
|
||||
// For OAuth tokens that already have installation/device but need a new session
|
||||
// We need to:
|
||||
// 1. Try to load existing installation/device info
|
||||
// 2. Create a new session using the OAuth token as the secret
|
||||
|
||||
const existingContext = await this.loadContext();
|
||||
|
||||
if (existingContext && existingContext.clientPrivateKey && existingContext.clientPublicKey) {
|
||||
// Restore crypto keys from previous installation
|
||||
this.crypto.setKeys(
|
||||
existingContext.clientPrivateKey,
|
||||
existingContext.clientPublicKey
|
||||
);
|
||||
|
||||
// Update context with existing installation data
|
||||
this.context = { ...this.context, ...existingContext };
|
||||
|
||||
// Create new session instance
|
||||
this.session = new BunqSession(this.crypto, this.context);
|
||||
|
||||
// Try to create a new session with the OAuth token
|
||||
try {
|
||||
await this.session.init(
|
||||
this.options.deviceDescription,
|
||||
this.options.permittedIps || [],
|
||||
true // skipInstallationAndDevice = true
|
||||
);
|
||||
|
||||
if (this.options.isOAuthToken) {
|
||||
this.session.setOAuthMode(true);
|
||||
}
|
||||
|
||||
await this.saveContext();
|
||||
console.log('Successfully created new session with existing installation');
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to create session with OAuth token: ${error.message}`);
|
||||
}
|
||||
} else {
|
||||
// No existing installation, fall back to full init
|
||||
throw new Error('No existing installation found, full initialization required');
|
||||
}
|
||||
}
|
||||
}
|
@@ -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();
|
||||
if (options.useSigning !== false && 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
|
||||
}
|
||||
}
|
||||
|
||||
// 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)) {
|
||||
|
@@ -24,14 +24,16 @@ export class BunqSession {
|
||||
/**
|
||||
* Initialize a new bunq API session
|
||||
*/
|
||||
public async init(deviceDescription: string, permittedIps: string[] = []): Promise<void> {
|
||||
public async init(deviceDescription: string, permittedIps: string[] = [], skipInstallationAndDevice: boolean = false): Promise<void> {
|
||||
if (!skipInstallationAndDevice) {
|
||||
// Step 1: Installation
|
||||
await this.createInstallation();
|
||||
|
||||
// Step 2: Device registration
|
||||
await this.registerDevice(deviceDescription, permittedIps);
|
||||
}
|
||||
|
||||
// Step 3: Session creation
|
||||
// Step 3: Session creation (always required)
|
||||
await this.createSession();
|
||||
}
|
||||
|
||||
@@ -149,8 +151,6 @@ export class BunqSession {
|
||||
// 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);
|
||||
// Also set OAuth mode on HTTP client
|
||||
this.httpClient.setOAuthMode(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,11 +158,6 @@ export class BunqSession {
|
||||
* Check if session is still valid
|
||||
*/
|
||||
public isSessionValid(): boolean {
|
||||
// OAuth tokens are always considered valid (they have their own expiry mechanism)
|
||||
if (this.isOAuthMode) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!this.sessionExpiryTime) {
|
||||
return false;
|
||||
}
|
||||
@@ -175,11 +170,6 @@ export class BunqSession {
|
||||
* Refresh the session if needed
|
||||
*/
|
||||
public async refreshSession(): Promise<void> {
|
||||
// OAuth tokens don't need session refresh
|
||||
if (this.isOAuthMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.isSessionValid()) {
|
||||
await this.createSession();
|
||||
}
|
||||
|
Reference in New Issue
Block a user