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

# OIDCでのリソース所有者のパスワードフロー

> OIDC準拠のパイプラインがリソース所有者のパスワード（ROP）フローに与える影響を説明します。

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/resource-owner-password-flow)（リソース所有者のパスワード付与（ROPG）と呼ばれることもある）は、信頼性の高いアプリケーションでアクティブな認証を行うために使用されます。認可コードや暗黙的付与とは異なり、この認証メカニズムではユーザーはAuth0にリダイレクトされず、単一の要求でユーザーを認証し、パスワード資格情報をトークンと交換します。

OIDC準拠のパイプラインがリソース所有者のパスワード（ROP）フローに影響を与えるエリアは以下のとおりです。

* 認証要求
* 認証応答
* IDトークンの構造
* アクセストークンの構造

## 認証要求

### 旧

```json lines theme={null}
POST /oauth/ro HTTP 1.1
Content-Type: application/json
{
  "grant_type": "password",
  "client_id": "123",
  "username": "alice",
  "password": "A3ddj3w",
  "connection": "my-database-connection",
  "scope": "openid email favorite_color offline_access",
  "device": "my-device-name"
}
```

`device`パラメーターは、`offline_access`スコープを渡してリフレッシュトークンを要求する場合にのみ必要です。

### OIDC準拠

```json lines theme={null}
POST /oauth/token HTTP 1.1
Content-Type: application/x-www-form-urlencoded
grant_type=http%3A%2F%2Fauth0.com%2Foauth%2Fgrant-type%2Fpassword-realm&client_id=123&username=alice&password=A3ddj3w&realm=my-database-connection&scope=openid+email+offline_access&audience=https%3A%2F%2Fapi.example.com
```

* 資格情報交換を実行するエンドポイントは`/oauth/token`です。
* Auth0の独自の付与タイプは、特定の接続（`realm`）からユーザーを認証するために使用されます。標準のOIDCパスワード付与もサポートされていますが、`realm`などAuth0固有のパラメーターは受け入れません。
* `favorite_color`は有効なスコープでなくなりました。
* `device`パラメーターは削除されています。
* `audience`パラメーターは任意です。

## 認証応答

### 旧

```json lines theme={null}
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
Pragma: no-cache
{
    "access_token": "SlAV32hkKG",
    "token_type": "Bearer",
    "refresh_token": "8xLOxBtZp8",
    "expires_in": 3600,
    "id_token": "eyJ..."
}
```

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

### OIDC準拠

```json lines theme={null}
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
Pragma: no-cache
{
    "access_token": "eyJ...",
    "token_type": "Bearer",
    "refresh_token": "8xLOxBtZp8",
    "expires_in": 3600,
    "id_token": "eyJ..."
}
```

* 返されるアクセストークンは、`/userinfo`エンドポイント（`audience`パラメーターで指定したAPIが`RS256`を[署名アルゴリズム](/docs/ja-jp/get-started/applications/signing-algorithms)として使用していることを条件とする）と、`audience`パラメーターで指定したリソースサーバー（任意）の呼び出しに対してのみ有効です。
* IDトークンは、公開アプリケーションによって要求されると、`RS256`を使用して強制的に署名されます。詳細については、「[機密アプリケーションとパブリックアプリケーション](/docs/ja-jp/get-started/applications/confidential-and-public-applications)」をお読みください。
* リフレッシュトークンは、`offline_access`スコープが付与された場合にのみ返されます。

## 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"
}`;

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

* IDトークンは、公開アプリケーションによって要求されると、`RS256`を使用して強制的に署名されます。
* `favorite_color`クレームには名前空間が存在し、ルールを通じて追加される必要があります。詳細については、「[名前空間カスタムクレームを作成する](/docs/ja-jp/secure/tokens/json-web-tokens/create-custom-claims)」をお読みください。

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

### 旧

```json JSON 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`を署名アルゴリズムとして使用していることを条件とする）と、`audience`パラメーターで指定したリソースサーバーの呼び出しに対してのみ有効です。
* `/userinfo`が唯一指定されたオーディエンスである場合でも、不透明なアクセストークンが返されることがあります。

## 標準のパスワード付与要求

Auth0のパスワードレルム付与は標準のOIDCによって定義されてはいませんが、Auth0固有の`realm`パラメーターをサポートしているため、レガシーのリソース所有者エンドポイントの代わりとして推奨されます。OIDC認証を使用する場合には、[標準のOIDCフローもサポートされます](/docs/ja-jp/get-started/authentication-and-authorization-flow/resource-owner-password-flow)。

## もっと詳しく

* [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-implicit-flow)
* [OIDCにおけるリフレッシュトークン](/docs/ja-jp/authenticate/login/oidc-conformant-authentication/oidc-adoption-refresh-tokens)
