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

Function getChatGptOAuthCredentials

sdk/src/credentials.ts:99–128  ·  view source on GitHub ↗
(
  clientEnv: ClientEnv = env,
)

Source from the content-addressed store, hash-verified

97 * Environment variable takes precedence.
98 */
99export const getChatGptOAuthCredentials = (
100 clientEnv: ClientEnv = env,
101): ChatGptOAuthCredentials | null => {
102 // 1. Environment variable takes highest precedence
103 const envToken = getChatGptOAuthTokenFromEnv()
104 if (envToken) {
105 return {
106 accessToken: envToken,
107 refreshToken: '',
108 expiresAt: Date.now() + 365 * 24 * 60 * 60 * 1000,
109 connectedAt: Date.now(),
110 }
111 }
112
113 // 2. Codebuff's own stored credentials
114 const credentialsPath = getCredentialsPath(clientEnv)
115 if (fs.existsSync(credentialsPath)) {
116 try {
117 const credentialsFile = fs.readFileSync(credentialsPath, 'utf8')
118 const parsed = credentialsFileSchema.safeParse(JSON.parse(credentialsFile))
119 if (parsed.success && parsed.data.chatgptOAuth) {
120 return parsed.data.chatgptOAuth
121 }
122 } catch {
123 // Fall through
124 }
125 }
126
127 return null
128}
129
130export const saveChatGptOAuthCredentials = (
131 credentials: ChatGptOAuthCredentials,

Callers 6

initializeAppFunction · 0.90
getChatGptOAuthStatusFunction · 0.90
isChatGptOAuthValidFunction · 0.85
refreshChatGptOAuthTokenFunction · 0.85

Calls 3

parseMethod · 0.80
getCredentialsPathFunction · 0.70

Tested by

no test coverage detected