@@ -6,8 +6,16 @@ export interface ConnectorAuthStatus {
6
6
}
7
7
8
8
// Fetches the authentication status for a given connector type
9
- export async function getConnectorAuthStatus ( apiBaseUrl : string , connectorType : string ) : Promise < ConnectorAuthStatus > {
10
- const response = await fetch ( `${ apiBaseUrl } /ee/connectors/${ connectorType } /auth_status` ) ;
9
+ export async function getConnectorAuthStatus (
10
+ apiBaseUrl : string ,
11
+ connectorType : string ,
12
+ authToken : string | null
13
+ ) : Promise < ConnectorAuthStatus > {
14
+ const response = await fetch ( `${ apiBaseUrl } /ee/connectors/${ connectorType } /auth_status` , {
15
+ headers : {
16
+ ...( authToken ? { Authorization : `Bearer ${ authToken } ` } : { } ) ,
17
+ } ,
18
+ } ) ;
11
19
if ( ! response . ok ) {
12
20
const errorData = await response . json ( ) . catch ( ( ) => ( { } ) ) ;
13
21
throw new Error (
@@ -19,7 +27,14 @@ export async function getConnectorAuthStatus(apiBaseUrl: string, connectorType:
19
27
20
28
// Initiates the authentication process by redirecting the user
21
29
// The backend will handle the actual redirect to the OAuth provider
22
- export function initiateConnectorAuth ( apiBaseUrl : string , connectorType : string , appRedirectUri : string ) : void {
30
+ export function initiateConnectorAuth (
31
+ apiBaseUrl : string ,
32
+ connectorType : string ,
33
+ appRedirectUri : string
34
+ // authToken is not typically needed for the initiation step if it's a redirect-based flow
35
+ // and the backend establishes session/cookie upon callback.
36
+ // If token IS needed by this specific /initiate endpoint, it would be added here.
37
+ ) : void {
23
38
// The backend /auth/initiate endpoint itself performs a redirect.
24
39
// So, navigating to it will trigger the OAuth flow.
25
40
// We add the app_redirect_uri for the backend to use after successful callback.
@@ -29,11 +44,16 @@ export function initiateConnectorAuth(apiBaseUrl: string, connectorType: string,
29
44
}
30
45
31
46
// Disconnects a connector for the current user
32
- export async function disconnectConnector ( apiBaseUrl : string , connectorType : string ) : Promise < void > {
47
+ export async function disconnectConnector (
48
+ apiBaseUrl : string ,
49
+ connectorType : string ,
50
+ authToken : string | null
51
+ ) : Promise < void > {
33
52
const response = await fetch ( `${ apiBaseUrl } /ee/connectors/${ connectorType } /disconnect` , {
34
53
method : "POST" ,
35
54
headers : {
36
55
"Content-Type" : "application/json" ,
56
+ ...( authToken ? { Authorization : `Bearer ${ authToken } ` } : { } ) ,
37
57
} ,
38
58
} ) ;
39
59
if ( ! response . ok ) {
@@ -59,6 +79,7 @@ export interface ConnectorFile {
59
79
export async function listConnectorFiles (
60
80
apiBaseUrl : string ,
61
81
connectorType : string ,
82
+ authToken : string | null ,
62
83
path : string | null ,
63
84
pageToken ?: string ,
64
85
q_filter ?: string ,
@@ -81,7 +102,7 @@ export async function listConnectorFiles(
81
102
method : "GET" ,
82
103
headers : {
83
104
"Content-Type" : "application/json" ,
84
- // TODO: Add authorization headers if required by your API setup
105
+ ... ( authToken ? { Authorization : `Bearer ${ authToken } ` } : { } ) ,
85
106
} ,
86
107
} ) ;
87
108
@@ -103,6 +124,7 @@ interface IngestionOptions {
103
124
export async function ingestConnectorFile (
104
125
apiBaseUrl : string ,
105
126
connectorType : string ,
127
+ authToken : string | null ,
106
128
fileId : string ,
107
129
// Replace displayName with ingestionOptions
108
130
options ?: IngestionOptions
@@ -121,7 +143,7 @@ export async function ingestConnectorFile(
121
143
method : "POST" ,
122
144
headers : {
123
145
"Content-Type" : "application/json" ,
124
- // TODO: Add authorization headers if required
146
+ ... ( authToken ? { Authorization : `Bearer ${ authToken } ` } : { } ) ,
125
147
} ,
126
148
body : JSON . stringify ( body ) ,
127
149
} ) ;
0 commit comments