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

Function authenticateOAuthBearer

apps/host-selfhost/src/mcp/auth.ts:223–233  ·  view source on GitHub ↗
(request: Request)

Source from the content-addressed store, hash-verified

221
222 /** (a) The mcp() OAuth opaque bearer, with self-enforced expiry. */
223 const authenticateOAuthBearer = (request: Request): Effect.Effect<Principal | null> =>
224 Effect.gen(function* () {
225 const session = yield* Effect.promise(() =>
226 auth.api.getMcpSession({ headers: request.headers }),
227 );
228 if (!session) return null;
229 // GOTCHA: getMcpSession does NOT validate accessTokenExpiresAt — an
230 // expired token still resolves. Reject it here.
231 if (new Date(session.accessTokenExpiresAt).getTime() < Date.now()) return null;
232 return yield* principalFromUserId(session.userId);
233 }).pipe(Effect.orElseSucceed(() => null));
234
235 /** (b) The existing cookie / bearer-session / x-api-key path. The fallback's
236 * api `Principal` shape is byte-identical to host-mcp's `Principal`. */

Callers 1

authenticateFunction · 0.85

Calls 1

principalFromUserIdFunction · 0.85

Tested by

no test coverage detected