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

Function decodeAccessTokenClaims

apps/cli/src/device-login.ts:85–99  ·  view source on GitHub ↗
(
  accessToken: string,
)

Source from the content-addressed store, hash-verified

83 * server is the only thing that verifies the token's signature.
84 */
85export const decodeAccessTokenClaims = (
86 accessToken: string,
87): Record<string, unknown> | undefined => {
88 const segments = accessToken.split(".");
89 if (segments.length !== 3) return undefined;
90 const payloadSegment = segments[1];
91 if (!payloadSegment) return undefined;
92 try {
93 const json = Buffer.from(payloadSegment, "base64url").toString("utf8");
94 const claims = JSON.parse(json) as unknown;
95 return claims && typeof claims === "object" ? (claims as Record<string, unknown>) : undefined;
96 } catch {
97 return undefined;
98 }
99};
100
101/** Read `exp` (epoch seconds) out of a JWT access token without verifying it. */
102export const accessTokenExpiry = (accessToken: string): number | undefined =>

Callers 4

oauthAccountIdentityFunction · 0.90
main.tsFile · 0.90
accessTokenExpiryFunction · 0.85
pollForDeviceTokensFunction · 0.85

Calls 1

toStringMethod · 0.80

Tested by

no test coverage detected