MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / parseCliAuthCodeShape

Function parseCliAuthCodeShape

freebuff/web/src/lib/cli-auth-code-shape.ts:8–43  ·  view source on GitHub ↗
(authCode: string)

Source from the content-addressed store, hash-verified

6}
7
8export function parseCliAuthCodeShape(authCode: string): {
9 fingerprintId: string
10 expiresAt: string
11 receivedHash: string
12} {
13 const normalizedAuthCode = authCode.trim()
14 const hashSeparatorIndex = normalizedAuthCode.lastIndexOf('.')
15 const expiresSeparatorIndex = normalizedAuthCode.lastIndexOf(
16 '.',
17 hashSeparatorIndex - 1,
18 )
19
20 if (hashSeparatorIndex === -1 || expiresSeparatorIndex === -1) {
21 const legacyMatch = normalizedAuthCode.match(
22 /^(?<fingerprintId>.+)-(?<expiresAt>\d+)-(?<receivedHash>[a-f0-9]{64})$/i,
23 )
24 if (legacyMatch?.groups) {
25 return {
26 fingerprintId: legacyMatch.groups.fingerprintId,
27 expiresAt: legacyMatch.groups.expiresAt,
28 receivedHash: legacyMatch.groups.receivedHash,
29 }
30 }
31
32 return { fingerprintId: '', expiresAt: '', receivedHash: '' }
33 }
34
35 const fingerprintId = normalizedAuthCode.slice(0, expiresSeparatorIndex)
36 const expiresAt = normalizedAuthCode.slice(
37 expiresSeparatorIndex + 1,
38 hashSeparatorIndex,
39 )
40 const receivedHash = normalizedAuthCode.slice(hashSeparatorIndex + 1)
41
42 return { fingerprintId, expiresAt, receivedHash }
43}
44
45export function isCliAuthCodeCandidate(authCode: string): boolean {
46 if (isOpaqueCliAuthCodeToken(authCode)) {

Callers 2

parseAuthCodeFunction · 0.90
isCliAuthCodeCandidateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected