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

# AWS Cognito の設定

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

{% hint style="warning" %}
このガイドでは、ドキュメント用の保護されたサインイン画面を設定する手順を説明します。このガイドを進める前に、まず次のプロセスを完了していることを確認してください。 [認証済みアクセスを有効にする](/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」をクリックします。

作成したアプリクライアントをクリックし、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%2FCZy21M4LIPwMVSxI3ec1%2FScreen%20Shot%202024-12-13%20at%203.37.39%20PM.png?alt=media&amp;token=4e31d496-04eb-4d00-ac45-011b543edfe4" 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%2Fgy177CzFZiy6U4IntLUE%2FScreen%20Shot%202024-12-13%20at%203.41.57%20PM.png?alt=media&amp;token=3823d5cb-56e0-4e02-abd6-6d6d66cacf71" alt="A GitBook screenshot showing the AWS Cognito configuration screen"><figcaption></figcaption></figure>

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

Save を押します。

次に、GitBook でインテグレーションのモーダルを閉じ、Manage site ボタンをクリックします。に移動し **対象**、次を選択します **認証アクセス**、そして Cognito をバックエンドとして選択し、次にクリックします **対象を更新**。サイトの画面に移動して **公開**.\
\
サイトは、あなたの Auth0 アプリケーションによって制御される認証済みアクセスの背後で公開されました。試すには、「Visit」をクリックします。Cognito でサインインするよう求められます。これにより、サイトが Auth0 を使用した認証済みアクセスの背後で公開されていることが確認できます。

### アダプティブ コンテンツ用に 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)—具体的には *Pre Token Generation* 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%2FwwKLiRUOJ27tjJCPc1Vd%2FScreenshot%202025-06-30%20at%2017.31.23.png?alt=media&amp;token=f015ad33-1e96-47d4-82a5-e3b259f55a0e" 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.
