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

Function verifySealedSessionLocally

apps/cloud/src/auth/workos.ts:210–242  ·  view source on GitHub ↗
(
  sessionData: string,
  cookiePassword: string,
  jwks: CachedRemoteJWKSet,
)

Source from the content-addressed store, hash-verified

208 );
209
210const verifySealedSessionLocally = (
211 sessionData: string,
212 cookiePassword: string,
213 jwks: CachedRemoteJWKSet,
214): Effect.Effect<LocalSessionVerification, ServiceAdapterError> =>
215 Effect.gen(function* () {
216 const unsealed = yield* Effect.tryPromise({
217 try: () => unsealWorkOSSession(sessionData, cookiePassword),
218 catch: (cause) => new LocalSessionCookieError({ cause }),
219 }).pipe(
220 Effect.catchTag("LocalSessionCookieError", () => Effect.succeed(null as unknown | null)),
221 );
222 if (!unsealed) return { _tag: "InvalidCookie" };
223
224 const session = Option.match(decodeSealedSessionPayload(unsealed), {
225 onNone: (): SealedSessionPayload | null => null,
226 onSome: (payload) => payload,
227 });
228 if (!session) return { _tag: "InvalidCookie" };
229
230 const verified = yield* verifyJwtWithRefreshRetry(session.accessToken, jwks);
231 if (!verified) return { _tag: "Refresh" };
232
233 const claims = Option.getOrNull(decodeJwtClaims(decodeJwt(session.accessToken)));
234 if (!claims) return { _tag: "Refresh" };
235
236 return {
237 _tag: "Valid",
238 session,
239 organizationId: claims.org_id,
240 sessionId: claims.sid,
241 };
242 });
243
244const completedListMetadata = {
245 before: null,

Callers 1

Calls 2

unsealWorkOSSessionFunction · 0.85

Tested by

no test coverage detected