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

Method authorizeLogin

src/utils/cli.manager.js:134–172  ·  view source on GitHub ↗

* 授权登录 * @param {string} user_code - 用户代码 * @param {string} access_token - 访问令牌 * @param {Object} [account] - Qwen 账户对象(用于解析账号级代理) * @returns {Promise } 是否授权成功

(user_code, access_token, account)

Source from the content-addressed store, hash-verified

132 * @returns {Promise<boolean>} 是否授权成功
133 */
134 async authorizeLogin(user_code, access_token, account) {
135 const chatBaseUrl = getChatBaseUrl()
136
137 try {
138 const fetchOptions = {
139 method: 'POST',
140 headers: {
141 'Content-Type': 'application/json',
142 "authorization": `Bearer ${access_token}`,
143 },
144 body: JSON.stringify({
145 "approved": true,
146 "user_code": user_code
147 })
148 }
149
150 applyProxyToFetchOptions(fetchOptions, account)
151
152 const response = await fetch(`${chatBaseUrl}/api/v2/oauth2/authorize`, fetchOptions)
153
154 if (response.ok) {
155 return true
156 } else {
157 const responseBody = await this.readResponseBody(response)
158 logger.error('CLI设备授权确认失败', 'CLI', '', {
159 status: response.status,
160 statusText: response.statusText,
161 body: responseBody
162 })
163 throw new Error('authorize_failed')
164 }
165 } catch (error) {
166 logger.error('CLI设备授权确认异常', 'CLI', '', {
167 url: `${chatBaseUrl}/api/v2/oauth2/authorize`,
168 message: error.message
169 })
170 return false
171 }
172 }
173
174 /**
175 * 轮询获取访问令牌

Callers 1

initCliAccountMethod · 0.95

Calls 4

readResponseBodyMethod · 0.95
getChatBaseUrlFunction · 0.85
applyProxyToFetchOptionsFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected