MCPcopy Create free account
hub / github.com/Rfym21/Qwen2API / initCliAccount

Method initCliAccount

src/utils/cli.manager.js:259–288  ·  view source on GitHub ↗

* 初始化 CLI 账户 * @param {string} access_token - 访问令牌 * @param {Object} [account] - Qwen 账户对象(用于解析账号级代理) * @returns {Promise } 账户信息

(access_token, account)

Source from the content-addressed store, hash-verified

257 * @returns {Promise<Object>} 账户信息
258 */
259 async initCliAccount(access_token, account) {
260 const deviceFlow = await this.initiateDeviceFlow(account)
261 if (!deviceFlow.status) {
262 logger.error('CLI账户初始化失败:设备授权流程未成功启动', 'CLI')
263 return {
264 status: false,
265 access_token: null,
266 refresh_token: null,
267 expiry_date: null
268 }
269 }
270
271 if (!await this.authorizeLogin(deviceFlow.user_code, access_token, account)) {
272 logger.error('CLI账户初始化失败:设备授权确认未通过', 'CLI', '', {
273 user_code: deviceFlow.user_code
274 })
275 return {
276 status: false,
277 access_token: null,
278 refresh_token: null,
279 expiry_date: null
280 }
281 }
282
283 const cliToken = await this.pollForToken(deviceFlow.device_code, deviceFlow.code_verifier, account)
284 if (!cliToken.access_token || !cliToken.refresh_token || !cliToken.expiry_date) {
285 logger.error('CLI账户初始化失败:轮询令牌返回数据不完整', 'CLI', '', cliToken)
286 }
287 return cliToken
288 }
289
290 /**
291 * 刷新访问令牌

Callers 1

_initializeCliAccountMethod · 0.80

Calls 4

initiateDeviceFlowMethod · 0.95
authorizeLoginMethod · 0.95
pollForTokenMethod · 0.95
errorMethod · 0.80

Tested by

no test coverage detected