

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 Amazon Cognito 字首網域進行受管登入
<a name="cognito-user-pools-assign-domain-prefix"></a>

受管登入的預設體驗託管在 AWS 擁有的網域上。這種方法進入的障礙很低，選擇字首名稱且處於作用中狀態，但沒有自訂網域的信任啟發功能。Amazon Cognito 網域選項和自訂網域選項之間沒有成本差異。唯一的差別是您引導使用者前往的網址中的網域。對於第三方 IdP 重新導向和用戶端憑證流程的情況，託管網域幾乎沒有可見效果。自訂網域更適合使用者使用受管登入來登入，並且會與不符合應用程式網域的身分驗證網域互動的情況。

託管的 Amazon Cognito 網域具有您選擇的字首，但託管於根網域 `amazoncognito.com`。以下是範例：

```
https://{{cognitoexample}}.auth.{{ap-south-1}}.amazoncognito.com
```

所有字首網域都遵循此格式：`{{prefix}}`.`auth`.{{`AWS 區域 code`}}.`amazoncognito``com`. [自訂網域](cognito-user-pools-add-custom-domain.md)使用者集區可以在您擁有的任何網域上託管受管登入或託管 UI 頁面。

**注意**  
為了增強 Amazon Cognito 應用程式的安全性，使用者集區端點的父網域會在[公用尾碼清單 (PSL)](https://publicsuffix.org/) 中註冊。PSL 可協助使用者的網頁瀏覽器對您的使用者集區端點及其設定的 Cookie 建立一致的了解。  
使用者集區父網域採用下列格式。  

```
auth.{{Region}}.amazoncognito.com
auth-fips.{{Region}}.amazoncognito.com
```

若要使用 新增應用程式用戶端和使用者集區網域 AWS 管理主控台，請參閱 [建立應用程式用戶端](user-pool-settings-client-apps.md#cognito-user-pools-app-idp-settings-console-create)。

**Topics**
+ [先決條件](#cognito-user-pools-assign-domain-prefix-prereq)
+ [設定 Amazon Cognito 網域字首](#cognito-user-pools-assign-domain-prefix-step-1)
+ [驗證您的登入頁面](#cognito-user-pools-assign-domain-prefix-verify)

## 先決條件
<a name="cognito-user-pools-assign-domain-prefix-prereq"></a>

開始之前，您需要：
+ 搭配應用程式用戶端的使用者集區。如需詳細資訊，請參閱[使用者集區入門](getting-started-user-pools.md)。

## 設定 Amazon Cognito 網域字首
<a name="cognito-user-pools-assign-domain-prefix-step-1"></a>

您可以使用 AWS 管理主控台 或 AWS CLI 或 API 來設定使用者集區網域。

------
#### [ Amazon Cognito console ]

**設定網域**

1. 導覽至**品牌**下的**網域**功能表。

1. 在**網域**旁邊，選擇**動作**，然後選取**建立 Cognito 網域**。如果您已設定使用者集區字首網域，請選擇**刪除 Cognito 網域**，然後再建立新的自訂網域。

1. 輸入可用的網域字首來搭配 **Amazon Cognito 網域**使用。如需設定**自訂網域**的資訊，請參閱 [使用您自己的網域進行受管登入](cognito-user-pools-add-custom-domain.md)。

1. 選擇**品牌版本**。您的品牌版本適用於該網域中的所有使用者互動頁面。您的使用者集區可以託管所有應用程式用戶端的受管登入或託管 UI 品牌。
**注意**  
您可以擁有自訂網域和字首網域，但 Amazon Cognito 僅提供*自訂*網域的`/.well-known/openid-configuration`端點。

1. 選擇**建立**。

------
#### [ CLI/API ]

使用下列命令來建立網域字首，並將其指派給您的使用者集區。

**設定使用者集區網域**
+ AWS CLI: `aws cognito-idp create-user-pool-domain`

  **範例**：`aws cognito-idp create-user-pool-domain --user-pool-id {{<user_pool_id>}} --domain {{<domain_name>}} --managed-login-version {{2}}`
+ 使用者集區 API 操作：[CreateUserPoolDomain](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_CreateUserPoolDomain.html)

**取得網域的相關資訊**
+ AWS CLI: `aws cognito-idp describe-user-pool-domain`

  **範例**：`aws cognito-idp describe-user-pool-domain --domain {{<domain_name>}}`
+ 使用者集區 API 操作：[DescribeUserPoolDomain](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_DescribeUserPoolDomain.html)

**刪除網域**
+ AWS CLI: `aws cognito-idp delete-user-pool-domain`

  **範例**：`aws cognito-idp delete-user-pool-domain --domain {{<domain_name>}}`
+ 使用者集區 API 操作：[DeleteUserPoolDomain](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_DeleteUserPoolDomain.html)

------

## 驗證您的登入頁面
<a name="cognito-user-pools-assign-domain-prefix-verify"></a>
+ 驗證可從 Amazon Cognito 託管網域使用上述登入頁面。

  ```
  https://{{<your_domain>}}/login?response_type=code&client_id={{<your_app_client_id>}}&redirect_uri={{<your_callback_url>}}
  ```

您的網域會顯示在 Amazon Cognito 主控台的 **Domain name (網域名稱)** 頁面中。您的應用程式用戶端 ID 和回呼 URL 會顯示在 **App client settings (應用程式用戶端設定)** 頁面中。