MCPcopy
hub / github.com/MiniMax-AI/cli / resolveCredential

Function resolveCredential

src/auth/resolver.ts:8–31  ·  view source on GitHub ↗
(config: Config)

Source from the content-addressed store, hash-verified

6import { ExitCode } from '../errors/codes';
7
8export async function resolveCredential(config: Config): Promise<ResolvedCredential> {
9 // 1. --api-key flag
10 if (config.apiKey) {
11 return { token: config.apiKey, method: 'api-key', source: 'flag' };
12 }
13
14 // 2. OAuth credentials in config file
15 const oauth = await loadCredentials();
16 if (oauth) {
17 const token = await ensureFreshToken(oauth);
18 return { token, method: 'oauth', source: 'config.json' };
19 }
20
21 // 3. API key from config file
22 if (config.fileApiKey) {
23 return { token: config.fileApiKey, method: 'api-key', source: 'config.json' };
24 }
25
26 throw new CLIError(
27 'No credentials found.',
28 ExitCode.AUTH,
29 'Log in: mmx auth login\nPass directly: --api-key sk-xxxxx',
30 );
31}

Callers 3

resolver.test.tsFile · 0.90
requestFunction · 0.90
runFunction · 0.90

Calls 2

loadCredentialsFunction · 0.90
ensureFreshTokenFunction · 0.90

Tested by

no test coverage detected