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

Function decodeAccessTokenClaims

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

Source from the content-addressed store, hash-verified

92 * server is the only thing that verifies the token's signature.
93 */
94export const decodeAccessTokenClaims = (
95 accessToken: string,
96): Record<string, unknown> | undefined => {
97 const segments = accessToken.split(".");
98 if (segments.length !== 3) return undefined;
99 const payloadSegment = segments[1];
100 if (!payloadSegment) return undefined;
101 try {
102 const json = Buffer.from(payloadSegment, "base64url").toString("utf8");
103 const claims = JSON.parse(json) as unknown;
104 return claims && typeof claims === "object" ? (claims as Record<string, unknown>) : undefined;
105 } catch {
106 return undefined;
107 }
108};
109
110/** Read `exp` (epoch seconds) out of a JWT access token without verifying it. */
111export 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