You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Azure B2C自定义策略的SignUporSignIn流程完成邮箱验证后调用REST API?

在Azure B2C SignUporSignIn流程完成邮箱验证后调用REST API

核心逻辑

在用户完成邮箱验证码验证的节点后,通过自定义策略中的RESTful技术配置文件插入API调用步骤,确保流程顺序是「邮箱验证通过→调用REST API→继续后续登录/注册流程」。

具体实现步骤

1. 配置REST API技术配置文件

在自定义策略的<ClaimsProviders>节点下新增一个ClaimsProvider,用来定义API的连接规则、参数传递逻辑:

<ClaimsProvider>
  <DisplayName>Post-Email-Verification API</DisplayName>
  <TechnicalProfiles>
    <TechnicalProfile Id="REST-CallAfterEmailVerify">
      <DisplayName>Call external API after email validation</DisplayName>
      <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.RestfulProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      <Metadata>
        <!-- 替换为你的实际API地址 -->
        <Item Key="ServiceUrl">https://your-api-domain.com/notify-user</Item>
        <!-- 请求方式,按需改为GET/PUT等 -->
        <Item Key="HttpMethod">POST</Item>
        <Item Key="AuthenticationType">None</Item>
        <!-- 声明放在请求体中传递 -->
        <Item Key="SendClaimsIn">Body</Item>
      </Metadata>
      <InputClaims>
        <!-- 传递给API的用户信息,按需添加 -->
        <InputClaim ClaimTypeReferenceId="email" />
        <InputClaim ClaimTypeReferenceId="objectId" />
        <InputClaim ClaimTypeReferenceId="givenName" />
      </InputClaims>
      <OutputClaims>
        <!-- 若API返回需要存储的字段,在此定义 -->
        <OutputClaim ClaimTypeReferenceId="apiProcessStatus" />
      </OutputClaims>
      <!-- 无需会话管理,使用空实现 -->
      <UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
    </TechnicalProfile>
  </TechnicalProfiles>
</ClaimsProvider>
  • 如果API需要身份验证,可将AuthenticationType改为Basic或ClientCertificate,并添加对应元数据(如BasicAuthUsername/BasicAuthPassword)。

2. 调整用户旅程顺序

找到SignUporSignIn用户旅程的<OrchestrationSteps>节点,在邮箱验证步骤之后插入新的编排步骤:

<!-- 假设邮箱验证步骤的Order为3,这里设为4确保执行顺序 -->
<OrchestrationStep Order="4" Type="ClaimsExchange">
  <ClaimsExchanges>
    <ClaimsExchange Id="InvokePostVerifyAPI" TechnicalProfileReferenceId="REST-CallAfterEmailVerify" />
  </ClaimsExchanges>
</OrchestrationStep>
  • 邮箱验证步骤通常是类型为ClaimsExchange、技术配置文件关联邮箱验证(如LocalAccountSignUpWithLogonEmail)的步骤,确认其Order值后,将API调用步骤的Order设为该值+1。

3. 错误处理配置(可选)

为避免API调用失败导致流程中断,可在技术配置文件中添加重试、错误跳转规则:

<Metadata>
  <!-- 其他元数据 -->
  <Item Key="NumberOfRetries">2</Item>
  <Item Key="RetryIntervalSeconds">3</Item>
  <!-- API调用失败时跳转的错误页面技术配置文件 -->
  <Item Key="RaiseErrorIfClaimsPrincipalDoesNotExist">true</Item>
</Metadata>

4. 测试验证

将修改后的自定义策略上传至Azure B2C租户,发起SignUporSignIn流程:

  1. 完成邮箱注册/登录并输入验证码验证通过;
  2. 检查API服务端是否接收到请求;
  3. 确认策略流程是否正常完成(或按错误配置跳转)。

内容的提问来源于stack exchange,提问作者Gowtham k

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 22:46:13