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

Function validateWorkOSApiKey

server/src/middleware/auth.ts:222–245  ·  view source on GitHub ↗
(req: Request)

Source from the content-addressed store, hash-verified

220 * Returns the validated API key info or null if invalid
221 */
222export async function validateWorkOSApiKey(req: Request): Promise<ValidatedApiKey | null> {
223 const authHeader = req.headers.authorization;
224 if (!authHeader?.startsWith('Bearer ')) return null;
225
226 const token = authHeader.slice(7); // Remove 'Bearer ' prefix
227
228 // WorkOS API keys use 'wos_api_key_' (legacy) or 'sk_' (current) prefix
229 if (!isWorkOSApiKeyFormat(token)) return null;
230
231 try {
232 const result = await workos.apiKeys.createValidation({ value: token });
233 if (!result.apiKey) return null;
234
235 return {
236 id: result.apiKey.id,
237 organizationId: result.apiKey.owner.id,
238 name: result.apiKey.name,
239 permissions: result.apiKey.permissions,
240 };
241 } catch (error) {
242 logger.debug({ err: error }, 'API key validation failed');
243 return null;
244 }
245}
246
247/**
248 * Check if validated API key has a specific permission

Callers 2

requireAuthFunction · 0.85
resolveCallerOrgIdFunction · 0.85

Calls 1

isWorkOSApiKeyFormatFunction · 0.85

Tested by

no test coverage detected