@honor-claw/yoyo 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/apis/honor-auth.ts
CHANGED
|
@@ -5,12 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
import { createHash, randomBytes } from 'crypto';
|
|
7
7
|
import { HttpClient, type HttpClientOptions } from './http-client.js';
|
|
8
|
-
import type {
|
|
8
|
+
import type { TokenResponse, HonorAuthConfig } from '../honor-auth/types.js';
|
|
9
9
|
import { uuid } from '../utils/id.js';
|
|
10
10
|
import { isOKResponse } from './helpers.js';
|
|
11
11
|
import type { HttpApiWrapper } from './types.js';
|
|
12
12
|
import { takeApiHost } from '../modules/claw-configs/hosts.js';
|
|
13
|
-
import type { DeviceInfo } from '../types.js';
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* PKCE参数
|
|
@@ -102,9 +101,9 @@ export class HonorAuthClient {
|
|
|
102
101
|
/**
|
|
103
102
|
* 使用授权码换取Token
|
|
104
103
|
*/
|
|
105
|
-
async exchangeToken(code: string
|
|
104
|
+
async exchangeToken(code: string) {
|
|
106
105
|
const hosts = takeApiHost();
|
|
107
|
-
const tokenUrl = `https://${hosts.
|
|
106
|
+
const tokenUrl = `https://${hosts.ics}/honorboard/auth/v1/oauth/jwtToken`;
|
|
108
107
|
|
|
109
108
|
const data = {
|
|
110
109
|
clientId: this.config.clientId,
|
|
@@ -116,9 +115,10 @@ export class HonorAuthClient {
|
|
|
116
115
|
// 构建请求头,包含灰度标签(如果有)
|
|
117
116
|
const headers: Record<string, string> = {
|
|
118
117
|
'Content-Type': 'application/json',
|
|
119
|
-
'x-
|
|
120
|
-
|
|
121
|
-
'x-
|
|
118
|
+
'x-origin-udid': this.config.clientId,
|
|
119
|
+
'x-app-pkg': 'com.hihonor.pc.openclaw',
|
|
120
|
+
'x-request-nonce': uuid(),
|
|
121
|
+
'x-timestamp': String(Date.now()),
|
|
122
122
|
};
|
|
123
123
|
|
|
124
124
|
// 添加灰度标签
|
|
@@ -126,7 +126,7 @@ export class HonorAuthClient {
|
|
|
126
126
|
headers['x-gray'] = hosts.grayTag;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
const response = await this.httpClient.post<HttpApiWrapper<
|
|
129
|
+
const response = await this.httpClient.post<HttpApiWrapper<TokenResponse>>(tokenUrl, {
|
|
130
130
|
body: data,
|
|
131
131
|
headers,
|
|
132
132
|
timeout: 15000,
|
|
@@ -10,10 +10,10 @@ import open from 'open';
|
|
|
10
10
|
/**
|
|
11
11
|
* 执行OAuth2授权流程(自动打开浏览器)
|
|
12
12
|
*/
|
|
13
|
-
export async function performOAuth2AuthWithBrowser(
|
|
13
|
+
export async function performOAuth2AuthWithBrowser(_: DeviceInfo, configOverrides?: Partial<HonorAuthConfig>) {
|
|
14
14
|
const config = getConfig(configOverrides);
|
|
15
15
|
const logger = useClawLogger();
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
logger.debug('Starting Honor login flow...');
|
|
18
18
|
|
|
19
19
|
// 创建认证客户端
|
|
@@ -59,17 +59,19 @@ export async function performOAuth2AuthWithBrowser(deviceInfo: DeviceInfo, confi
|
|
|
59
59
|
|
|
60
60
|
// 使用授权码换取Token
|
|
61
61
|
try {
|
|
62
|
-
const tokenInfo = await authClient.exchangeToken(receivedCode
|
|
62
|
+
const tokenInfo = await authClient.exchangeToken(receivedCode);
|
|
63
63
|
|
|
64
|
-
if (!tokenInfo.
|
|
65
|
-
throw new Error('failed to get
|
|
64
|
+
if (!tokenInfo.token || !tokenInfo.userInfo?.userId) {
|
|
65
|
+
throw new Error('failed to get user info');
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
// 保存Token
|
|
69
|
-
await saveToken(
|
|
69
|
+
await saveToken(tokenInfo, config.saveToFile !== false);
|
|
70
70
|
|
|
71
71
|
return {
|
|
72
|
-
|
|
72
|
+
userId: tokenInfo.userInfo.userId,
|
|
73
|
+
token: tokenInfo.token,
|
|
74
|
+
userName: tokenInfo.userInfo.displayName,
|
|
73
75
|
} as HonorUserInfo;
|
|
74
76
|
} catch (error) {
|
|
75
77
|
throw new Error(`get token failed: ${error instanceof Error ? error.message : String(error)}`);
|