LoginSignup
8
7

More than 3 years have passed since last update.

Azure AD と Salesforce を SAML 連携し IdP-Initiated のシングル サインオン構成を一から構築する。

Posted at

はじめに

Azure AD と Salesforce を SAML 連携し、シングル サインオンする構成は、下記 MS 公開情報のとおりに設定すれば構成は可能です。MS の公開情報を読んでいただければわかりますが、ギャラリーから Salesforce を選択し、シングル サインオンを構成する場合、「SP-Initiated」のシングル サインオンを構成することになります。

-参考情報
チュートリアル:Azure Active Directory と Salesforce の統合
URL:https://docs.microsoft.com/ja-jp/azure/active-directory/saas-apps/salesforce-tutorial

ご利用になられている環境次第では、 IdP-Initiated でシングル サインオンを構成したい、ということもあるかと思います。
SP-Initiated と IdP-Initiated の動作の違いは、下記 Blog を参考にしてください。

SP-Initiated と IdP-Initiated の動作の違いを Fiddler を見ながら確認してみる
URL:https://qiita.com/Shinya-Yamaguchi/items/434fab8c39e806e69a88

1点前置きさせていただくと、ギャラリーの中から Salesforce を選択し SP-Initiated でシングル サインオンを構成する場合は、ライセンス費用はかかりません。
(Azure AD Free であれば、 ギャラリー内のアプリケーションを 10 個までなら無料でシングル サインオン構成できます)

逆にギャラりー以外のアプリケーションから、シングル サインオンを構成する場合、 Azure AD Premium P1 以上のライセンスが必要になります。割り当てを行うユーザー単位でライセンスが必要になります。

また、公開情報がないので、参考にできる情報がありません。
今回、検証もかねて IdP-Initiated のシングル サインオンを構成してみましたので、以下に手順を記載します。

Azure AD 側の設定

「Azure Active Directory」→「エンタープライズ アプリケーション」→「+新しい アプリケーション」の順に選択します。

アプリケーションの追加画面より、「ギャラリー以外のアプリケーション」をクリックします。
image.png

独自のアプリケーションの追加画面より、任意の名前を入力し、「追加」をクリックします。
image.png

概要画面より、「シングル サインオン」をクリックします。
image.png

シングル サインオン方式の選択より、「SAML」をクリックします。
image.png

設定する箇所は2か所だけです。基本的な SAML 構成の右上にある鉛筆マークをクリックします。
image.png

識別子には、「https://saml.salesforce.com」と入力します。
これは、Salesforce のコミュニティサイトにも下記のとおり記載があり、「私のドメイン」を設定しない、つまり、 IdP-Initiated で構成する場合は、https://saml.salesforce.com を識別子に設定しなさいとの記載があるためです。

Identity Provider Values
URL:https://help.salesforce.com/articleView?id=sso_saml_idp_values.htm&type=5> The issuer in SAML requests generated by Salesforce, and is also the expected audience of any inbound SAML Responses. If you don’t have domains deployed, this value is always https://saml.salesforce.com. If you have domains deployed, Salesforce recommends that you use your custom domain name.

また、応答 URL は「https://ap15.lightning.force.com/」 を設定していますが、この値は、実際にご利用になられる Salesforce の URL に合わせてください。
※上記 URL は評価版の URL になります。

上記2点を設定後に、「保存」ボタンをクリックします。
image.png

次に、フェデレーション メタデータ XML をダウンロードし、任意のフォルダに保存します。
image.png

Salesforce 側の設定

Salesforce に管理者ユーザーでログインします。
image.png

「設定」→「ID」→「シングル サインオン設定」の順に選択します。
image.png

設定画面より、「編集」をクリックします。
image.png

SAML を有効化のチェック ボックスにチェックを入れて、「保存」をクリックします。
image.png

次に、SAML シングル サインオン構成の欄より、「メタデータ ファイルから新規作成」をクリックします。
image.png

メタデータ ファイルの横にある「参照」をクリックします。
image.png

Azure AD からダウンロードしたメタデータファイルを指定し、「作成」をクリックします。
image.png

設定された値のまま「保存」ボタンをクリックすると、下記画面のとおり、
「ID プロバイダのシングルログアウト URL を設定する場合、[私のドメイン] を有効にする必要があります」と表示され怒られますので、シングル サインアウトを有効にするチェックボックスのチェックを外します。
image.png

下記のとおり、チェックを外し、「保存」ボタンをクリックします。
image.png

Azure AD にユーザーを割り当てます

再度 Azure AD の画面に戻り、「ユーザーとグループ」をクリックします。
image.png

画面上部の「+ユーザーの追加」をクリックします。
image.png

割り当てるユーザーを選択し、「選択」をクリックします。
image.png

選択後に「割り当て」をクリックします。
image.png

今回はプロビジョニング機能を使わないので、 Salesforce 側にも同名のユーザーを用意しておきます。
image.png

アクセス パネルよりシングル サインオンしてみる。

URL に myapps.microsoft.com と入力し、割り当てたユーザーのアカウントを選択します。
image.png

アクセス パネルより作成した Salesforce のアイコンをクリックします。
image.png

再度アカウントを選択します。
image.png

Salesforce にシングル サインオンすることを確認します。
image.png

Fiddler を取ってみる。

参考までに SAML Request と SAML Response の中身を見てみます。

SAML Request

<samlp:AuthnRequest xmlns="urn:oasis:names:tc:SAML:2.0:metadata" ID="F84D888AA3B44C1B844375A4E8210D9E" Version="2.0" IssueInstant="2019-06-01T15:06:03.420Z" IsPassive="false" AssertionConsumerServiceURL="https://ap15.lightning.force.com/" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
  <Issuer xmlns="urn:oasis:names:tc:SAML:2.0:assertion">https://saml.salesforce.com</Issuer>
  <samlp:NameIDPolicy Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">
  </samlp:NameIDPolicy>
</samlp:AuthnRequest>

SAML Response

<samlp:Response ID="_fcbbac74-35ce-4807-9c46-f93b631f9aca" Version="2.0" IssueInstant="2019-06-01T15:59:04.488Z" Destination="https://ap15.lightning.force.com/" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
  <Issuer xmlns="urn:oasis:names:tc:SAML:2.0:assertion">https://sts.windows.net/d6a725a7-fde0-4d2a-ab70-843f0d5bf595/</Issuer>
  <samlp:Status>
    <samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" />
  </samlp:Status>
  <Assertion ID="_5284cd1f-9649-43a6-83e2-465318d21300" IssueInstant="2019-06-01T15:59:04.472Z" Version="2.0" xmlns="urn:oasis:names:tc:SAML:2.0:assertion">
    <Issuer>https://sts.windows.net/d6a725a7-fde0-4d2a-ab70-843f0d5bf595/</Issuer>
    <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
      <SignedInfo>
        <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
        <SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
        <Reference URI="#_5284cd1f-9649-43a6-83e2-465318d21300">
          <Transforms>
            <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
            <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
          </Transforms>
          <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
          <DigestValue>SpSNDlnga5PCe4Xz6tPfaMd/CNKjmKRtWQQso3tgoJE=</DigestValue>
        </Reference>
      </SignedInfo>
      <SignatureValue>YEVxB3zUwGwbaN7LtdXqGGxQsmAmLWjSvfImcc7aMFh9VhTcT4FMeCm/eTsEkNIELUifw9deamtXuouzFQUzqy0QK8AcAyFunVTEOHMrSUnZViSH4rLExVKF1mKX7f+22nOuW/JZotayDvnoYyo+/QGtg8F0CGt6INhhXTE6E9nGUMtm7iR+H8hYcQySOY7suXtv3m4jb8YGOjS9UORSEXjMD+Jmiagq+h6urj7kRsAmUKeUAgHFRO3UtAQ+654uP7zaLa3nq/atoEOSNttIo29yJpFufZvKIAcxQGVkCPYOJ3SkkuKO7zSfqAbfC9wOkvi1d8ydX4+eldg5JzsfHg==</SignatureValue>
      <KeyInfo>
        <X509Data>
          <X509Certificate>MIIC8DCCAdigAwIBAgIQZgqE6bQGzKlOazHsq94lwjANBgkqhkiG9w0BAQsFADA0MTIwMAYDVQQDEylNaWNyb3NvZnQgQXp1cmUgRmVkZXJhdGVkIFNTTyBDZXJ0aWZpY2F0ZTAeFw0xOTA2MDExNTE3NTBaFw0yMjA2MDExNTE3NTBaMDQxMjAwBgNVBAMTKU1pY3Jvc29mdCBBenVyZSBGZWRlcmF0ZWQgU1NPIENlcnRpZmljYXRlMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx6FW6s7A7Qe9W/ogyQ6asDJ7UFnYxDz/mIgmPwoULTo0aEyyn65odAMBb3C4WXEr1iycmIqVjI/KwhGZZcKTOSVTVUKC6xEF+JH+2wAhR3lsxCR0u4A1VSJ0Z7qUSLocY8L5lgIyqxecnt/ZyVIxFaJB8vAUU7G2eh8zcuWrw2LT5PaVj94o7hnxIgAXDl1kAY21wGE8LDOpy9jXyos6Nwn/2Gle2gAC6GkKmi9vQhkjDXF/+wUM/g3fZ0lpGS358l+96fYyrHoK12+KWxeVtKcQ7+zlXBAGr6n8U7IdzynFav+/EHwc3dPUXuF7dVLJSZSwddJA2w4oYzhjJ1WJpwIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQBkRqVu2IlD+6R9fiRK9vLEbtHV12aAoTuhIGSlnZ/A3+saVOoXQYBLWGKC8AGwdn9gd/5woIVWQS9+I7Ye2+/DNcHPbuTMzn+raSIYOtdjMelMRNxQKwL47SGaU9z8FgoNd2c0cHtsKUgiw4/jFUe54DFLMY2squRWjcmY6CrwlHhGdcbU0F+E7qtgoRqyCFMrA0CxnS2Pm0RQKJRRNukFaEKpluxkRsiiYXA3+p7lUPRxlKcDbFhZoZJJEk9DsZFK2sv+zIwac8CJxGgqTja3wawxwF6E048PeGd9F+VD7Tioi3CIZBNBoTFZryJm6Dv2Km8usDHWq9+4mWymk1Po</X509Certificate>
        </X509Data>
      </KeyInfo>
    </Signature>
    <Subject>
      <NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">test005@shyamag014.onmicrosoft.com</NameID>
      <SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
        <SubjectConfirmationData NotOnOrAfter="2019-06-01T16:04:04.472Z" Recipient="https://ap15.lightning.force.com/" />
      </SubjectConfirmation>
    </Subject>
    <Conditions NotBefore="2019-06-01T15:54:04.472Z" NotOnOrAfter="2019-06-01T16:54:04.472Z">
      <AudienceRestriction>
        <Audience>https://saml.salesforce.com</Audience>
      </AudienceRestriction>
    </Conditions>
    <AttributeStatement>
      <Attribute Name="http://schemas.microsoft.com/identity/claims/tenantid">
        <AttributeValue>d6a725a7-fde0-4d2a-ab70-843f0d5bf595</AttributeValue>
      </Attribute>
      <Attribute Name="http://schemas.microsoft.com/identity/claims/objectidentifier">
        <AttributeValue>3f997549-2ae6-4072-bd86-2bd19b86a2a2</AttributeValue>
      </Attribute>
      <Attribute Name="http://schemas.microsoft.com/identity/claims/displayname">
        <AttributeValue>test005@shyamag014.onmicrosoft.com</AttributeValue>
      </Attribute>
      <Attribute Name="http://schemas.microsoft.com/identity/claims/identityprovider">
        <AttributeValue>https://sts.windows.net/d6a725a7-fde0-4d2a-ab70-843f0d5bf595/</AttributeValue>
      </Attribute>
      <Attribute Name="http://schemas.microsoft.com/claims/authnmethodsreferences">
        <AttributeValue>http://schemas.microsoft.com/ws/2008/06/identity/authenticationmethod/password</AttributeValue>
      </Attribute>
      <Attribute Name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress">
        <AttributeValue>test005@shyamag014.onmicrosoft.com</AttributeValue>
      </Attribute>
      <Attribute Name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name">
        <AttributeValue>test005@shyamag014.onmicrosoft.com</AttributeValue>
      </Attribute>
    </AttributeStatement>
    <AuthnStatement AuthnInstant="2019-06-01T15:57:20.844Z" SessionIndex="_5284cd1f-9649-43a6-83e2-465318d21300">
      <AuthnContext>
        <AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</AuthnContextClassRef>
      </AuthnContext>
    </AuthnStatement>
  </Assertion>
</samlp:Response>

おわりに

シンプルに構成されているように見えますが、動作検証には実は結構時間がかかりました…。
ですので、本 Blog が少しでも参考になれば幸いです。

8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7