Azure active directory B2C自定义注册-使用外部API调试声明交换

Azure active directory B2C自定义注册-使用外部API调试声明交换,azure-active-directory,azure-ad-b2c,Azure Active Directory,Azure Ad B2c,我遵循这个教程 我对它进行了定制,因为我在这里的目标是防止任何人使用已经存在的显示名注册 但是,我总是遇到错误“在步骤“2”中指定的声明交换“REST API注册”返回了无法解析的HTTP错误响应。” 我已经使用这个模型用postman测试了端点,它返回的结果与预期的一样 public class InputClaimsModel { public string email { get; set; } public string firstName { get; set; }

我遵循这个教程

我对它进行了定制,因为我在这里的目标是防止任何人使用已经存在的显示名注册

但是,我总是遇到错误“在步骤“2”中指定的声明交换“REST API注册”返回了无法解析的HTTP错误响应。”

我已经使用这个模型用postman测试了端点,它返回的结果与预期的一样

public class InputClaimsModel
{
    public string email { get; set; }
    public string firstName { get; set; }
    public string lastName { get; set; }
    public string displayName { get; set; }

}

public class OutputClaimsModel
{
    public string uniqueName { get; set; }
}
如果我可以调试该消息,我可能会发现更多,但不确定如何才能做到这一点

信任框架扩展的摘录如下

<BasePolicy>
   <TenantId>null.onmicrosoft.com</TenantId>
  <PolicyId>B2C_1A_TrustFrameworkBase</PolicyId>
</BasePolicy>
<BuildingBlocks>
<ClaimsSchema>
  <ClaimType Id="uniqueName">
    <DisplayName>uniqueName</DisplayName>
    <DataType>string</DataType>
    <UserHelpText>Customer unique name</UserHelpText>
  </ClaimType>
</ClaimsSchema>
</BuildingBlocks>
<ClaimsProviders>
<ClaimsProvider>
  <DisplayName>REST APIs</DisplayName>
  <TechnicalProfiles>
    <!-- Custom Restful service -->
    <TechnicalProfile Id="REST-API-SignUp">
      <DisplayName>Validate user's input data and return unique name claim</DisplayName>
      <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.RestfulProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      <Metadata>
        <Item Key="ServiceUrl">https://null.azurewebsites.NET/api/AzureB2C/validate</Item>
        <Item Key="SendClaimsIn">Body</Item>
        <!-- Set AuthenticationType to Basic or ClientCertificate in production environments -->
        <Item Key="AuthenticationType">Basic</Item>
      </Metadata>
      <CryptographicKeys>
        <Key Id="BasicAuthenticationUsername" StorageReferenceId="B2C_1A_B2cRestClientId" />
        <Key Id="BasicAuthenticationPassword" StorageReferenceId="B2C_1A_B2cRestClientSecret" />
      </CryptographicKeys>
      <InputClaims>
        <InputClaim ClaimTypeReferenceId="email" />
        <InputClaim ClaimTypeReferenceId="givenName" PartnerClaimType="firstName" />
        <InputClaim ClaimTypeReferenceId="surname" PartnerClaimType="lastName" />
      </InputClaims>
      <OutputClaims>
        <OutputClaim ClaimTypeReferenceId="uniqueName" PartnerClaimType="uniqueName" />
      </OutputClaims>
      <UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
    </TechnicalProfile>
    <!-- Change LocalAccountSignUpWithLogonEmail technical profile to support your validation technical profile -->
    <TechnicalProfile Id="LocalAccountSignUpWithLogonEmail">
      <OutputClaims>
        <OutputClaim ClaimTypeReferenceId="uniqueName" PartnerClaimType="uniqueName" />
      </OutputClaims>
      <ValidationTechnicalProfiles>
        <ValidationTechnicalProfile ReferenceId="REST-API-SignUp" />
      </ValidationTechnicalProfiles>
    </TechnicalProfile>
  </TechnicalProfiles>
</ClaimsProvider>

应按如下方式返回成功的响应:

返回Ok(outputClaimsModel);
返回:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "uniqueName": "Chris Padgett"
}
这只是一个失败的响应,应该使用
b2responsecontent
模型返回


为了排除意外响应的故障,您必须。

如何从Web API返回数据?使用这个.Request.CreateResponse(HttpStatusCode.OK,OutputClaimsModel);然后看看它是如何工作的。我复制了一个类似的示例,我编辑了上面的内容并将其添加到示例中,但正如前面提到的,我看不出如何读取它-postman只是告诉我返回了一个预期类型的对象。您是否放置了Request.CreateResponse(HttpStatusCode.OK,OutputClaimsModel)?我正在使用的ASP.NET版本似乎不支持这一点,我想我基本上会咬紧牙关,将API移植到最新版本的.NET,我必须这样做才能实现API级别的安全性,而不是让应用程序服务去做它的工作。。。!不管怎样,成功是一件好事。完全是我的错,是API中的错误响应类型。不过,我仍然需要弄清楚如何让它处理失败场景
public class B2CResponseContent
{
    public string version { get; set; }
    public int status { get; set; }
    public string userMessage { get; set; }

    public B2CResponseContent(string message, HttpStatusCode status)
    {
        this.userMessage = message;
        this.status = (int)status;
        this.version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
    }
}
HTTP/1.1 200 OK
Content-Type: application/json

{
  "uniqueName": "Chris Padgett"
}