MCPcopy Create free account
hub / github.com/vercel/vercel / debugTokenClaims

Function debugTokenClaims

packages/container/src/util.ts:205–243  ·  view source on GitHub ↗
(
  label: string,
  token: string | undefined
)

Source from the content-addressed store, hash-verified

203}
204
205export function debugTokenClaims(
206 label: string,
207 token: string | undefined
208): void {
209 if (!DEBUG) return;
210 if (!token) {
211 debug(`${label}: <absent>`);
212 return;
213 }
214 try {
215 const payload = token.split('.')[1];
216 if (!payload) {
217 debug(`${label}: <not a JWT>`);
218 return;
219 }
220 const claims = JSON.parse(
221 Buffer.from(payload, 'base64url').toString('utf8')
222 ) as Record<string, unknown>;
223 const safe = {
224 iss: claims.iss,
225 aud: claims.aud,
226 sub: claims.sub,
227 scope: claims.scope,
228 owner: claims.owner,
229 owner_id: claims.owner_id,
230 project: claims.project,
231 project_id: claims.project_id,
232 exp:
233 typeof claims.exp === 'number'
234 ? `${new Date(claims.exp * 1000).toISOString()} (in ${Math.round(
235 (claims.exp * 1000 - Date.now()) / 1000
236 )}s)`
237 : claims.exp,
238 };
239 debug(`${label}: ${JSON.stringify(safe)}`);
240 } catch (err) {
241 debug(`${label}: <unparseable claims> (${(err as Error).message})`);
242 }
243}
244
245export interface OidcClaims {
246 owner?: string;

Callers 1

buildAndPushImageFunction · 0.90

Calls 4

splitMethod · 0.80
debugFunction · 0.70
parseMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected