MCPcopy Create free account
hub / github.com/microsoft/data-formulator / handler

Function handler

src/views/DBTableManager.tsx:193–237  ·  view source on GitHub ↗
(event: MessageEvent)

Source from the content-addressed store, hash-verified

191 }
192
193 const handler = async (event: MessageEvent) => {
194 if (event.data?.type !== 'df-sso-auth') return;
195 window.removeEventListener('message', handler);
196 if (pollTimerRef.current) { clearInterval(pollTimerRef.current); pollTimerRef.current = null; }
197 popup.close();
198
199 const { access_token, refresh_token, user } = event.data;
200 if (access_token) {
201 try {
202 // Persist token in TokenStore for Agent and future requests
203 await apiRequest('/api/auth/tokens/save', {
204 method: 'POST',
205 headers: { 'Content-Type': 'application/json' },
206 body: JSON.stringify({
207 system_id: connectorIdRef.current,
208 access_token,
209 refresh_token,
210 user,
211 }),
212 }).catch(() => {});
213
214 // Send tokens to backend token-connect endpoint
215 const { data: connectData } = await apiRequest<any>(CONNECTOR_ACTION_URLS.CONNECT, {
216 method: 'POST',
217 headers: { 'Content-Type': 'application/json' },
218 body: JSON.stringify({
219 connector_id: connectorIdRef.current,
220 mode: 'token',
221 access_token,
222 refresh_token,
223 user,
224 params: mergedParams, // include any filled-in params (e.g. url)
225 persist: persistCredentials,
226 }),
227 });
228 if (connectData.status !== 'connected') {
229 throw new Error(extractConnectError(connectData, 'Token connection failed'));
230 }
231 onConnected?.();
232 } catch (err: any) {
233 onFinish("error", err.message || 'Login failed');
234 }
235 }
236 setIsConnecting(false);
237 };
238
239 window.addEventListener('message', handler);
240

Callers

nothing calls this directly

Calls 3

apiRequestFunction · 0.90
extractConnectErrorFunction · 0.85
closeMethod · 0.45

Tested by

no test coverage detected