> For the complete documentation index, see [llms.txt](https://gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.com/docs/documentation/ja-gitbook-documentation/publish/site-audience/authenticated-access/setting-up-aws-cognito.md). Agents can also search and read this documentation through its [MCP server](https://gitbook.com/docs/~gitbook/mcp).

# AWS Cognito の設定

ドキュメント閲覧者向けに AWS Cognito のログイン画面を設定します

{% hint style="warning" %}
このガイドでは、ドキュメント用の保護されたサインイン画面を設定する手順を説明します。このガイドを始める前に、まず次の手順を完了してください。 [認証済みアクセスを有効にする](https://gitbook.com/docs/documentation/ja-gitbook-documentation/publish/site-audience/authenticated-access/enabling-authenticated-access.md).
{% endhint %}

AWS Cognito を使用して認証アクセス付きで GitBook サイトを設定する手順は次のとおりです：

{% stepper %}
{% step %}
**新しい AWS Cognito アプリケーションを作成する**

AWS ダッシュボードから AWS Cognito アプリケーションを作成します。
{% endstep %}

{% step %}
**AWS Cognito の連携をインストールして設定する**

AWS Cognito の連携をインストールし、必要な設定を追加します。
{% endstep %}

{% step %}
**アダプティブコンテンツ用に AWS Cognito を設定する（任意）**

GitBook のアダプティブコンテンツと連携するように AWS Cognito を設定します。
{% endstep %}
{% endstepper %}

### 新しい AWS Cognito アプリケーションを作成する

Cognito で目的の User Pool に移動し、App integration をクリックします。Cognito ドメインを控えておいてください。連携を設定する際に必要になります。

下までスクロールして「Create app client」をクリックします。アプリのタイプは「Confidential client」を選択します。さらに下にスクロールして Hosted UI settings に進みます。allowed Callback URLs に、セクションに連携をインストールした際に GitBook から取得した Callback URL を入力します。

さらに下にスクロールして「OAuth 2.0 grant types」に進み、「Authorization code grant」が選択されていることを確認します。

「OpenID connect scopes」では、OpenID が選択されていることを確認します。

下までスクロールして「Create app client」をクリックします。

作成した app client をクリックし、Client ID と Client Secret を控えておいてください。

### AWS Cognito の連携をインストールして設定する

GitBook アプリ内の integrations に移動し、カテゴリとして authenticated access を選択して、AWS Cognito の連携をインストールします。

<figure><img src="https://4217681718-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-eacab294e24488e224d7378a7788c8958026486e%2F25_04_10_setting_up_oidc_2.png?alt=media" alt="A GitBook screenshot showing the AWS Cognito integration install screen"><figcaption></figcaption></figure>

サイトにインストールしたら、configuration に移動し、Save ボタンのすぐ上にある Callback URL を控えておいてください。Cognito を設定する際に必要になります。

連携をインストールしたセクションで、Cognito 連携の設定画面を開きます。

次の画像のようになります：

<figure><img src="https://4217681718-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-fb06520c25389f87e3cfb23de34adedddb063049%2F25_04_10_setting_up_aws_cognito_1.png?alt=media" alt="A GitBook screenshot showing the AWS Cognito configuration screen"><figcaption></figcaption></figure>

Client ID、Cognito Domain、Client Secret には、Cognito から取得した値を貼り付けます。

Save をクリックします。

次に、GitBookでインテグレーションのモーダルを閉じ、「サイトを管理」ボタンをクリックします。 **オーディエンス**を開き、 **認証済みアクセス**を選択し、バックエンドとしてCognitoを選びます。次に、 **オーディエンスを更新**をクリックします。サイトの画面に移動して、 **公開**をクリックします。\
\
これで、AWS Cognitoアプリケーションによって制御される認証済みアクセスの背後にサイトが公開されます。試すには、「訪問」をクリックしてください。Cognitoでのサインインを求められます。これにより、AWS Cognitoを使用した認証済みアクセスの背後にサイトが公開されていることを確認できます。

### アダプティブコンテンツ用に AWS Cognito を設定する（任意）

GitBook で認証アクセスとともに Adaptive Content を活用するには、Amazon Cognito のユーザープールを設定して、ID トークンにカスタムクレームを含める必要があります。

通常は、 [Cognito Lambda トリガー](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-token-generation.html)を作成します。具体的には、 *トークン生成前* Lambda を作成し、カスタムクレームを上書きまたは追加する JSON ペイロードを返します。これらのクレームには、ユーザーロール、サブスクリプションのプラン、その他コンテンツに関連するメタデータを含めることができます。

例は次のようになります：

```javascript
export const handler = async (event, context) => {
  // event リクエストからユーザー属性を取得
  const userAttributes = event.request.userAttributes;

  // event レスポンスに追加のクレームを追加
  event.response = {
    "claimsAndScopeOverrideDetails": {
      "idTokenGeneration": {},
      "accessTokenGeneration": {
        "claimsToAddOrOverride": {
          "products": ['api', 'sites', 'askAI'],
          "isBetaUser": true,
          "isAlphaUser": true,
        }
      }
    }
  };
  // Amazon Cognito に返す
  context.done(null, event);
};
```

<figure><img src="https://4217681718-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-6f6d58f8848b4f8635be3b3b469875d727981514%2F25_06_30_setting_up_aws_cognito_2.png?alt=media" alt=""><figcaption></figcaption></figure>

追加すると、これらのキーと値のペアは認証トークンに含まれて GitBook に渡され、サイトが認証済みユーザーのプロフィールに基づいてコンテンツを動的に適応できるようになります。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://gitbook.com/docs/documentation/ja-gitbook-documentation/publish/site-audience/authenticated-access/setting-up-aws-cognito.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
