Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Choose your framework/language

Gen1 DocsLegacy

Page updated Mar 1, 2025

Microsoft Entra ID (SAML)

Microsoft Entra IDは、Amazon Cognitoで使用するためのSAMLプロバイダーとして構成できます。Entra IDを統合することで、既存のエンタープライズユーザーでサインインし、Amplifyアプリ内で使用するためのAmplify Authリソースに一意のプロファイルを保持できます。詳細については、Microsoft Entra IDを使用したSAML認証に関するAzureドキュメントをご覧ください。

注: 以下のガイダンスは、パーソナルクラウドサンドボックスでの構成を紹介しています。サンドボックスに対する機能を確認した後、ブランチデプロイメントの構成手順を繰り返す必要があります。

パーソナルクラウドサンドボックスを開始する

開始するには、適切なリダイレクトURIを使用して認証リソースを定義します:

amplify/auth/resource.ts
import { defineAuth } from "@aws-amplify/backend"
/**
* Define and configure your auth resource
* @see https://docs.amplify.aws/gen2/build-a-backend/auth
*/
export const auth = defineAuth({
loginWith: {
email: true,
externalProviders: {
logoutUrls: ["http://localhost:3000/come-back-soon"],
callbackUrls: ["http://localhost:3000/profile"],
},
},
})

npx ampx sandboxでパーソナルクラウドサンドボックスにデプロイします。これにより、新しいEntra IDアプリを構成するために使用できるドメインが生成されます。変更を正常にデプロイした後、amplify_outputs.jsonから生成されたdomain値をコピーします

amplify_outputs.json
{
"auth": {
"aws_region": "us-east-1",
"user_pool_id": "<your-cognito-user-pool-id>",
"user_pool_client_id": "<your-cognito-user-pool-client-id>",
"identity_pool_id": "<your-cognito-identity-pool-id>",
"mfa_methods": [],
"standard_required_attributes": [
"email"
],
"username_attributes": [
"email"
],
"user_verification_types": [
"email"
],
"mfa_configuration": "OFF",
"password_policy": {
"min_length": 8,
"require_numbers": true,
"require_lowercase": true,
"require_uppercase": true,
"require_symbols": true
},
"oauth": {
"identity_providers": [],
"redirect_sign_in_uri": [
"http://localhost:3000/profile"
],
"redirect_sign_out_uri": [
"http://localhost:3000/come-back-soon"
],
"response_type": "code",
"scopes": [
"phone",
"email",
"openid",
"profile",
"aws.cognito.signin.user.admin"
],
"domain": "<some-hash>.auth.us-east-1.amazoncognito.com"
},
},
"version": "1"
}

Microsoft Entra IDのセットアップ

次に、portal.azure.comに移動して、Entra IDを選択します。デフォルトディレクトリまたは企業の既存ディレクトリで、管理の下のエンタープライズアプリケーションを選択します

Entra IDデフォルトディレクトリページでエンタープライズアプリケーションをハイライト

その後、新しいアプリケーションを選択し、独自のアプリケーションを作成を選択します。アプリケーションの名前を指定し、**ギャラリーに見つからない他のアプリケーション統合(ギャラリー以外)**を選択します

Azure Portalでの新しいエンタープライズアプリケーション作成

新しいエンタープライズアプリケーションを作成したので、SAMLでシングルサインオンを構成できます。シングルサインオンを選択します

Entra IDエンタープライズアプリケーションで「シングルサインオン」をハイライト

次にSAMLを選択します

Entra IDエンタープライズアプリケーションのシングルサインオン設定で「SAML」をハイライト

SAMLでシングルサインオンを設定するページが表示され、Amplify Authリソースからのいくつかの情報が必要になります。

Entra IDシングルサインオンセットアップページでエンティティIDとReply URLが必要

基本的なSAML構成ステップで編集を選択し、適切な値を入力します。

ラベル
Identifier (Entity ID)urn:amazon:cognito:sp:<your-cognito-user-pool-id>
Reply URL (Assertion Consumer Service URL)https://<your-cognito-domain>/saml2/idpresponse
Logout Url (Optional)https://<your-cognito-domain>/saml2/logout

注: Amazon CognitoのSAMLプロバイダーのリダイレクトURIは、以下の規約に従います:

https://<some-hash>.auth.<aws-region>.amazoncognito.com/saml2/<action>

カスタムドメインを使用している場合、ルートは同じままです: /saml2/<action>Amazon CognitoをSAML IDプロバイダーで構成する方法について詳しく学ぶ

警告: アップストリームサインアウト機能がEntra IDからのサインアウトに成功しても、ユーザーアプリへのリダイレクトに失敗するという既知の制限があります。この動作は、Amplify AuthのSAML統合ではデフォルトで無効化されています。

構成を保存し、ステップ3のSAML証明書セクションに進みます。アプリフェデレーションメタデータURLをコピーします

Entra IDシングルサインオンセットアップページでアプリフェデレーションメタデータURLをハイライト

Entra IDでバックエンドを構成する

SAMLプロバイダーをMicrosoft Entra IDで構成し、アプリフェデレーションメタデータURLをコピーしたので、認証リソースを新しいSAMLプロバイダーで構成し、URLの値をmetadataContentプロパティに貼り付けます:

amplify/auth/resource.ts
import { defineAuth } from "@aws-amplify/backend"
/**
* Define and configure your auth resource
* @see https://docs.amplify.aws/gen2/build-a-backend/auth
*/
export const auth = defineAuth({
loginWith: {
email: true,
externalProviders: {
saml: {
name: "MicrosoftEntraIDSAML",
metadata: {
metadataType: "URL",
metadataContent: "<your-metadata-content-url>",
},
attributeMapping: {
email: "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress",
},
},
logoutUrls: ["http://localhost:3000/come-back-soon"],
callbackUrls: ["http://localhost:3000/profile"],
},
},
})

ユーザー属性は、ステップ2の属性とクレームセクションにあり、デフォルトではネームスペースが付与されます。上の例は、SAMLユーザーのメールアドレスのデフォルトクレームをマッピングしていますが、追加の属性をマッピングできます。

オプション: Cognitoサイニング証明書をアップロードする

AWSコンソールで、Cognito User Poolに移動します。Amplify AuthをEntra ID SAMLプロバイダーで構成した後に作成されたIDプロバイダーMicrosoftEntraIDSAMLを選択します。署名証明書を表示を選択し、.crtとしてダウンロードします

Amazon Cognitoコンソールでサイニング証明書を表示

ファイルの拡張子を.cerに変更してAzureにアップロードします。シングルサインオンページで、ステップ3(SAML証明書)にスクロールダウンし、検証証明書(オプション)の下で編集を選択します。

Entra IDシングルサインオンページで検証証明書の「編集」をハイライト

検証証明書が必要を選択し、証明書をアップロードします。

Entra ID検証証明書アップロードペイン

変更を保存すると、Cognito User PoolからEntra IDへのリクエストが検証されるようになります。

フロントエンドを接続する

これで、ユーザーはMicrosoft Entra IDでサインインする準備が整いました。このカスタムプロバイダーでサインインするには、認証リソース定義で指定された名前(MicrosoftEntraIDSAML)としてプロバイダー名を指定します

main.ts
import { signInWithRedirect } from "aws-amplify/auth"
signInWithRedirect({
provider: { custom: "MicrosoftEntraIDSAML" }
})