Azure Active Directory B2C でカスタム ポリシーを使用してパスワードの変更を設定する

開始する前に[ポリシーの種類の選択] セレクターを使用して、設定するポリシーの種類を選択します。 Azure Active Directory B2C には、ユーザーがアプリケーションを操作する方法を定義する 2 つの方法 (定義済みのユーザー フローを使用する、または完全に構成可能なカスタム ポリシーを使用する) があります。 この記事で必要な手順は、方法ごとに異なります。

Azure Active Directory B2C (Azure AD B2C) を構成して、ローカル アカウントでサインインしているユーザーが、本人証明のためのメール確認を使用せずにパスワードを変更できるようにすることができます。

パスワード変更フローでは、次の手順を行います。

  1. ユーザーはローカル アカウントにサインインします。 セッションがまだアクティブである場合、Azure AD B2C によってユーザーが認可され、次の手順にスキップします。

  2. [古いパスワード] では、ユーザーは古いパスワードを確認します。 [新しいパスワード] では、新しいパスワードを作成して確認します。

    Screenshot that shows two numbered dialogs for making a password change.

ヒント

ユーザーは、自分のパスワードを知っていて、パスワードを変更したい場合にのみ、この記事で説明されているパスワード変更フローを使用できます。 ユーザーがパスワードを忘れた場合に備えて、セルフサービス パスワード リセットを有効にしておくことをお勧めします。

この機能は、カスタム ポリシーでのみ使用できます。 セットアップ手順は、前のセレクターで [カスタム ポリシー] を選択します。

前提条件

要素を追加する

  1. TrustFrameworkExtensions.xml ファイルを開きます。 次の ClaimType 要素を、ClaimsSchema 要素に追加します。識別子は oldPassword にします。

    <BuildingBlocks>
      <ClaimsSchema>
        <ClaimType Id="oldPassword">
          <DisplayName>Old Password</DisplayName>
          <DataType>string</DataType>
          <UserHelpText>Enter your old password</UserHelpText>
          <UserInputType>Password</UserInputType>
        </ClaimType>
      </ClaimsSchema>
    </BuildingBlocks>
    
  2. ClaimsProvider 要素には、ユーザーを認証する技術プロファイルが含まれています。 ClaimsProviders 要素に次の要素プロバイダーを追加します。

    <ClaimsProviders>
      <ClaimsProvider>
        <DisplayName>Local Account SignIn</DisplayName>
        <TechnicalProfiles>
          <TechnicalProfile Id="login-NonInteractive-PasswordChange">
            <DisplayName>Local Account SignIn</DisplayName>
            <InputClaims>
              <InputClaim ClaimTypeReferenceId="oldPassword" PartnerClaimType="password" Required="true" />
              </InputClaims>
            <IncludeTechnicalProfile ReferenceId="login-NonInteractive" />
          </TechnicalProfile>
        </TechnicalProfiles>
      </ClaimsProvider>
      <ClaimsProvider>
        <DisplayName>Local Account Password Change</DisplayName>
        <TechnicalProfiles>
          <TechnicalProfile Id="LocalAccountWritePasswordChangeUsingObjectId">
            <DisplayName>Change password (username)</DisplayName>
            <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.SelfAssertedAttributeProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
            <Metadata>
              <Item Key="ContentDefinitionReferenceId">api.selfasserted</Item>
            </Metadata>
            <InputClaims>
              <InputClaim ClaimTypeReferenceId="objectId" />
            </InputClaims>
            <OutputClaims>
              <OutputClaim ClaimTypeReferenceId="oldPassword" Required="true" />
              <OutputClaim ClaimTypeReferenceId="newPassword" Required="true" />
              <OutputClaim ClaimTypeReferenceId="reenterPassword" Required="true" />
            </OutputClaims>
            <ValidationTechnicalProfiles>
              <ValidationTechnicalProfile ReferenceId="login-NonInteractive-PasswordChange" />
              <ValidationTechnicalProfile ReferenceId="AAD-UserWritePasswordUsingObjectId" />
            </ValidationTechnicalProfiles>
          </TechnicalProfile>
        </TechnicalProfiles>
      </ClaimsProvider>
    </ClaimsProviders>
    
  3. UserJourneys 要素は、ユーザーがアプリケーションとやり取りするときにたどるパスを定義します。 UserJourneys 要素が存在しない場合は追加します。UserJourney 識別子は PasswordChange にします。

    <UserJourneys>
      <UserJourney Id="PasswordChange">
        <OrchestrationSteps>
          <OrchestrationStep Order="1" Type="ClaimsProviderSelection" ContentDefinitionReferenceId="api.signuporsignin">
            <ClaimsProviderSelections>
              <ClaimsProviderSelection TargetClaimsExchangeId="LocalAccountSigninEmailExchange" />
            </ClaimsProviderSelections>
          </OrchestrationStep>
          <OrchestrationStep Order="2" Type="ClaimsExchange">
            <ClaimsExchanges>
              <ClaimsExchange Id="LocalAccountSigninEmailExchange" TechnicalProfileReferenceId="SelfAsserted-LocalAccountSignin-Email" />
            </ClaimsExchanges>
          </OrchestrationStep>
          <OrchestrationStep Order="3" Type="ClaimsExchange">
            <ClaimsExchanges>
              <ClaimsExchange Id="NewCredentials" TechnicalProfileReferenceId="LocalAccountWritePasswordChangeUsingObjectId" />
            </ClaimsExchanges>
          </OrchestrationStep>
          <OrchestrationStep Order="4" Type="ClaimsExchange">
            <ClaimsExchanges>
              <ClaimsExchange Id="AADUserReadWithObjectId" TechnicalProfileReferenceId="AAD-UserReadUsingObjectId" />
            </ClaimsExchanges>
          </OrchestrationStep>
          <OrchestrationStep Order="5" Type="SendClaims" CpimIssuerTechnicalProfileReferenceId="JwtIssuer" />
        </OrchestrationSteps>
        <ClientDefinition ReferenceId="DefaultWeb" />
      </UserJourney>
    </UserJourneys>
    
  4. TrustFrameworkExtensions.xml ポリシー ファイルを保存します。

  5. スターター パックと一緒にダウンロードした ProfileEdit.xml ファイルをコピーして、ProfileEditPasswordChange.xml という名前を付けます。

  6. 新しいファイルを開き、PolicyId 属性を一意の値で更新します。 この値がポリシーの名前になります。 たとえば、B2C_1A_profile_edit_password_change です。

  7. DefaultUserJourneyReferenceId 属性を変更して、作成した新しいユーザー体験の ID と一致するようにします。 たとえば、PasswordChange です。

  8. 変更を保存します。

ポリシーをアップロードしてテストします。

  1. Azure portal にサインインします。
  2. 複数のテナントにアクセスできる場合、上部のメニューの [設定] アイコンを選択し、[ディレクトリとサブスクリプション] メニューからお使いの Azure AD B2C テナントに切り替えます。
  3. Azure portal の左上隅にある [すべてのサービス] を選択してから、 [Azure AD B2C] を検索して選択します。
  4. [Identity Experience Framework] を選択します。
  5. [カスタム ポリシー] で、 [ポリシーのアップロード] 選択します。
  6. [ポリシーが存在する場合は上書きする] を選択し、TrustFrameworkExtensions.xml ファイルを検索して選択します。
  7. [アップロード] を選択します。
  8. その証明書利用者ファイル (ProfileEditPasswordChange.xml など) で、手順 5 から 7 を繰り返します。

ポリシーを実行する

  1. 変更したポリシーを開きます。 たとえば、B2C_1A_profile_edit_password_change です。
  2. [アプリケーション] で、前に登録したアプリケーションを選択します。 トークンを表示するには、 [応答 URL]https://jwt.ms が表示される必要があります。
  3. [今すぐ実行] を選択します。 開いた新しいタブで、URL から "&&prompt=login" を削除し、タブを更新します。次に、前に作成したアカウントを使用してサインインします。 パスワード変更ダイアログには、パスワードを変更するオプションが表示されます。

次のステップ