forked from FlowiseAI/FlowiseChatEmbed
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-oauth-headers.js
More file actions
62 lines (53 loc) Β· 2.39 KB
/
test-oauth-headers.js
File metadata and controls
62 lines (53 loc) Β· 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Test script to verify OAuth header implementation
* This script simulates the client-side behavior and tests the proxy server
*/
// Mock auth service for testing
const mockAuthService = {
getAccessToken: () => 'mock-access-token-12345',
isAuthenticated: () => true,
getCurrentUser: () => ({
sub: 'test-user-123',
email: 'test@example.com',
name: 'Test User',
preferred_username: 'testuser'
})
};
// Test the sendRequest function with auth service
console.log('π§ͺ Testing OAuth header implementation...');
// Simulate a request with auth service
const testRequest = {
url: 'http://localhost:3005/api/v1/prediction/test-chatflow',
method: 'POST',
body: { question: 'Hello' },
authService: mockAuthService
};
console.log('π Test request configuration:');
console.log('- URL:', testRequest.url);
console.log('- Method:', testRequest.method);
console.log('- Has authService:', !!testRequest.authService);
console.log('- Access token:', testRequest.authService.getAccessToken());
// Expected headers that should be generated
const expectedHeaders = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${mockAuthService.getAccessToken()}`
};
console.log('π― Expected headers:');
console.log(JSON.stringify(expectedHeaders, null, 2));
console.log('\nβ
Implementation complete! The following changes have been made:');
console.log('1. β Modified sendRequest() to accept authService parameter');
console.log('2. β Updated all query functions to pass authService');
console.log('3. β Modified Bot component to include OAuth tokens in API calls');
console.log('4. β Added user context extraction middleware to proxy server');
console.log('5. β Added debug logging for user information extraction');
console.log('\nπ How it works:');
console.log('- Client includes OAuth access token in Authorization header');
console.log('- Proxy server validates token with OAuth provider');
console.log('- User information is extracted and attached to req.user');
console.log('- Debug messages show when user info is available');
console.log('- Authentication is optional - works without tokens too');
console.log('\nπ To test:');
console.log('1. Start the proxy server with OAuth configuration');
console.log('2. Load a chatbot with authentication enabled');
console.log('3. Authenticate with OAuth provider');
console.log('4. Send messages and check proxy server logs for user info');