> ## 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.

# トークンの取得

> Authorization Code Flow を使用して、認可コードからトークンを取得します。

export const ReleaseStageNotice = ({feature, stage, plans, contact, terms}) => {
  const stageTextMap = {
    "beta": "Beta",
    "ea": "早期アクセス"
  };
  const stageText = stageTextMap[stage] || "製品リリース段階";
  const prsLink = "/docs/troubleshoot/product-lifecycle/product-release-stages";
  const linkify = (text, url) => {
    return <a href={url} target="_blank" rel="noreferrer" class="link">{text}</a>;
  };
  const includeDetails = (plans, contact, terms) => {
    const hasDetails = terms || plans || contact;
    if (!hasDetails) return null;
    return <span data-as="p">
            {plans && <>この機能は{linkify(`${plans}プラン`, "https://auth0.com/pricing")}でご利用いただけます。 </>}
            {contact && "参加をご希望の場合は、" + contact + "までお問い合わせください。 "}
            {terms && <>この機能を使用することにより、Oktaの該当する無料トライアル規約および{linkify("Master Subscription Agreement", "https://www.okta.com/legal")}に同意したものとみなされます。</>}
        </span>;
  };
  return <Warning>
            <span data-as="p">
                <strong>{feature}機能は現在、{linkify(stageText, prsLink)}です。</strong>
            </span>

            {includeDetails(plans, contact, terms)}
        </Warning>;
};

export const ResponseSchema = ({statusCode, type = "{}", children}) => {
  const [open, setOpen] = useState(false);
  return <div className="border border-gray-100 dark:border-gray-800 rounded-lg mb-3 overflow-hidden">
      <div className={`flex items-center gap-2.5 px-4 py-2.5 cursor-pointer select-none ${open ? "bg-gray-50 dark:bg-gray-800" : ""}`} onClick={() => setOpen(!open)}>
        {statusCode && <span className="border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 font-mono text-xs px-1.5 py-0.5 rounded">
            {statusCode.startsWith("default") ? "default" : statusCode}
          </span>}
        <span className="text-gray-500 dark:text-gray-400 text-sm font-mono">
          {type}
        </span>
        <span className="text-gray-400 dark:text-gray-500 text-sm italic">
          application/json
        </span>
        <svg className={`ml-auto opacity-50 transition-transform duration-200 ${open ? "rotate-180" : ""}`} width="16" height="16" viewBox="0 0 16 16" fill="none">
          <path d="M4 6l4 4 4-4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
        </svg>
      </div>
      {open && <div className="px-4 pt-1 pb-3 border-t border-gray-100 dark:border-gray-800">
          {children}
        </div>}
    </div>;
};

<div id="endpoint">
  ## エンドポイント
</div>

`POST /oauth/token`

トークンベースの認証では、`oauth/token` エンドポイントを使用して、アプリケーションが保護された API に対して認証済みの呼び出しを行うためのアクセストークンを取得します。必要に応じて、ID トークンやリフレッシュトークンを取得することもできます。ID トークンには、アプリケーションが抽出してよりよいユーザー体験の提供に役立てられる、スコープの形のユーザー情報が含まれています。リフレッシュトークンを使用すると、現在のトークンの有効期限が切れたあとでも、ユーザー体験を損なうことなく、アプリケーションで新しいアクセストークンをリクエストできます。詳しくは、[ID Tokens](https://auth0.com/docs/secure/tokens/id-tokens) と [Refresh Tokens](https://auth0.com/docs/secure/tokens/refresh-tokens) を参照してください。

リフレッシュトークンを取得できる OAuth 2.0 フローは、次のものに限られます。

* [Authorization Code Flow (Authorization Code)](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow)
* [Authorization Code Flow with PKCE (Authorization Code with PKCE)](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow-with-pkce)
* [Resource Owner Password](https://auth0.com/docs/get-started/authentication-and-authorization-flow/resource-owner-password-flow)
* [Device Authorization Flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/device-authorization-flow)
* Token Exchange\*

これは、一般的な Web アプリが API にアクセスする際に使用するフローです。このエンドポイントを使って、Authorization Code をトークンに交換します。

<div id="headers">
  ## ヘッダー
</div>

<ParamField header="DPoP" type="string">
  リクエスト用の DPoP プルーフです。これは任意項目で、アプリケーションで Demonstrating Proof-of-Possession を使用している場合にのみ必要です。
</ParamField>

<div id="body-parameters">
  ## リクエストボディのパラメータ
</div>

<div className="prose-sm prose-gray dark:prose-invert">
  <span data-as="p">リクエストボディは `application/x-www-form-urlencoded` 形式です。</span>
</div>

<ParamField body="grant_type" type="string" required>
  使用するフローを指定します。認可コード の場合は `authorization_code` を使用します。
</ParamField>

<ParamField body="client_id" type="string" required>
  アプリケーションの Client ID です。
</ParamField>

<ParamField body="client_secret" type="string" required>
  アプリケーションの Client Secret です。
</ParamField>

<ParamField body="code" type="string" required>
  最初の `/authorize` 呼び出しで受け取った 認可コード です。
</ParamField>

<ParamField body="redirect_uri" type="string">
  [GET /authorize](#authorization-code-grant) エンドポイントで設定している場合にのみ必要です。`/authorize` で指定した値は、`/oauth/token` で設定する値と一致している必要があります。
</ParamField>

<div id="response-schema">
  ## レスポンススキーマ
</div>

<ResponseSchema>
  <ResponseField name="access_token" type="string">
    アクセストークン。
  </ResponseField>

  <ResponseField name="refresh_token" type="string">
    新しいアクセストークンを取得するためのリフレッシュトークン。
  </ResponseField>

  <ResponseField name="id_token" type="string">
    IDトークン。
  </ResponseField>

  <ResponseField name="token_type" type="string">
    トークンの種類。通常は `Bearer` です。
  </ResponseField>

  <ResponseField name="expires_in" type="integer">
    アクセストークンの有効期間 (秒) 。
  </ResponseField>
</ResponseSchema>

<div id="agent-access-tokens">
  ## エージェントアクセストークン
</div>

<ReleaseStageNotice feature="Agents as Principal" stage="ea" contact="Auth0 Support" terms="true" />

認可コードを交換するアプリケーションがエージェントにリンクされ、対象 API でエージェントの subject クレームが有効になっている場合、発行されるアクセストークンには、ユーザーに代わって動作する actor としてエージェントが記録されます。

* `sub` クレームは引き続きユーザー識別子です。エージェントのアイデンティティは `sub` ではなく `act` クレームに示されます。
* `act` クレームはエージェントを識別します: `{ "sub": "agt_72jbvv7LfRKYp59gtRLtkn", "sub_profile": "ai_agent", "client_id": "YOUR_CLIENT_ID", "iss": "https://YOUR_DOMAIN/" }`。
* トークンには `sub_profile: "user"` と、たとえば `web_app ai_agent` のように `ai_agent` 接尾辞が付いた `client_profile` が含まれます。

アクセストークンにセッション転送または On-Behalf-Of トークン交換による actor がすでに含まれている場合は、その actor が優先され、エージェントの actor は追加されません。これらのクレームはアクセストークンにのみ適用され、ID トークンには影響しません。レスポンスオブジェクトのスキーマは変更されません。詳細については、[Access Token Profiles](/docs/ja-jp/secure/tokens/access-tokens/access-token-profiles#claims)を参照してください。

<div id="response-messages">
  ## レスポンスメッセージ
</div>

| ステータス | 説明        |
| ----- | --------- |
| 200   | トークンの取得成功 |
