跳轉到主要內容

函式:fetchServerConfig()

function fetchServerConfig(issuer: string, config: ServerMetadataConfig): Promise<AuthServerConfig>;

根據簽發者(Issuer)與授權伺服器類型,擷取伺服器設定。

此函式會根據伺服器類型自動判斷 well-known URL,因為 OAuth 及 OpenID Connect 伺服器的中繼資料端點慣例不同。

參數

issuer

string

授權伺服器的簽發者(Issuer)URL。

config

ServerMetadataConfig

包含伺服器類型與可選轉換函式的設定物件。

回傳值

Promise<AuthServerConfig>

一個解析為伺服器設定的 Promise。

參考

範例

import { fetchServerConfig } from 'mcp-auth';
// 擷取 OAuth 伺服器設定
// 這將從 `https://auth.logto.io/.well-known/oauth-authorization-server/oauth` 取得中繼資料
const oauthConfig = await fetchServerConfig('https://auth.logto.io/oauth', { type: 'oauth' });

// 擷取 OpenID Connect 伺服器設定
// 這將從 `https://auth.logto.io/oidc/.well-known/openid-configuration` 取得中繼資料
const oidcConfig = await fetchServerConfig('https://auth.logto.io/oidc', { type: 'oidc' });

例外

若擷取操作失敗則會丟出例外。

例外

若伺服器中繼資料無效或不符合 MCP 規範則會丟出例外。