> ## Documentation Index
> Fetch the complete documentation index at: https://translations.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> SDK を使用して、OIDC ディスカバリーにより Auth0 でアプリケーションを設定する方法について説明します。

# OIDC ディスカバリーを使用してアプリケーションを設定する

export const AuthCodeBlock = ({filename, icon, language, highlight, children}) => {
  const [displayText, setDisplayText] = useState(children);
  const [copyText, setCopyText] = useState(children);
  const wrapperRef = React.useRef(null);
  useEffect(() => {
    let unsubscribe = null;
    function init() {
      if (!window.autorun || !window.rootStore) {
        return;
      }
      unsubscribe = window.autorun(() => {
        let processedChildrenForDisplay = children;
        let processedChildrenForCopy = children;
        for (const [key, value] of window.rootStore.variableStore.values.entries()) {
          const escapedKey = key.replaceAll(/[.*+?^${}()|[\]\\]/g, (String.raw)`\$&`);
          let displayValue = value;
          if (key === "{yourClientSecret}" && value !== "{yourClientSecret}") {
            displayValue = value.substring(0, 3) + "*****MASKED*****";
          }
          processedChildrenForDisplay = processedChildrenForDisplay.replaceAll(new RegExp(escapedKey, "g"), displayValue);
          processedChildrenForCopy = processedChildrenForCopy.replaceAll(new RegExp(escapedKey, "g"), value);
        }
        setDisplayText(processedChildrenForDisplay);
        setCopyText(processedChildrenForCopy);
      });
    }
    if (window.rootStore) {
      init();
    } else {
      window.addEventListener("adu:storeReady", init);
    }
    return () => {
      window.removeEventListener("adu:storeReady", init);
      unsubscribe?.();
    };
  }, [children]);
  useEffect(() => {
    if (!wrapperRef.current) return;
    const originalWriteText = navigator.clipboard.writeText.bind(navigator.clipboard);
    let isOverriding = false;
    const handleClick = e => {
      const button = e.target.closest('[data-testid="copy-code-button"]');
      if (!button || !wrapperRef.current.contains(button)) return;
      isOverriding = true;
      navigator.clipboard.writeText = text => {
        if (isOverriding) {
          isOverriding = false;
          navigator.clipboard.writeText = originalWriteText;
          return originalWriteText(copyText);
        }
        return originalWriteText(text);
      };
      setTimeout(() => {
        if (isOverriding) {
          isOverriding = false;
          navigator.clipboard.writeText = originalWriteText;
        }
      }, 100);
    };
    const wrapper = wrapperRef.current;
    wrapper.addEventListener('click', handleClick, true);
    return () => {
      wrapper.removeEventListener('click', handleClick, true);
      if (navigator.clipboard.writeText !== originalWriteText) {
        navigator.clipboard.writeText = originalWriteText;
      }
    };
  }, [copyText]);
  return <div ref={wrapperRef}>
      <CodeBlock filename={filename} icon={icon} language={language} lines highlight={highlight}>
        {displayText}
      </CodeBlock>
    </div>;
};

[OpenID Connect (OIDC) Discovery](https://openid.net/specs/openid-connect-discovery-1_0-final.html#RFC5785) ドキュメントには、<Tooltip tip="Identity Provider (IdP): デジタルアイデンティティを保存・管理するサービス。" cta="用語集を表示" href="/docs/ja-jp/glossary?term=identity+provider">アイデンティティプロバイダー</Tooltip> (IdP) に関するメタデータが含まれています。SDK にディスカバリーを追加して、アプリケーションが `./wellknown` エンドポイントを参照し、IdP に関する情報を利用できるようにすると、IdP との連携を設定しやすくなります。

SDK に OIDC ディスカバリーを組み込むと、次の情報を利用できます。

* IdP が公開しているエンドポイント
* 標準の [OIDC でサポートされるクレームとスコープ](/docs/ja-jp/get-started/apis/scopes/openid-connect-scopes) (これには [カスタムクレーム](/docs/ja-jp/secure/tokens/json-web-tokens/create-custom-claims) とテナントで定義されたスコープは含まれません)
* IdP がサポートする機能

アプリケーションは、次の場所にある [OpenID Connect (OIDC)](https://openid.net/specs/openid-connect-discovery-1_0.html) ディスカバリードキュメントを使用して設定できます: `https://{yourDomain}/.well-known/openid-configuration`。

<div id="sample-response">
  ### レスポンス例
</div>

export const codeExample1 = `{
  "issuer": "https://{yourDomain}.us.auth0.com/",
  "authorization_endpoint": "https://{yourDomain}.us.auth0.com/authorize",
  "token_endpoint": "https://{yourDomain}.us.auth0.com/oauth/token",
  "device_authorization_endpoint": "https://{yourDomain}.us.auth0.com/oauth/device/code",
  "userinfo_endpoint": "https://{yourDomain}.us.auth0.com/userinfo",
  "mfa_challenge_endpoint": "https://{yourDomain}.us.auth0.com/mfa/challenge",
  "jwks_uri": "https://{yourDomain}.us.auth0.com/.well-known/jwks.json",
  "registration_endpoint": "https://{yourDomain}.us.auth0.com/oidc/register",
  "revocation_endpoint": "https://{yourDomain}.us.auth0.com/oauth/revoke",
  "scopes_supported": [
    "openid",
    "profile",
    "offline_access",
    "name",
    "given_name",
    "family_name",
    "nickname",
    "email",
    "email_verified",
    "picture",
    "created_at",
    "identities",
    "phone",
    "address"
  ],
  "response_types_supported": [
    "code",
    "token",
    "id_token",
    "code token",
    "code id_token",
    "token id_token",
    "code token id_token"
  ],
  "code_challenge_methods_supported": [
    "S256",
    "plain"
  ],
  "response_modes_supported": [
    "query",
    "fragment",
    "form_post"
  ],
  "subject_types_supported": [
    "public"
  ],
  "id_token_signing_alg_values_supported": [
    "HS256",
    "RS256",
    "PS256"
  ],
  "token_endpoint_auth_methods_supported": [
    "client_secret_basic",
    "client_secret_post",
    "private_key_jwt"
  ],
  "claims_supported": [
    "aud",
    "auth_time",
    "created_at",
    "email",
    "email_verified",
    "exp",
    "family_name",
    "given_name",
    "iat",
    "identities",
    "iss",
    "name",
    "nickname",
    "phone_number",
    "picture",
    "sub"
  ],
  "entity_profiles_supported": {
    "client": [
      "native_app",
      "web_app",
      "browser_app",
      "service",
      "ai_agent"
    ],
    "subject": [
      "user",
      "service",
      "ai_agent"
    ]
  },
  "request_uri_parameter_supported": false,
  "request_parameter_supported": false,
  "token_endpoint_auth_signing_alg_values_supported": [
    "RS256",
    "RS384",
    "PS256",
    "PS384",
    "ES256",
    "ES384"
  ]
}`;

<AuthCodeBlock children={codeExample1} language="json" />

<Note>
  テナントで[Agents as Principal](/docs/ja-jp/ai-agents-mcp/agents-as-principal)が有効になっている場合、ディスカバリードキュメントには、テナントが発行できるクライアントおよびサブジェクトの[エンティティプロファイル](/docs/ja-jp/secure/tokens/access-tokens/access-token-profiles#claims)を一覧表示する`entity_profiles_supported`メタデータフィールドが含まれます。このフィールドは、`/.well-known/openid-configuration`とそのエイリアスである`/.well-known/oauth-authorization-server`の両方に表示されます。
</Note>

<div id="sample-implementation">
  ### 実装例
</div>

たとえば、Katana v3 (OWIN) で OIDC ミドルウェアを設定するには、次のようにします。

1. NuGet パッケージ **Microsoft.Owin.Security.OpenIdConnect** (v3.x.x) をインストールします
2. `App_Start\Startup.Auth.cs` を開き、現在の実装を以下の内容に置き換えます。

export const codeExample2 = `   app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = CookieAuthenticationDefaults.AuthenticationType
});

app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
    Authority = "https://{yourDomain}/",
    ClientId = "{yourClientId}",
    SignInAsAuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
    ResponseType = "token",
    Notifications = new OpenIdConnectAuthenticationNotifications
    {
        // 任意: JWT に含まれるクレームを読み取ったり変更したりできます
        SecurityTokenValidated = context =>
        {
            // Auth0 アクセストークンをクレームとして追加
            var accessToken = context.ProtocolMessage.AccessToken;
            if (!string.IsNullOrEmpty(accessToken))
            {
                context.AuthenticationTicket.Identity.AddClaim(new Claim("access_token", accessToken));
            }
            return Task.FromResult(0);
        }
    }
});
`;

<AuthCodeBlock children={codeExample2} language="text" />

<div id="rsa-algorithm-for-jwts">
  ## JWT 用の RSA アルゴリズム
</div>

OIDC ミドルウェアは、対称キーで署名された <Tooltip tip="JSON Web トークン（JWT）: 2 者間でクレームを安全に表現するために使用される標準的な ID トークン形式（多くの場合、アクセストークン形式でもあります）。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=JWTs">JWT</Tooltip> をサポートしていません。公開鍵と秘密鍵を使用する RSA アルゴリズムを使うように、アプリケーションを設定してください。

1. [Auth0 Dashboard > 設定](https://manage.auth0.com/#/applications/\{YOUR_AUTH0_CLIENT_ID}/settings) に移動します。
2. **Advanced Settings** までスクロールします。
3. **OAuth** タブで、**JSON Web Token(JWT) Signature Algorithm** に `RS256` を設定し、**Save** をクリックします。

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  OIDC エンタープライズ接続がある場合は、Private Key JWT に [追加の署名アルゴリズム](/docs/ja-jp/authenticate/enterprise-connections/private-key-jwt-client-auth#configure-private-key-jwt-client-authentication) を選択できます。
</Callout>

この設定により、Auth0 は秘密署名鍵で署名された JWT を発行します。アプリケーションは公開署名鍵を使ってそれらを検証します。

<div id="configure-applications-with-oauth-20-authorization-server-metadata">
  ## OAuth 2.0 Authorization Server Metadata を使用してアプリケーションを構成する
</div>

アプリケーションまたは SDK が [OAuth RFC-8414](https://www.rfc-editor.org/rfc/rfc8414) の <Tooltip tip="認可サーバー: ユーザーのアクセス範囲の境界を定義するのに役立つ中央集約型サーバー。たとえば、認可サーバーはユーザーが利用できるデータ、タスク、機能を制御できます。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=Authorization+Server">認可サーバー</Tooltip> メタデータ仕様を参照している場合は、<Tooltip tip="OAuth 2.0: 認可プロトコルとワークフローを定義する認可フレームワーク。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=OAuth">OAuth</Tooltip> エイリアスを使用して、IdP に関するメタデータを取得できます: `/.well-known/oauth-authorization-server`。たとえば、[Auth0 Model Context Protocol Server](/docs/ja-jp/get-started/auth0-mcp-server) では、すべての OAuth application が OAuth Authorization Server Metadata 仕様を参照することを推奨しています。

<div id="learn-more">
  ## 詳細はこちら
</div>

* [JSON Web Tokens](/docs/ja-jp/secure/tokens/json-web-tokens)
* [カスタムクレームを作成する](/docs/ja-jp/secure/tokens/json-web-tokens/create-custom-claims)
