@nihplod/sso-sdk 1.2.1 → 1.3.0
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/README.md +443 -441
- package/dist/index.d.mts +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.js +8 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -5
- package/dist/index.mjs.map +1 -1
- package/dist/next/index.d.mts +18 -0
- package/dist/next/index.d.ts +18 -0
- package/dist/next/index.js +46 -22
- package/dist/next/index.js.map +1 -1
- package/dist/next/index.mjs +46 -22
- package/dist/next/index.mjs.map +1 -1
- package/dist/react/index.d.mts +13 -2
- package/dist/react/index.d.ts +13 -2
- package/dist/react/index.js +8 -5
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +8 -5
- package/dist/react/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -454,6 +454,7 @@ var _SsoClient = class _SsoClient {
|
|
|
454
454
|
if (!config.ssoBaseUrl) throw new SsoError("invalid_config", "ssoBaseUrl \u4E0D\u80FD\u4E3A\u7A7A");
|
|
455
455
|
const base = config.ssoBaseUrl.replace(/\/+$/, "");
|
|
456
456
|
this.config = { ...config, ssoBaseUrl: base };
|
|
457
|
+
this._serverBase = (config.serverBaseUrl ?? base).replace(/\/+$/, "");
|
|
457
458
|
}
|
|
458
459
|
// ============================================
|
|
459
460
|
// 内部方法
|
|
@@ -469,7 +470,7 @@ var _SsoClient = class _SsoClient {
|
|
|
469
470
|
if (this._discovery && now - this._discoveryFetchedAt < _SsoClient.DISCOVERY_TTL_MS) {
|
|
470
471
|
return this._discovery;
|
|
471
472
|
}
|
|
472
|
-
const url = `${this.
|
|
473
|
+
const url = `${this._serverBase}/api/oauth/.well-known/openid-configuration`;
|
|
473
474
|
try {
|
|
474
475
|
const controller = new AbortController();
|
|
475
476
|
const timeoutId = setTimeout(
|
|
@@ -500,14 +501,16 @@ var _SsoClient = class _SsoClient {
|
|
|
500
501
|
if (d) return d.authorization_endpoint;
|
|
501
502
|
return `${this.config.ssoBaseUrl}/api/oauth/authorize`;
|
|
502
503
|
}
|
|
503
|
-
/** 获取 token 端点 URL
|
|
504
|
+
/** 获取 token 端点 URL(服务器间调用:serverBaseUrl 直连优先,其次 Discovery,回退默认) */
|
|
504
505
|
async _getTokenEndpoint() {
|
|
506
|
+
if (this.config.serverBaseUrl) return `${this._serverBase}/api/oauth/token`;
|
|
505
507
|
const d = await this._getDiscovery();
|
|
506
508
|
if (d) return d.token_endpoint;
|
|
507
509
|
return `${this.config.ssoBaseUrl}/api/oauth/token`;
|
|
508
510
|
}
|
|
509
|
-
/** 获取 userinfo 端点 URL
|
|
511
|
+
/** 获取 userinfo 端点 URL(服务器间调用:serverBaseUrl 直连优先,其次 Discovery,回退默认) */
|
|
510
512
|
async _getUserinfoEndpoint() {
|
|
513
|
+
if (this.config.serverBaseUrl) return `${this._serverBase}/api/oauth/userinfo`;
|
|
511
514
|
const d = await this._getDiscovery();
|
|
512
515
|
if (d) return d.userinfo_endpoint;
|
|
513
516
|
return `${this.config.ssoBaseUrl}/api/oauth/userinfo`;
|
|
@@ -984,8 +987,8 @@ var _SsoClient = class _SsoClient {
|
|
|
984
987
|
clearAllSsoData(this.config.clientId);
|
|
985
988
|
if (refreshToken && this.config.clientId) {
|
|
986
989
|
try {
|
|
987
|
-
const discovery = await this._getDiscovery();
|
|
988
|
-
const revokeUrl = discovery?.revocation_endpoint || `${this.config.ssoBaseUrl}/api/oauth/revoke`;
|
|
990
|
+
const discovery = this.config.serverBaseUrl ? null : await this._getDiscovery();
|
|
991
|
+
const revokeUrl = this.config.serverBaseUrl ? `${this._serverBase}/api/oauth/revoke` : discovery?.revocation_endpoint || `${this.config.ssoBaseUrl}/api/oauth/revoke`;
|
|
989
992
|
const revokeBody = new URLSearchParams({
|
|
990
993
|
token: refreshToken,
|
|
991
994
|
token_type_hint: "refresh_token",
|