MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / runOAuthCallback

Function runOAuthCallback

packages/core/api/src/oauth-popup.ts:192–241  ·  view source on GitHub ↗
(
  input: RunOAuthCallbackInput<TAuth, E, R>,
)

Source from the content-addressed store, hash-verified

190 * can still render and close itself.
191 */
192export const runOAuthCallback = <TAuth, E, R>(
193 input: RunOAuthCallbackInput<TAuth, E, R>,
194): Effect.Effect<string, never, R> => {
195 const providerError = providerErrorMessage(input.urlParams);
196 const callbackState = decodeOAuthCallbackState(input.urlParams.state);
197 const sessionId = callbackState?.state ?? input.urlParams.state;
198 const result =
199 providerError == null
200 ? input
201 .complete({
202 state: sessionId,
203 code: input.urlParams.code ?? null,
204 error: null,
205 callbackDomain: input.urlParams.domain ?? input.urlParams.site ?? null,
206 })
207 .pipe(
208 Effect.map(
209 (auth): OAuthPopupResult<TAuth> => ({
210 type: OAUTH_POPUP_MESSAGE_TYPE,
211 ok: true,
212 sessionId,
213 ...auth,
214 }),
215 ),
216 )
217 : Effect.succeed<OAuthPopupResult<TAuth>>({
218 type: OAUTH_POPUP_MESSAGE_TYPE,
219 ok: false,
220 sessionId,
221 error: providerError.short,
222 ...(providerError.details ? { errorDetails: providerError.details } : {}),
223 });
224
225 return result.pipe(
226 Effect.catchCause((cause) => {
227 const { short, details } = input.toErrorMessage(Cause.squash(cause));
228 return Effect.succeed<OAuthPopupResult<TAuth>>({
229 type: OAUTH_POPUP_MESSAGE_TYPE,
230 ok: false,
231 sessionId,
232 error: short,
233 ...(details && details !== short ? { errorDetails: details } : {}),
234 });
235 }),
236 Effect.tap((result) =>
237 Effect.sync(() => completionListener?.(result as OAuthPopupResult<unknown>)),
238 ),
239 Effect.map((result) => popupDocument(result, input.channelName)),
240 );
241};

Callers 2

oauth.tsFile · 0.90

Calls 5

decodeOAuthCallbackStateFunction · 0.90
providerErrorMessageFunction · 0.85
popupDocumentFunction · 0.85
completeMethod · 0.80
syncMethod · 0.65

Tested by

no test coverage detected