@nihplod/sso-sdk 1.2.0 → 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.
@@ -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.config.ssoBaseUrl}/api/oauth/.well-known/openid-configuration`;
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(优先 Discovery,回退默认) */
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(优先 Discovery,回退默认) */
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",