( label: string, token: string | undefined )
| 203 | } |
| 204 | |
| 205 | export 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 | |
| 245 | export interface OidcClaims { |
| 246 | owner?: string; |
no test coverage detected