@gooin/garmin-connect 1.6.12 → 1.7.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/dist/common/HttpClient copy.d.ts +38 -0
- package/dist/common/HttpClient copy.js +361 -0
- package/dist/common/HttpClient copy.js.map +1 -0
- package/dist/common/HttpClient.d.ts +142 -7
- package/dist/common/HttpClient.js +393 -145
- package/dist/common/HttpClient.js.map +1 -1
- package/dist/common/HttpClientOLD.d.ts +38 -0
- package/dist/common/HttpClientOLD.js +361 -0
- package/dist/common/HttpClientOLD.js.map +1 -0
- package/dist/common/HttpClientOLDV1.d.ts +38 -0
- package/dist/common/HttpClientOLDV1.js +361 -0
- package/dist/common/HttpClientOLDV1.js.map +1 -0
- package/dist/common/HttpClientV1.d.ts +77 -0
- package/dist/common/HttpClientV1.js +577 -0
- package/dist/common/HttpClientV1.js.map +1 -0
- package/dist/common/MFAManager.d.ts +68 -0
- package/dist/common/MFAManager.js +269 -0
- package/dist/common/MFAManager.js.map +1 -0
- package/dist/garmin/GarminConnect.d.ts +1 -1
- package/dist/garmin/GarminConnect.js +2 -2
- package/dist/garmin/GarminConnect.js.map +1 -1
- package/dist/garmin/types/index.d.ts +1 -0
- package/dist/garmin/types/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig, AxiosResponse, RawAxiosRequestHeaders } from 'axios';
|
|
2
|
+
import OAuth from 'oauth-1.0a';
|
|
3
|
+
import { UrlClass } from '../garmin/UrlClass';
|
|
4
|
+
import { GCConfig, IOauth1, IOauth1Consumer, IOauth1Token, IOauth2Token } from '../garmin/types';
|
|
5
|
+
export declare class HttpClient {
|
|
6
|
+
client: AxiosInstance;
|
|
7
|
+
url: UrlClass;
|
|
8
|
+
config: GCConfig;
|
|
9
|
+
oauth1Token: IOauth1Token | undefined;
|
|
10
|
+
oauth2Token: IOauth2Token | undefined;
|
|
11
|
+
OAUTH_CONSUMER: IOauth1Consumer | undefined;
|
|
12
|
+
constructor(url: UrlClass, config: GCConfig);
|
|
13
|
+
fetchOauthConsumer(): Promise<void>;
|
|
14
|
+
checkTokenVaild(): Promise<void>;
|
|
15
|
+
get<T>(url: string, config?: AxiosRequestConfig<any>): Promise<T>;
|
|
16
|
+
post<T>(url: string, data: any, config?: AxiosRequestConfig<any>): Promise<T>;
|
|
17
|
+
put<T>(url: string, data: any, config?: AxiosRequestConfig<any>): Promise<T>;
|
|
18
|
+
delete<T>(url: string, config?: AxiosRequestConfig<any>): Promise<T>;
|
|
19
|
+
setCommonHeader(headers: RawAxiosRequestHeaders): void;
|
|
20
|
+
handleError(response: AxiosResponse): void;
|
|
21
|
+
handleHttpError(response: AxiosResponse): void;
|
|
22
|
+
/**
|
|
23
|
+
* Login to Garmin Connect
|
|
24
|
+
* @param username
|
|
25
|
+
* @param password
|
|
26
|
+
* @returns {Promise<HttpClient>}
|
|
27
|
+
*/
|
|
28
|
+
login(username: string, password: string, mfaCallback?: () => Promise<string>): Promise<HttpClient>;
|
|
29
|
+
private getLoginTicket;
|
|
30
|
+
handleMFA(htmlStr: string): void;
|
|
31
|
+
handlePageTitle(htmlStr: string): void;
|
|
32
|
+
handleAccountLocked(htmlStr: string): void;
|
|
33
|
+
refreshOauth2Token(): Promise<void>;
|
|
34
|
+
getOauth1Token(ticket: string): Promise<IOauth1>;
|
|
35
|
+
getOauthClient(consumer: IOauth1Consumer): OAuth;
|
|
36
|
+
exchange(oauth1: IOauth1): Promise<void>;
|
|
37
|
+
setOauth2TokenExpiresAt(token: IOauth2Token): IOauth2Token;
|
|
38
|
+
}
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HttpClient = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
9
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
+
const luxon_1 = require("luxon");
|
|
11
|
+
const oauth_1_0a_1 = __importDefault(require("oauth-1.0a"));
|
|
12
|
+
const qs_1 = __importDefault(require("qs"));
|
|
13
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
14
|
+
const CSRF_RE = new RegExp('name="_csrf"\\s+value="(.+?)"');
|
|
15
|
+
const TICKET_RE = new RegExp('ticket=([^"]+)"');
|
|
16
|
+
const ACCOUNT_LOCKED_RE = new RegExp('var statuss*=s*"([^"]*)"');
|
|
17
|
+
const PAGE_TITLE_RE = new RegExp('<title>([^<]*)</title>');
|
|
18
|
+
const USER_AGENT_CONNECTMOBILE = 'com.garmin.android.apps.connectmobile';
|
|
19
|
+
const USER_AGENT_BROWSER = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36';
|
|
20
|
+
const USER_AGENT_BROWSER_MAC = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36';
|
|
21
|
+
const OAUTH_CONSUMER_URL = 'https://thegarth.s3.amazonaws.com/oauth_consumer.json';
|
|
22
|
+
const HTTP_STATUS = {
|
|
23
|
+
UNAUTHORIZED: 401
|
|
24
|
+
};
|
|
25
|
+
let tokenRefreshPromise = null;
|
|
26
|
+
let refreshSubscribers = [];
|
|
27
|
+
class HttpClient {
|
|
28
|
+
constructor(url, config) {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
this.url = url;
|
|
31
|
+
this.client = axios_1.default.create({
|
|
32
|
+
timeout: (_a = config === null || config === void 0 ? void 0 : config.timeout) !== null && _a !== void 0 ? _a : 5000,
|
|
33
|
+
timeoutErrorMessage: `Request Timeout: > ${(_b = config === null || config === void 0 ? void 0 : config.timeout) !== null && _b !== void 0 ? _b : 5000} ms`
|
|
34
|
+
/**
|
|
35
|
+
* Charles debugger: uncomment `proxy` and `httpsAgent`, then run bellow command.
|
|
36
|
+
* NODE_TLS_REJECT_UNAUTHORIZED=0 node test/sync.js
|
|
37
|
+
*/
|
|
38
|
+
// proxy: {
|
|
39
|
+
// host: '127.0.0.1',
|
|
40
|
+
// port: 8888,
|
|
41
|
+
// protocol: 'http'
|
|
42
|
+
// },
|
|
43
|
+
// httpsAgent: new (require('https').Agent)({
|
|
44
|
+
// rejectUnauthorized: false
|
|
45
|
+
// })
|
|
46
|
+
});
|
|
47
|
+
this.config = config;
|
|
48
|
+
this.client.interceptors.response.use((response) => response, async (error) => {
|
|
49
|
+
var _a;
|
|
50
|
+
if (axios_1.default.isAxiosError(error) &&
|
|
51
|
+
error.code === 'ECONNABORTED') {
|
|
52
|
+
throw new Error(error.message || 'Request Timeout');
|
|
53
|
+
}
|
|
54
|
+
const originalRequest = error.config;
|
|
55
|
+
if (((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status) === HTTP_STATUS.UNAUTHORIZED &&
|
|
56
|
+
!(originalRequest === null || originalRequest === void 0 ? void 0 : originalRequest._retry)) {
|
|
57
|
+
if (!this.oauth2Token) {
|
|
58
|
+
throw new Error('No OAuth2 token available');
|
|
59
|
+
}
|
|
60
|
+
originalRequest._retry = true;
|
|
61
|
+
try {
|
|
62
|
+
if (!tokenRefreshPromise) {
|
|
63
|
+
tokenRefreshPromise =
|
|
64
|
+
this.refreshOauth2Token().finally(() => {
|
|
65
|
+
tokenRefreshPromise = null;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
await tokenRefreshPromise;
|
|
69
|
+
originalRequest.headers.Authorization = `Bearer ${this.oauth2Token.access_token}`;
|
|
70
|
+
return this.client(originalRequest);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
console.error('Token refresh failed:', err);
|
|
74
|
+
throw err;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (axios_1.default.isAxiosError(error) && error.response) {
|
|
78
|
+
this.handleError(error.response);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// 处理没有response的情况
|
|
82
|
+
throw new Error('Network error or unknown error occurred');
|
|
83
|
+
}
|
|
84
|
+
throw error;
|
|
85
|
+
});
|
|
86
|
+
this.client.interceptors.request.use(async (config) => {
|
|
87
|
+
if (this.oauth2Token) {
|
|
88
|
+
config.headers.Authorization =
|
|
89
|
+
'Bearer ' + this.oauth2Token.access_token;
|
|
90
|
+
}
|
|
91
|
+
return config;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async fetchOauthConsumer() {
|
|
95
|
+
const response = await axios_1.default.get(OAUTH_CONSUMER_URL);
|
|
96
|
+
this.OAUTH_CONSUMER = {
|
|
97
|
+
key: response.data.consumer_key,
|
|
98
|
+
secret: response.data.consumer_secret
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
async checkTokenVaild() {
|
|
102
|
+
if (this.oauth2Token) {
|
|
103
|
+
if (this.oauth2Token.expires_at < luxon_1.DateTime.now().toSeconds()) {
|
|
104
|
+
console.error('Token expired!');
|
|
105
|
+
await this.refreshOauth2Token();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async get(url, config) {
|
|
110
|
+
const response = await this.client.get(url, config);
|
|
111
|
+
return response === null || response === void 0 ? void 0 : response.data;
|
|
112
|
+
}
|
|
113
|
+
async post(url, data, config) {
|
|
114
|
+
const response = await this.client.post(url, data, config);
|
|
115
|
+
return response === null || response === void 0 ? void 0 : response.data;
|
|
116
|
+
}
|
|
117
|
+
async put(url, data, config) {
|
|
118
|
+
const response = await this.client.put(url, data, config);
|
|
119
|
+
return response === null || response === void 0 ? void 0 : response.data;
|
|
120
|
+
}
|
|
121
|
+
async delete(url, config) {
|
|
122
|
+
const response = await this.client.post(url, null, {
|
|
123
|
+
...config,
|
|
124
|
+
headers: {
|
|
125
|
+
...config === null || config === void 0 ? void 0 : config.headers,
|
|
126
|
+
'X-Http-Method-Override': 'DELETE'
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
return response === null || response === void 0 ? void 0 : response.data;
|
|
130
|
+
}
|
|
131
|
+
setCommonHeader(headers) {
|
|
132
|
+
lodash_1.default.each(headers, (headerValue, key) => {
|
|
133
|
+
this.client.defaults.headers.common[key] = headerValue;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
handleError(response) {
|
|
137
|
+
this.handleHttpError(response);
|
|
138
|
+
}
|
|
139
|
+
handleHttpError(response) {
|
|
140
|
+
const { status, statusText, data } = response;
|
|
141
|
+
const errorMessage = {
|
|
142
|
+
status,
|
|
143
|
+
statusText,
|
|
144
|
+
data: typeof data === 'object' ? JSON.stringify(data) : data
|
|
145
|
+
};
|
|
146
|
+
console.error('HTTP Error:', errorMessage);
|
|
147
|
+
throw new Error(`HTTP Error (${status}): ${statusText}`);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Login to Garmin Connect
|
|
151
|
+
* @param username
|
|
152
|
+
* @param password
|
|
153
|
+
* @returns {Promise<HttpClient>}
|
|
154
|
+
*/
|
|
155
|
+
async login(username, password, mfaCallback) {
|
|
156
|
+
await this.fetchOauthConsumer();
|
|
157
|
+
// Step1-3: Get ticket from page.
|
|
158
|
+
const ticket = await this.getLoginTicket(username, password);
|
|
159
|
+
// Step4: Oauth1
|
|
160
|
+
const oauth1 = await this.getOauth1Token(ticket);
|
|
161
|
+
// TODO: Handle MFA
|
|
162
|
+
// Step 5: Oauth2
|
|
163
|
+
await this.exchange(oauth1);
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
async getLoginTicket(username, password) {
|
|
167
|
+
// Step1: Set cookie
|
|
168
|
+
const step1Params = {
|
|
169
|
+
clientId: 'GarminConnect',
|
|
170
|
+
locale: 'en',
|
|
171
|
+
service: this.url.GC_MODERN
|
|
172
|
+
};
|
|
173
|
+
const step1Url = `${this.url.GARMIN_SSO_EMBED}?${qs_1.default.stringify(step1Params)}`;
|
|
174
|
+
// console.log('login - step1Url:', step1Url);
|
|
175
|
+
await this.client.get(step1Url);
|
|
176
|
+
// Step2 Get _csrf
|
|
177
|
+
const step2Params = {
|
|
178
|
+
id: 'gauth-widget',
|
|
179
|
+
embedWidget: true,
|
|
180
|
+
locale: 'en',
|
|
181
|
+
gauthHost: this.url.GARMIN_SSO_EMBED
|
|
182
|
+
};
|
|
183
|
+
const step2Url = `${this.url.SIGNIN_URL}?${qs_1.default.stringify(step2Params)}`;
|
|
184
|
+
// console.log('login - step2Url:', step2Url);
|
|
185
|
+
const step2Result = await this.get(step2Url);
|
|
186
|
+
// console.log('login - step2Result:', step2Result)
|
|
187
|
+
const csrfRegResult = CSRF_RE.exec(step2Result);
|
|
188
|
+
if (!csrfRegResult) {
|
|
189
|
+
throw new Error('login - csrf not found');
|
|
190
|
+
}
|
|
191
|
+
const csrf_token = csrfRegResult[1];
|
|
192
|
+
// console.log('login - csrf:', csrf_token);
|
|
193
|
+
// Step3 Get ticket
|
|
194
|
+
const signinParams = {
|
|
195
|
+
id: 'gauth-widget',
|
|
196
|
+
embedWidget: true,
|
|
197
|
+
clientId: 'GarminConnect',
|
|
198
|
+
locale: 'en',
|
|
199
|
+
gauthHost: this.url.GARMIN_SSO_EMBED,
|
|
200
|
+
service: this.url.GARMIN_SSO_EMBED,
|
|
201
|
+
source: this.url.GARMIN_SSO_EMBED,
|
|
202
|
+
redirectAfterAccountLoginUrl: this.url.GARMIN_SSO_EMBED,
|
|
203
|
+
redirectAfterAccountCreationUrl: this.url.GARMIN_SSO_EMBED
|
|
204
|
+
};
|
|
205
|
+
const step3Url = `${this.url.SIGNIN_URL}?${qs_1.default.stringify(signinParams)}`;
|
|
206
|
+
// console.log('login - step3Url:', step3Url);
|
|
207
|
+
const step3Form = new form_data_1.default();
|
|
208
|
+
step3Form.append('username', username);
|
|
209
|
+
step3Form.append('password', password);
|
|
210
|
+
step3Form.append('embed', 'true');
|
|
211
|
+
step3Form.append('_csrf', csrf_token);
|
|
212
|
+
const step3Result = await this.post(step3Url, step3Form, {
|
|
213
|
+
headers: {
|
|
214
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
215
|
+
Dnt: 1,
|
|
216
|
+
Origin: this.url.GARMIN_SSO_ORIGIN,
|
|
217
|
+
Referer: this.url.SIGNIN_URL,
|
|
218
|
+
'User-Agent': USER_AGENT_BROWSER
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
console.log('step3Result:', step3Result);
|
|
222
|
+
this.handleAccountLocked(step3Result);
|
|
223
|
+
this.handlePageTitle(step3Result);
|
|
224
|
+
this.handleMFA(step3Result);
|
|
225
|
+
const ticketRegResult = TICKET_RE.exec(step3Result);
|
|
226
|
+
if (!ticketRegResult) {
|
|
227
|
+
throw new Error('login failed (Ticket not found or MFA), please check username and password');
|
|
228
|
+
}
|
|
229
|
+
const ticket = ticketRegResult[1];
|
|
230
|
+
return ticket;
|
|
231
|
+
}
|
|
232
|
+
// TODO: Handle MFA
|
|
233
|
+
handleMFA(htmlStr) { }
|
|
234
|
+
// TODO: Handle Phone number
|
|
235
|
+
handlePageTitle(htmlStr) {
|
|
236
|
+
const pageTitileRegResult = PAGE_TITLE_RE.exec(htmlStr);
|
|
237
|
+
if (pageTitileRegResult) {
|
|
238
|
+
const title = pageTitileRegResult[1];
|
|
239
|
+
console.log('login page title:', title);
|
|
240
|
+
if (lodash_1.default.includes(title, 'Update Phone Number')) {
|
|
241
|
+
// current I don't know where to update it
|
|
242
|
+
// See: https://github.com/matin/garth/issues/19
|
|
243
|
+
throw new Error('login failed (Update Phone number), please update your phone number, See: https://github.com/matin/garth/issues/19');
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
handleAccountLocked(htmlStr) {
|
|
248
|
+
const accountLockedRegResult = ACCOUNT_LOCKED_RE.exec(htmlStr);
|
|
249
|
+
if (accountLockedRegResult) {
|
|
250
|
+
const msg = accountLockedRegResult[1];
|
|
251
|
+
console.error(msg);
|
|
252
|
+
throw new Error('login failed (AccountLocked), please open connect web page to unlock your account');
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
async refreshOauth2Token() {
|
|
256
|
+
try {
|
|
257
|
+
if (!this.OAUTH_CONSUMER) {
|
|
258
|
+
await this.fetchOauthConsumer();
|
|
259
|
+
}
|
|
260
|
+
if (!this.oauth2Token || !this.oauth1Token) {
|
|
261
|
+
throw new Error('Missing required tokens for refresh');
|
|
262
|
+
}
|
|
263
|
+
const oauth1 = {
|
|
264
|
+
oauth: this.getOauthClient(this.OAUTH_CONSUMER),
|
|
265
|
+
token: this.oauth1Token
|
|
266
|
+
};
|
|
267
|
+
await this.exchange(oauth1);
|
|
268
|
+
console.log(`「${this.config.username}」in「${this.url.domain}」 OAuth2 token refreshed successfully`);
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
console.error('Failed to refresh OAuth2 token:', error);
|
|
272
|
+
throw error;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
async getOauth1Token(ticket) {
|
|
276
|
+
if (!this.OAUTH_CONSUMER) {
|
|
277
|
+
throw new Error('No OAUTH_CONSUMER');
|
|
278
|
+
}
|
|
279
|
+
const params = {
|
|
280
|
+
ticket,
|
|
281
|
+
'login-url': this.url.GARMIN_SSO_EMBED,
|
|
282
|
+
'accepts-mfa-tokens': true
|
|
283
|
+
};
|
|
284
|
+
const url = `${this.url.OAUTH_URL}/preauthorized?${qs_1.default.stringify(params)}`;
|
|
285
|
+
const oauth = this.getOauthClient(this.OAUTH_CONSUMER);
|
|
286
|
+
const step4RequestData = {
|
|
287
|
+
url: url,
|
|
288
|
+
method: 'GET'
|
|
289
|
+
};
|
|
290
|
+
const headers = oauth.toHeader(oauth.authorize(step4RequestData));
|
|
291
|
+
// console.log('getOauth1Token - headers:', headers);
|
|
292
|
+
const response = await this.get(url, {
|
|
293
|
+
headers: {
|
|
294
|
+
...headers,
|
|
295
|
+
'User-Agent': USER_AGENT_CONNECTMOBILE
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
// console.log('getOauth1Token - response:', response);
|
|
299
|
+
const token = qs_1.default.parse(response);
|
|
300
|
+
// console.log('getOauth1Token - token:', token);
|
|
301
|
+
this.oauth1Token = token;
|
|
302
|
+
return { token, oauth };
|
|
303
|
+
}
|
|
304
|
+
getOauthClient(consumer) {
|
|
305
|
+
const oauth = new oauth_1_0a_1.default({
|
|
306
|
+
consumer: consumer,
|
|
307
|
+
signature_method: 'HMAC-SHA1',
|
|
308
|
+
hash_function(base_string, key) {
|
|
309
|
+
return node_crypto_1.default
|
|
310
|
+
.createHmac('sha1', key)
|
|
311
|
+
.update(base_string)
|
|
312
|
+
.digest('base64');
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
return oauth;
|
|
316
|
+
}
|
|
317
|
+
//
|
|
318
|
+
async exchange(oauth1) {
|
|
319
|
+
const token = {
|
|
320
|
+
key: oauth1.token.oauth_token,
|
|
321
|
+
secret: oauth1.token.oauth_token_secret
|
|
322
|
+
};
|
|
323
|
+
// console.log('exchange - token:', token);
|
|
324
|
+
const baseUrl = `${this.url.OAUTH_URL}/exchange/user/2.0`;
|
|
325
|
+
const requestData = {
|
|
326
|
+
url: baseUrl,
|
|
327
|
+
method: 'POST',
|
|
328
|
+
data: null
|
|
329
|
+
};
|
|
330
|
+
const step5AuthData = oauth1.oauth.authorize(requestData, token);
|
|
331
|
+
// console.log('login - step5AuthData:', step5AuthData);
|
|
332
|
+
const url = `${baseUrl}?${qs_1.default.stringify(step5AuthData)}`;
|
|
333
|
+
// console.log('exchange - url:', url);
|
|
334
|
+
this.oauth2Token = undefined;
|
|
335
|
+
const response = await this.post(url, null, {
|
|
336
|
+
headers: {
|
|
337
|
+
'User-Agent': USER_AGENT_CONNECTMOBILE,
|
|
338
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
// console.log('exchange - response:', response);
|
|
342
|
+
this.oauth2Token = this.setOauth2TokenExpiresAt(response);
|
|
343
|
+
// console.log('exchange - oauth2Token:', this.oauth2Token);
|
|
344
|
+
}
|
|
345
|
+
setOauth2TokenExpiresAt(token) {
|
|
346
|
+
const now = luxon_1.DateTime.now();
|
|
347
|
+
const expiresAt = now.plus({ seconds: token.expires_in });
|
|
348
|
+
const refreshTokenExpiresAt = now.plus({
|
|
349
|
+
seconds: token.refresh_token_expires_in
|
|
350
|
+
});
|
|
351
|
+
return {
|
|
352
|
+
...token,
|
|
353
|
+
last_update_date: now.toLocal().toString(),
|
|
354
|
+
expires_date: expiresAt.toLocal().toString(),
|
|
355
|
+
expires_at: expiresAt.toSeconds(),
|
|
356
|
+
refresh_token_expires_at: refreshTokenExpiresAt.toSeconds()
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
exports.HttpClient = HttpClient;
|
|
361
|
+
//# sourceMappingURL=HttpClient%20copy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpClient copy.js","sourceRoot":"","sources":["../../src/common/HttpClient copy.ts"],"names":[],"mappings":";;;;;;AAAA,kDAKe;AACf,0DAAiC;AACjC,oDAAuB;AACvB,iCAAiC;AACjC,4DAA+B;AAC/B,4CAAoB;AASpB,8DAAiC;AAEjC,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,+BAA+B,CAAC,CAAC;AAC5D,MAAM,SAAS,GAAG,IAAI,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAChD,MAAM,iBAAiB,GAAG,IAAI,MAAM,CAAC,0BAA0B,CAAC,CAAC;AACjE,MAAM,aAAa,GAAG,IAAI,MAAM,CAAC,wBAAwB,CAAC,CAAC;AAE3D,MAAM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6 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosRequestConfig, AxiosResponse, RawAxiosRequestHeaders } from 'axios';
|
|
2
2
|
import OAuth from 'oauth-1.0a';
|
|
3
|
+
import { MFAManager } from './MFAManager';
|
|
3
4
|
import { UrlClass } from '../garmin/UrlClass';
|
|
4
5
|
import { GCConfig, IOauth1, IOauth1Consumer, IOauth1Token, IOauth2Token } from '../garmin/types';
|
|
5
6
|
export declare class HttpClient {
|
|
@@ -9,30 +10,164 @@ export declare class HttpClient {
|
|
|
9
10
|
oauth1Token: IOauth1Token | undefined;
|
|
10
11
|
oauth2Token: IOauth2Token | undefined;
|
|
11
12
|
OAUTH_CONSUMER: IOauth1Consumer | undefined;
|
|
13
|
+
mfaManager: MFAManager;
|
|
12
14
|
constructor(url: UrlClass, config: GCConfig);
|
|
15
|
+
/**
|
|
16
|
+
* 设置请求和响应拦截器
|
|
17
|
+
*/
|
|
18
|
+
private setupInterceptors;
|
|
19
|
+
/**
|
|
20
|
+
* 记录响应跟踪信息
|
|
21
|
+
*/
|
|
22
|
+
private logResponseTracking;
|
|
23
|
+
/**
|
|
24
|
+
* 处理响应错误
|
|
25
|
+
*/
|
|
26
|
+
private handleResponseError;
|
|
27
|
+
/**
|
|
28
|
+
* 获取OAuth消费者信息
|
|
29
|
+
*/
|
|
13
30
|
fetchOauthConsumer(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* 检查令牌有效性
|
|
33
|
+
*/
|
|
14
34
|
checkTokenVaild(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* GET请求
|
|
37
|
+
*/
|
|
15
38
|
get<T>(url: string, config?: AxiosRequestConfig<any>): Promise<T>;
|
|
39
|
+
/**
|
|
40
|
+
* POST请求
|
|
41
|
+
*/
|
|
16
42
|
post<T>(url: string, data: any, config?: AxiosRequestConfig<any>): Promise<T>;
|
|
43
|
+
/**
|
|
44
|
+
* PUT请求
|
|
45
|
+
*/
|
|
17
46
|
put<T>(url: string, data: any, config?: AxiosRequestConfig<any>): Promise<T>;
|
|
47
|
+
/**
|
|
48
|
+
* DELETE请求
|
|
49
|
+
*/
|
|
18
50
|
delete<T>(url: string, config?: AxiosRequestConfig<any>): Promise<T>;
|
|
51
|
+
/**
|
|
52
|
+
* 设置通用请求头
|
|
53
|
+
*/
|
|
19
54
|
setCommonHeader(headers: RawAxiosRequestHeaders): void;
|
|
55
|
+
/**
|
|
56
|
+
* 处理错误
|
|
57
|
+
*/
|
|
20
58
|
handleError(response: AxiosResponse): void;
|
|
59
|
+
/**
|
|
60
|
+
* 处理HTTP错误
|
|
61
|
+
*/
|
|
21
62
|
handleHttpError(response: AxiosResponse): void;
|
|
22
63
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @param username
|
|
25
|
-
* @param password
|
|
26
|
-
* @
|
|
64
|
+
* 登录到Garmin Connect
|
|
65
|
+
* @param username 用户名
|
|
66
|
+
* @param password 密码
|
|
67
|
+
* @param mfaCallback MFA验证回调函数
|
|
68
|
+
* @param sessionId 会话ID,用于分步登录
|
|
69
|
+
* @returns Promise<HttpClient>
|
|
70
|
+
*/
|
|
71
|
+
login(username: string, password: string, sessionId?: string): Promise<HttpClient>;
|
|
72
|
+
/**
|
|
73
|
+
* 获取登录票据
|
|
74
|
+
* @param username 用户名
|
|
75
|
+
* @param password 密码
|
|
76
|
+
* @param mfaCallback MFA验证回调函数
|
|
77
|
+
* @param sessionId 会话ID,用于分步登录
|
|
78
|
+
* @returns 登录票据
|
|
27
79
|
*/
|
|
28
|
-
login(username: string, password: string): Promise<HttpClient>;
|
|
29
80
|
private getLoginTicket;
|
|
30
|
-
|
|
31
|
-
|
|
81
|
+
/**
|
|
82
|
+
* 准备登录参数
|
|
83
|
+
*/
|
|
84
|
+
private prepareLoginParams;
|
|
85
|
+
/**
|
|
86
|
+
* 执行登录步骤1:设置cookie
|
|
87
|
+
*/
|
|
88
|
+
private performLoginStep1;
|
|
89
|
+
/**
|
|
90
|
+
* 执行登录步骤2:获取CSRF令牌
|
|
91
|
+
*/
|
|
92
|
+
private performLoginStep2;
|
|
93
|
+
/**
|
|
94
|
+
* 执行登录步骤3:提交凭据
|
|
95
|
+
*/
|
|
96
|
+
private performLoginStep3;
|
|
97
|
+
/**
|
|
98
|
+
* 判断是否需要MFA验证
|
|
99
|
+
*/
|
|
100
|
+
private isMFARequired;
|
|
101
|
+
/**
|
|
102
|
+
* 从响应中提取票据
|
|
103
|
+
*/
|
|
104
|
+
private extractTicket;
|
|
105
|
+
/**
|
|
106
|
+
* 处理MFA验证(使用直接提供的验证码)
|
|
107
|
+
* @param htmlStr HTML响应字符串
|
|
108
|
+
* @param signinParams 登录参数
|
|
109
|
+
* @param mfaCode MFA验证码
|
|
110
|
+
* @returns MFA验证后的响应字符串
|
|
111
|
+
*/
|
|
112
|
+
handleMFAWithCode(htmlStr: string, signinParams: Record<string, any>, mfaCode: string): Promise<string>;
|
|
113
|
+
/**
|
|
114
|
+
* 处理MFA验证
|
|
115
|
+
* @param htmlStr HTML响应字符串
|
|
116
|
+
* @param signinParams 登录参数
|
|
117
|
+
* @param mfaCallback MFA验证回调函数
|
|
118
|
+
* @returns MFA验证后的响应字符串
|
|
119
|
+
*/
|
|
120
|
+
handleMFA(htmlStr: string, signinParams: Record<string, any>, mfaCallback?: () => Promise<string>): Promise<string>;
|
|
121
|
+
/**
|
|
122
|
+
* 提交MFA验证码
|
|
123
|
+
*/
|
|
124
|
+
private submitMFACode;
|
|
125
|
+
/**
|
|
126
|
+
* 验证MFA结果
|
|
127
|
+
*/
|
|
128
|
+
private validateMFAResult;
|
|
129
|
+
/**
|
|
130
|
+
* 从HTML中提取CSRF令牌
|
|
131
|
+
* @param html HTML字符串
|
|
132
|
+
* @returns CSRF令牌或null
|
|
133
|
+
*/
|
|
134
|
+
extractCsrfToken(html: string): string | null;
|
|
135
|
+
/**
|
|
136
|
+
* 处理页面标题
|
|
137
|
+
* @param htmlStr HTML字符串
|
|
138
|
+
* @returns 页面标题
|
|
139
|
+
*/
|
|
140
|
+
handlePageTitle(htmlStr: string): string;
|
|
141
|
+
/**
|
|
142
|
+
* 处理账户锁定状态
|
|
143
|
+
* @param htmlStr HTML字符串
|
|
144
|
+
*/
|
|
32
145
|
handleAccountLocked(htmlStr: string): void;
|
|
146
|
+
/**
|
|
147
|
+
* 刷新OAuth2令牌
|
|
148
|
+
*/
|
|
33
149
|
refreshOauth2Token(): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* 获取OAuth1令牌
|
|
152
|
+
* @param ticket 登录票据
|
|
153
|
+
* @returns OAuth1令牌和客户端
|
|
154
|
+
*/
|
|
34
155
|
getOauth1Token(ticket: string): Promise<IOauth1>;
|
|
156
|
+
/**
|
|
157
|
+
* 获取OAuth客户端
|
|
158
|
+
* @param consumer OAuth消费者信息
|
|
159
|
+
* @returns OAuth客户端
|
|
160
|
+
*/
|
|
35
161
|
getOauthClient(consumer: IOauth1Consumer): OAuth;
|
|
162
|
+
/**
|
|
163
|
+
* 交换OAuth2令牌
|
|
164
|
+
* @param oauth1 OAuth1令牌和客户端
|
|
165
|
+
*/
|
|
36
166
|
exchange(oauth1: IOauth1): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* 设置OAuth2令牌过期时间
|
|
169
|
+
* @param token OAuth2令牌
|
|
170
|
+
* @returns 设置了过期时间的OAuth2令牌
|
|
171
|
+
*/
|
|
37
172
|
setOauth2TokenExpiresAt(token: IOauth2Token): IOauth2Token;
|
|
38
173
|
}
|