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

> Auth0 で Amazon Web Services（AWS）のシングルサインオン（SSO）を設定する方法を学びます。

# Amazon Web Services でシングルサインオンを設定する

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>;
};

Auth0 を AWS と連携すると、サポート対象の任意の <Tooltip tip="アイデンティティプロバイダー（IdP）: デジタルアイデンティティを保存および管理するサービス。" cta="用語集を表示" href="/docs/ja-jp/glossary?term=identity+provider">アイデンティティプロバイダー</Tooltip>を使用して、ユーザーが AWS にログインできるようになります。

AWS で <Tooltip tip="シングルサインオン（SSO）: ユーザーが 1 つのアプリケーションにログインすると、そのユーザーは自動的に他のアプリケーションにもログインされるサービス。" cta="用語集を表示" href="/docs/ja-jp/glossary?term=SSO">SSO</Tooltip> を設定するには、次の手順を完了する必要があります。

1. AWS で外部アイデンティティプロバイダーを作成します。
2. Auth0 アプリケーションの SAML2 Web App アドオンを設定します。
3. AWS のアイデンティティプロバイダー設定を完了します。
4. AWS IAM ロールを作成します。
5. AWS ロールをユーザーに対応付けます。

<div id="create-an-external-identity-provider-in-aws">
  ## AWS で外部アイデンティティプロバイダーを作成する
</div>

1. 1 つ変更を加えたうえで、AWS のガイド [Connect to your External Identity Provider](https://docs.aws.amazon.com/singlesignon/latest/userguide/manage-your-identity-source-idp.html) に従って、AWS で外部アイデンティティプロバイダーを設定します。

   1. AWS のメタデータファイルをダウンロードする代わりに、**Show Individual Metadata Values** をクリックします。
   2. **AWS SSO 発行者 URL** と **AWS SSO ACS URL** の値をコピーします。これらは次のセクションで使用します。
2. 後のセクションで設定を完了する必要があるため、このページはブラウザーで開いたままにしておいてください。

<div id="configure-saml-sso-for-auth0">
  ## Auth0 の SAML SSO を設定する
</div>

<Tooltip tip="Auth0 Dashboard: サービスを設定するための Auth0 の主要な製品です。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=Auth0+Dashboard">Auth0 Dashboard</Tooltip> を使用して、アプリケーションの SAML2 Web App アドオンを設定します。設定方法については、[Amazon Web Services 向けに Auth0 を IDプロバイダーとして設定する](/docs/ja-jp/authenticate/single-sign-on/outbound-single-sign-on/configure-auth0-saml-identity-provider/configure-saml2-web-app-addon-for-aws) を参照してください。

<div id="complete-aws-identity-provider-configuration">
  ## AWSアイデンティティプロバイダーの設定を完了する
</div>

1. ブラウザーで開いている AWS SSO のアイデンティティプロバイダーページに戻ります。
2. 前のセクションでダウンロードして保存したメタデータファイルをアップロードします。
3. 内容を確認し、アイデンティティソースの変更を**確認**します。

<div id="create-aws-iam-role">
  ## AWS IAMロールを作成
</div>

プロバイダーを使用するには、そのプロバイダーをロールの信頼ポリシーに含めた IAM ロールを作成する必要があります。

1. サイドバーの **Access Management** から [**Roles**](https://console.aws.amazon.com/iam/home#/roles) に移動し、**Create Role** をクリックします。
2. 次のページで、信頼するエンティティの種類を選択するよう求められます。**SAML 2.0 Federation** を選択します。
3. 画面の指示が表示されたら、先ほど作成したプロバイダーを **SAML provider** として設定します。**Allow programmatic and AWS Management Console access** を選択し、**Next** をクリックして続行します。
4. **Attach Permission Policies** ページで、ロールにアタッチする適切なポリシーを選択します。これらのポリシーによって、このロールを付与されたユーザーが AWS で持つ権限が決まります。たとえば、ユーザーに IAM への読み取り専用アクセスを付与するには、`IAMReadOnlyAccess` ポリシーを絞り込んで選択します。完了したら、**Next Step** をクリックします。
5. 3 つ目の **Create Role** 画面は **Add Tags** です。多数のロールを作成する予定がある場合は、タグを使って作成したロールを整理できます。
6. **Review** ページで **Role Name** を設定し、設定内容を確認します。次のパラメーターに値を入力します。

   | Field                | Description   |
   | -------------------- | ------------- |
   | **Role name**        | ロールのわかりやすい名前。 |
   | **Role description** | ロールの用途の説明。    |
7. **Trusted entities** と **Policies** の情報を確認し、**Create Role** をクリックします。

<div id="map-aws-role-to-a-user">
  ## AWS ロールをユーザーにマッピングする
</div>

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  高度なユースケースでロールを割り当てるサーバー側のルールを定義する例については、[Amazon API Gateway チュートリアル](/docs/ja-jp/customize/integrations/aws/aws-api-gateway-delegation/aws-api-gateway-delegation-5)を参照してください。
</Callout>

指定した**AWS ロール**は、AWS マネジメントコンソールを含むリソースに対して許可されるアクセスの種類を適用する**IAM ポリシー**に関連付けられます。ロールとポリシーの詳細については、[Creating IAM Roles](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create.html)を参照してください。

1. AWS ロールをユーザーにマッピングするには、[ルール](/docs/ja-jp/customize/rules)を作成します。

   ```javascript lines theme={null}
   function (user, context, callback) {

     user.awsRole = 'arn:aws:iam::951887872838:role/TestSAML,arn:aws:iam::951887872838:saml-provider/MyAuth0';
     user.awsRoleSession = user.name;

     context.samlConfiguration.mappings = {
       'https://aws.amazon.com/SAML/Attributes/Role': 'awsRole',
       'https://aws.amazon.com/SAML/Attributes/RoleSessionName': 'awsRoleSession'
     };

     callback(null, user, context);

   }
   ```

   上のコードスニペットでは、`user.awsRole` は AWS ロールと IdP を識別します。AWS ロールの識別子はカンマの前にあり、IdP の識別子はカンマの後にあります。

   1. ルールでは、これら 2 つの値を複数の方法で取得できます。たとえば、IAM Console の左側のサイドバーで、前の手順で AWS に作成した項目を選択すると取得できます。作成した IDプロバイダーとロールは、どちらも Console で選択するとコピー可能な ARN を利用できます。
   2. 上の例では、これら 2 つの値はいずれもルール内にハードコードされています。あるいは、これらの値をユーザープロファイルに保存したり、他の属性を使って導き出したりすることもできます。たとえば、Active Directory を使用している場合は、`group` などのユーザーに関連付けられたプロパティを適切な AWS ロールにマッピングできます。

      ```text lines theme={null}
      var awsRoles = {
        'DomainUser': 'arn:aws:iam::951887872838:role/TestSAML,arn:aws:iam::95123456838:saml-provider/MyAuth0',
        'DomainAdmins': 'arn:aws:iam::957483571234:role/SysAdmins,arn:aws:iam::95123456838:saml-provider/MyAuth0'
      };
      user.awsRole = awsRoles[user.group];
      user.awsRoleSession = user.email;

      context.samlConfiguration.mappings = {
        'https://aws.amazon.com/SAML/Attributes/Role': 'awsRole',
        'https://aws.amazon.com/SAML/Attributes/RoleSessionName': 'awsRoleSession',
      };
      ```

<div id="map-multiple-roles">
  ### 複数のロールをマッピングする
</div>

ロールのマッピングには配列を指定することもできます (つまり、`awsRoles: role1` ではなく `awsRoles = [ role1, role2 ]` になります)

たとえば、次のような構造の Active Directory グループがあるとします。

```javascript lines theme={null}
var user = {
  app_metadata: {
    ad_groups: {
      "admins": "some info not aws related",
      "aws_dev_Admin": "arn:aws:iam::123456789111:role/Admin,arn:aws:iam::123456789111:saml-provider / Auth0",
      "aws_prod_ReadOnly": "arn:aws:iam::123456789999:role/ReadOnly,arn:aws:iam::123456789999:saml-provider / Auth0"
    }
  }
};
```

この場合、ルールは次のようになります。

```javascript lines theme={null}
function (user, context, callback) {

  var userGroups = user.app_metadata.ad_groups;

  function awsFilter(group) {
    return group.startsWith('aws_');
  }

  function mapGroupToRole(awsGroup) {
    return userGroups[awsGroup];
  }

  user.awsRole = Object.keys(userGroups).filter(awsFilter).map(mapGroupToRole);
  user.awsRoleSession = 'myawsuser'; // ユーザーごとに一意 http://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html

  context.samlConfiguration.mappings = {
    'https://aws.amazon.com/SAML/Attributes/Role': 'awsRole',
    'https://aws.amazon.com/SAML/Attributes/RoleSessionName': 'awsRoleSession'
  };

  callback(null, user, context);

}
```

<div id="configure-session-expiration">
  ## セッションの有効期限を設定する
</div>

AWS セッションの有効期限 (3600 秒) を延長するには、カスタムの[ルール](/docs/ja-jp/customize/rules)を使用します。このルールでは、セッション時間を変更する [**SessionDuration** 属性](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_saml_assertions.html) を設定します。

export const codeExample = `function (user, context, callback) {
    if(context.clientID !== '{yourClientId}'){
      return callback(null, user, context);
    }

  user.awsRole = '{yourArn}';
  user.awsRoleSession = '{yourRoleSession}';
  user.time = 1000; // 有効期限が切れるまでの時間（秒）

  context.samlConfiguration.mappings = {
    'https://aws.amazon.com/SAML/Attributes/Role': '{yourAwsRoleName}',
    'https://aws.amazon.com/SAML/Attributes/RoleSessionName': '{yourAwsRoleSessionName}',
    'https://aws.amazon.com/SAML/Attributes/SessionDuration': 'time'   };

  callback(null, user, context);
}`;

<AuthCodeBlock children={codeExample} language="javascript" />

<div id="test-configuration">
  ## 設定をテストする
</div>

1. [Auth0 Dashboard > アプリケーション > アプリケーション](https://manage.auth0.com/#/applications) に移動し、対象のアプリケーション名をクリックします。
2. **Addons** タブで、**SAML2 Web App** アドオン を選択します。
3. **Usage** タブで、**IDプロバイダーのログイン URL** を探します。Auth0 アカウントのログインページにリダイレクトされます。正常にログインできると、AWS にリダイレクトされます。

<div id="learn-more">
  ## 詳細はこちら
</div>

* [Amazon Web Services を SAMLサービスプロバイダーとして設定する](/docs/ja-jp/authenticate/single-sign-on/outbound-single-sign-on/configure-auth0-saml-identity-provider/configure-saml2-web-app-addon-for-aws)
