MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / verifyWorkOSJWT

Function verifyWorkOSJWT

server/src/auth/workos-jwt.ts:92–126  ·  view source on GitHub ↗
(token: string)

Source from the content-addressed store, hash-verified

90 * signature verification against our shared JWKS.
91 */
92export async function verifyWorkOSJWT(token: string): Promise<VerifiedWorkOSToken> {
93 const jwksInstance = getJWKS();
94
95 const { payload } = await jwtVerify(token, jwksInstance);
96
97 const azp = typeof payload.azp === 'string' ? payload.azp : undefined;
98 const clientIdClaim =
99 typeof payload.client_id === 'string' ? payload.client_id : undefined;
100 const applicationId = azp ?? clientIdClaim;
101 if (!applicationId || applicationId !== workosClientId()) {
102 throw new Error(
103 `Token application id ("${applicationId ?? 'missing'}") does not match this application`,
104 );
105 }
106
107 const sub = typeof payload.sub === 'string' ? payload.sub : '';
108 const isM2M =
109 payload.grant_type === 'client_credentials' || sub.startsWith('client_');
110
111 const scopes =
112 typeof payload.scope === 'string'
113 ? payload.scope.split(' ').filter(Boolean)
114 : [];
115
116 return {
117 sub,
118 clientId: applicationId,
119 email: typeof payload.email === 'string' ? payload.email : undefined,
120 orgId: typeof payload.org_id === 'string' ? payload.org_id : undefined,
121 isM2M,
122 scopes,
123 expiresAt: typeof payload.exp === 'number' ? payload.exp : undefined,
124 payload,
125 };
126}

Callers 3

validateWorkOSBearerJWTFunction · 0.85
verifyAccessTokenJWTFunction · 0.85
workos-jwt.test.tsFile · 0.85

Calls 2

getJWKSFunction · 0.85
workosClientIdFunction · 0.85

Tested by

no test coverage detected