> ## 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) + "*****マスク済み*****";
          }
          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="IDプロバイダー（IdP）: デジタルアイデンティティを保存および管理するサービス。" cta="用語集を見る" href="/ja/docs/glossary?term=identity+provider">IDプロバイダー</Tooltip> (IdP) に関するメタデータが含まれています。SDK にディスカバリーを追加し、アプリケーションが `./wellknown` エンドポイントを参照して IdP に関する情報を取得できるようにすると、IdP との統合を設定しやすくなります。

SDK に OIDC ディスカバリーを統合すると、次の情報を利用できます。

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

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

<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"
  ],
  "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" />

<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 Token（JWT）: 2 者間でクレームを安全に表現するために使用される標準的な IDトークン形式（多くの場合、アクセストークン形式としても使用されます）。" cta="用語集を表示" href="/ja/docs/glossary?term=JWTs">JWTs</Tooltip> をサポートしていません。公開鍵/秘密鍵を使用する RSA アルゴリズムを使用するように、アプリを設定してください。

1. [Dashboard > Settings](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 の Enterprise 接続がある場合は、Private Key JWT に [追加の署名アルゴリズム](/ja/docs/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 認可サーバーのメタデータを使用してアプリケーションを設定する
</div>

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

<div id="learn-more">
  ## 詳しく見る
</div>

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