> ## Documentation Index
> Fetch the complete documentation index at: https://docs-dev-docs-event-stream-action-templates.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# OIDCを使った暗黙フロー

> 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>;
};

[暗黙フロー](/docs/ja-jp/get-started/authentication-and-authorization-flow/implicit-flow-with-form-post)は従来、シークレットを安全に保存できないアプリケーションで使用されていましたが、このフローの使用はアクセストークンを要求するためのベストプラクティスとはみなされなくなりました。新しい実装では、[PKCEを使った認可コードフロー](/docs/ja-jp/get-started/authentication-and-authorization-flow/authorization-code-flow-with-pkce)を使用してください。ただし、アプリケーションがユーザー認証にIDトークンのみを必要とする場合、フォームPOST応答モードと併用することでワークフローが効率化します。この場合は、[ハイブリッドフロー](/docs/ja-jp/get-started/authentication-and-authorization-flow/hybrid-flow)の一部として使用します。

認証に暗黙フローを使用すると、リフレッシュトークンは返されなくなります。

さらに、OIDC準拠のパイプラインが認証要求、認証応答、IDトークンの構造、およびアクセストークンの構造の領域で暗黙フローに影響を与えます。

## 認証要求

### 旧

```http lines theme={null}
GET /authorize?
    response_type=token
    &scope=openid email favorite_color offline_access
    &client_id=123
    &state=af0ifjsldkj
    &redirect_uri=https://app.example.com
    &device=my-device-name
```

`device`パラメーターは、`offline_access`スコープを渡してリフレッシュトークンを要求する場合にのみ必要です。詳細については、「[リフレッシュトークン](/docs/ja-jp/secure/tokens/refresh-tokens)」をお読みください。

### OIDC準拠

```http lines theme={null}
GET /authorize?
    response_type=token id_token
    &scope=openid email
    &client_id=123
    &state=af0ifjsldkj
    &nonce=jxdlsjfi0fa
    &redirect_uri=https://app.example.com
    &audience=https://api.example.com
```

* `response_type`は、アクセストークンとIDトークンの両方を受け取りたいことを示します。
* リフレッシュトークンは暗黙的付与では許可されていません。代わりに、`prompt=none`を使用してください。詳細については「[サイレント認証を構成する](/docs/ja-jp/authenticate/login/configure-silent-authentication)」をお読みください。
* `favorite_color`は有効なスコープでなくなりました。
* `audience`は任意です。
* `nonce`は暗号学的に安全なランダム文字列でなければなりません。詳細については、「[暗黙フロー使用時にリプレイ攻撃を軽減する](/docs/ja-jp/get-started/authentication-and-authorization-flow/implicit-flow-with-form-post/mitigate-replay-attacks-when-using-the-implicit-flow)」をお読みください。

## 認証応答

### 旧

```json lines theme={null}
HTTP/1.1 302 Found
Location: https://app.example.com/#
    access_token=SlAV32hkKG
    &expires_in=86400
    &state=af0ifjsldk
    &id_token=eyJ...
    &refresh_token=8xLOxBtZp8
    &token_type=Bearer
```

* 返されるアクセストークンは、[`/userinfo`](/docs/ja-jp/api/authentication#get-user-info)エンドポイントの呼び出しに対して有効です。
* リフレッシュトークンは、`device`パラメーターが渡され、`offline_access`スコープが要求された場合にのみ返されます。

### OIDC準拠

```json lines theme={null}
HTTP/1.1 302 Found
Location: https://app.example.com/#
    access_token=eyJ...
    &expires_in=86400
    &state=af0ifjsldk
    &id_token=eyJ...
    &token_type=Bearer
```

* 返されるアクセストークンは、[`/userinfo`](/docs/ja-jp/api/authentication#get-user-info)エンドポイント（`audience`パラメーターで指定したAPIが`RS256`を[署名アルゴリズム](/docs/ja-jp/get-started/applications/signing-algorithms)として使用していることを条件とする）と、`audience`パラメーターで指定したリソースサーバー（任意）の呼び出しに対してのみ有効です。
* `response_type=id_token`を使用する場合は、IDトークンのみが返されます。リフレッシュトークンは暗黙的付与では許可されていません。代わりに、`prompt=none`を使用してください。

## IDトークンの構造

### 旧

export const codeExample1 = `{
    "sub": "auth0|alice",
    "iss": "https://{yourDomain}/",
    "aud": "123",
    "exp": 1482809609,
    "iat": 1482773609,
    "email": "alice@example.com",
    "email_verified": true,
    "favorite_color": "blue"
}`;

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

### OIDC準拠

export const codeExample2 = `{
    "sub": "auth0|alice",
    "iss": "https://{yourDomain}/",
    "aud": "123",
    "exp": 1482809609,
    "iat": 1482773609,
    "email": "alice@example.com",
    "email_verified": true,
    "https://app.example.com/favorite_color": "blue",
    "nonce": "jxdlsjfi0fa"
}`;

<AuthCodeBlock children={codeExample2} language="json" filename="JSON" />

* `favorite_color`クレームには名前空間が存在し、ルールを通じて追加される必要があります。詳細については、「[名前空間カスタムクレームを作成する](/docs/ja-jp/secure/tokens/json-web-tokens/create-custom-claims)」をお読みください。
* IDトークンを検証したら、アプリケーションはリプレイ攻撃を軽減するために<Tooltip data-tooltip-id="react-containers-DefinitionTooltip-0" href="/docs/ja-jp/glossary?term=nonce" tip="Nonce: リプレイ攻撃を検出および防止するために、認証プロトコルで1回だけ発行される任意の数値。" cta="用語集の表示">nonce</Tooltip>を検証する必要があります。

## アクセストークンの構造（任意）

### 旧

```bash HTTP lines theme={null}
SlAV32hkKG
```

返されるアクセストークンは不透明で、`/userinfo`の呼び出しに対してのみ有効です。

### OIDC準拠

export const codeExample3 = `{
    "sub": "auth0|alice",
    "iss": "https://{yourDomain}/",
    "aud": [
        "https://api.example.com",
        "https://{yourDomain}/userinfo"
    ],
    "azp": "123",
    "exp": 1482816809,
    "iat": 1482809609,
    "scope": "openid email"
}`;

<AuthCodeBlock children={codeExample3} language="json" filename="JSON" />

* 返されるアクセストークンは、`/userinfo`（`audience`パラメーターで指定したAPIが`RS256`を[署名アルゴリズム](/docs/ja-jp/get-started/applications/change-application-signing-algorithms)として使用していることを条件とする）と、`audience`パラメーターで指定したリソースサーバーの呼び出しに対してのみ有効です。
* `/userinfo`が唯一指定されたオーディエンスである場合でも、不透明なアクセストークンが返されることがあります。

## もっと詳しく

* [OIDCにおけるアクセストークン](/docs/ja-jp/authenticate/login/oidc-conformant-authentication/oidc-adoption-access-tokens)
* [OIDCを持つ外部API](/docs/ja-jp/authenticate/login/oidc-conformant-authentication/oidc-adoption-apis)
* [OIDCを使った認可コードフロー](/docs/ja-jp/authenticate/login/oidc-conformant-authentication/oidc-adoption-auth-code-flow)
* [OIDCを使用したクライアントの資格情報フロー](/docs/ja-jp/authenticate/login/oidc-conformant-authentication/oidc-adoption-client-credentials-flow)
* [OIDCを使用した委任](/docs/ja-jp/authenticate/login/oidc-conformant-authentication/oidc-adoption-delegation)
* [OIDCにおけるリフレッシュトークン](/docs/ja-jp/authenticate/login/oidc-conformant-authentication/oidc-adoption-refresh-tokens)
