Skip to content

Commit 01713c2

Browse files
author
lixueping
committed
fix: 升级 axios 版本
1 parent 1c1cca8 commit 01713c2

File tree

4 files changed

+61
-41
lines changed

4 files changed

+61
-41
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"author": "Willin Wang <[email protected]> (https://willin.wang/)",
1313
"license": "MIT",
1414
"dependencies": {
15-
"axios": "^0.26.1",
15+
"axios": "^1.7.7",
1616
"base64url": "^3.0.1",
1717
"buffer": "^6.0.3",
1818
"crypto-js": "^4.1.1",

src/AutherticationHttpClient.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import Axios, {
2-
AxiosInstance,
3-
AxiosRequestConfig,
4-
AxiosRequestHeaders,
5-
} from "axios";
1+
import Axios, { AxiosHeaders, AxiosInstance, AxiosRequestConfig } from "axios";
62
import { AuthenticationClientInitOptions } from "./AuthenticationClientOptions";
73
import https from "https";
84

@@ -18,10 +14,10 @@ export class AuthenticationHttpClient {
1814
}
1915

2016
async request(config: AxiosRequestConfig) {
21-
const headers: AxiosRequestHeaders = {
17+
const headers = new AxiosHeaders({
2218
...config.headers,
2319
"x-authing-app-id": this.options.appId,
24-
};
20+
});
2521

2622
// 如果设置的 tokenEndPointAuthMethod 为 client_secret_basic 并且调用的是 /oidc 相关接口:
2723
// 1. 获取 token: /oidc(oauth)/token
@@ -37,16 +33,22 @@ export class AuthenticationHttpClient {
3733
"/oauth/token/introspection",
3834
"/api/v3/signin",
3935
"/api/v3/signin-by-mobile",
40-
"/api/v3/exchange-tokenset-with-qrcode-ticket"
36+
"/api/v3/exchange-tokenset-with-qrcode-ticket",
4137
];
42-
if (this.options.tokenEndPointAuthMethod === "client_secret_basic" && endpointsToSendBasicHeader.includes(config.url!)) {
43-
headers["authorization"] =
44-
"Basic " +
45-
Buffer.from(
46-
this.options.appId + ":" + this.options.appSecret
47-
).toString("base64");
38+
if (
39+
this.options.tokenEndPointAuthMethod === "client_secret_basic" &&
40+
endpointsToSendBasicHeader.includes(config.url!)
41+
) {
42+
headers.set(
43+
"authorization",
44+
"Basic " +
45+
Buffer.from(
46+
this.options.appId + ":" + this.options.appSecret
47+
).toString("base64"),
48+
true
49+
);
4850
} else if (this.options.accessToken) {
49-
headers["authorization"] = this.options.accessToken;
51+
headers.set("authorization", this.options.accessToken, true);
5052
}
5153

5254
const { data } = await this.axios.request({

src/ManagementHttpClient.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Axios, { AxiosInstance, AxiosRequestConfig } from "axios";
1+
import Axios, { AxiosHeaders, AxiosInstance, AxiosRequestConfig } from "axios";
22

33
import { ManagementClientOptions } from "./ManagementClientOptions";
44
import { pickBy } from "./utils";
@@ -22,25 +22,27 @@ export class ManagementHttpClient {
2222

2323
async request(config: AxiosRequestConfig) {
2424
// 此次请求的请求头
25-
let headers: any = {};
25+
let headers = new AxiosHeaders(DEFAULT_HEADERS());
2626
if (this.options.tenantId) {
27-
headers["x-authing-tenant-id"] = this.options.tenantId;
27+
headers.set("x-authing-app-id", this.options.tenantId, true);
2828
}
29-
headers["x-authing-lang"] = this.options.lang || "zh-CN";
30-
headers["date"] = new Date().toUTCString();
31-
headers = Object.assign(DEFAULT_HEADERS(), headers);
29+
headers.set("x-authing-lang", this.options.lang || "zh-CN");
30+
headers.set("date", new Date().toUTCString());
3231

3332
// 计算签名
3433
const stringToSign = buildStringToSign(
3534
config.method!,
3635
config.url!,
3736
headers,
38-
config.method === 'GET' ? config.params || {} : config.data || {},
37+
config.method === "GET" ? config.params || {} : config.data || {}
3938
);
40-
headers["authorization"] = buildAuthorization(
41-
this.options.accessKeyId,
42-
this.options.accessKeySecret,
43-
stringToSign
39+
headers.set(
40+
"authorization",
41+
buildAuthorization(
42+
this.options.accessKeyId,
43+
this.options.accessKeySecret,
44+
stringToSign
45+
)
4446
);
4547

4648
config.headers = headers;
@@ -51,11 +53,11 @@ export class ManagementHttpClient {
5153
...pickBy(config.headers, (i) => !!i),
5254
},
5355
httpsAgent:
54-
this.options.rejectUnauthorized === false
55-
? new https.Agent({
56-
rejectUnauthorized: false,
57-
})
58-
: undefined,
56+
this.options.rejectUnauthorized === false
57+
? new https.Agent({
58+
rejectUnauthorized: false,
59+
})
60+
: undefined,
5961
});
6062
return data;
6163
}

yarn.lock

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -699,12 +699,14 @@ asynckit@^0.4.0:
699699
resolved "https://registry.npmmirror.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
700700
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==
701701

702-
axios@^0.26.1:
703-
version "0.26.1"
704-
resolved "https://registry.npmmirror.com/axios/-/axios-0.26.1.tgz#1ede41c51fcf51bbbd6fd43669caaa4f0495aaa9"
705-
integrity sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==
702+
axios@^1.7.7:
703+
version "1.7.7"
704+
resolved "https://registry.npmmirror.com/axios/-/axios-1.7.7.tgz#2f554296f9892a72ac8d8e4c5b79c14a91d0a47f"
705+
integrity sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==
706706
dependencies:
707-
follow-redirects "^1.14.8"
707+
follow-redirects "^1.15.6"
708+
form-data "^4.0.0"
709+
proxy-from-env "^1.1.0"
708710

709711
babel-jest@^27.5.1:
710712
version "27.5.1"
@@ -1174,10 +1176,10 @@ find-up@^4.0.0, find-up@^4.1.0:
11741176
locate-path "^5.0.0"
11751177
path-exists "^4.0.0"
11761178

1177-
follow-redirects@^1.14.8:
1178-
version "1.14.9"
1179-
resolved "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7"
1180-
integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==
1179+
follow-redirects@^1.15.6:
1180+
version "1.15.9"
1181+
resolved "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.15.9.tgz#a604fa10e443bf98ca94228d9eebcc2e8a2c8ee1"
1182+
integrity sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==
11811183

11821184
form-data@^3.0.0:
11831185
version "3.0.1"
@@ -1188,6 +1190,15 @@ form-data@^3.0.0:
11881190
combined-stream "^1.0.8"
11891191
mime-types "^2.1.12"
11901192

1193+
form-data@^4.0.0:
1194+
version "4.0.1"
1195+
resolved "https://registry.npmmirror.com/form-data/-/form-data-4.0.1.tgz#ba1076daaaa5bfd7e99c1a6cb02aa0a5cff90d48"
1196+
integrity sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==
1197+
dependencies:
1198+
asynckit "^0.4.0"
1199+
combined-stream "^1.0.8"
1200+
mime-types "^2.1.12"
1201+
11911202
fs.realpath@^1.0.0:
11921203
version "1.0.0"
11931204
resolved "https://registry.npmmirror.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@@ -2158,6 +2169,11 @@ prompts@^2.0.1:
21582169
kleur "^3.0.3"
21592170
sisteransi "^1.0.5"
21602171

2172+
proxy-from-env@^1.1.0:
2173+
version "1.1.0"
2174+
resolved "https://registry.npmmirror.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
2175+
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==
2176+
21612177
psl@^1.1.33:
21622178
version "1.8.0"
21632179
resolved "https://registry.npmmirror.com/psl/-/psl-1.8.0.tgz#9326f8bcfb013adcc005fdff056acce020e51c24"

0 commit comments

Comments
 (0)