fix(oauth): correct OAuth implementation to match bunq documentation
This commit is contained in:
@@ -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)');
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user