简体   繁体   English

Rest API 在 Azure AD B2C 中调用自定义策略

[英]Rest API call in custom policy in Azure AD B2C

I am new and have tried to build custom policy for sign-in by invoking a REST API call to legacy.我是新手,并尝试通过调用 REST API 调用来构建自定义登录策略。

The API expects below parameters as input: client_id=fixed value, client_secret=fixed value, grant_type=fixed value, scope=fixed value, username=variable, password=variable API 需要以下参数作为输入:client_id=固定值,client_secret=固定值,grant_type=固定值,范围=固定值,用户名=变量,密码=变量

The above parameters are not for Azure valued but some fixed values that need to be sent in the request.以上参数不是针对 Azure 值的,而是一些需要在请求中发送的固定值。

I have added few portions in the extensions custom policy but seems the request body is not forming correctly and I am getting the error The claims exchange User Migration Via Legacy specified in step '1' returned HTTP error response with Code Bad Request and Reason 'Bad Request'.我在扩展自定义策略中添加了一些部分,但似乎请求正文没有正确形成,我收到错误 The claim exchange User Migration Via Legacy specified in step '1' returned HTTP error response with Code Bad Request and Reason 'Bad要求'。 What am I doing wrong here?我在这里做错了什么? Please help.请帮忙。

Added my portion:添加了我的部分:

  <BuildingBlocks>
<ClaimsSchema>
  <ClaimType Id="RequestBody">
    <DisplayName>Request body</DisplayName>
    <DataType>string</DataType>
    <UserHelpText>RequestBody</UserHelpText>
  </ClaimType>
</ClaimsSchema>
<ClaimsTransformations>
    <ClaimsTransformation Id="GenerateRequestBody" TransformationMethod="GenerateJson">
    <InputClaims>
      <InputClaim ClaimTypeReferenceId="email" TransformationClaimType="username" />
      <InputClaim ClaimTypeReferenceId="password" TransformationClaimType="password" />
    </InputClaims>
    <InputParameters>
      <InputParameter Id="client_id" DataType="string" Value="client" />
      <InputParameter Id="client_secret" DataType="string" Value="sec" />
      <InputParameter Id="grant_type" DataType="string" Value="grant" />
      <InputParameter Id="scope" DataType="string" Value="scope" />
    </InputParameters>
    <OutputClaims>
      <OutputClaim ClaimTypeReferenceId="RequestBody" TransformationClaimType="outputClaim" />
    </OutputClaims>
  </ClaimsTransformation>
</ClaimsTransformations>
<ClaimsProviders>
  <ClaimsProvider>
  <DisplayName>REST API to communicate with Legacy IdP</DisplayName>
  <TechnicalProfiles>
    <TechnicalProfile Id="UserMigrationViaLegacyIdp">
      <DisplayName>REST API call to communicate with Legacy IdP</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://</Item>
        <Item Key="AuthenticationType">None</Item>
        <Item Key="SendClaimsIn">Body</Item>
        <Item Key="AllowInsecureAuthInProduction">true</Item>
        <Item Key="ClaimUsedForRequestPayload">RequestBody</Item>
      </Metadata>
      <InputClaimsTransformations>
        <InputClaimsTransformation ReferenceId="GenerateRequestBody" />
      </InputClaimsTransformations>
      <InputClaims>
        <InputClaim ClaimTypeReferenceId="RequestBody" />
      </InputClaims>
      <OutputClaims>
        <OutputClaim ClaimTypeReferenceId="tokenSuccess" DefaultValue="false" />
        <OutputClaim ClaimTypeReferenceId="migrationRequired" />
      </OutputClaims>
      <UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
    </TechnicalProfile>
  </TechnicalProfiles>
</ClaimsProvider>

Can you share the actual JSON created by the claim transformation?你能分享一下声明转换创建的实际 JSON 吗? Is it well formatted?格式是否正确? You can make troubleshooting easy by displaying the output of <InputClaimsTransformation ReferenceId="GenerateRequestBody" /> before you actually use it as input claim inside the REST API technical profile.在实际将其用作 REST ZDB974238714CA8DE634A7CE1D08 中的输入声明之前,您可以通过显示<InputClaimsTransformation ReferenceId="GenerateRequestBody" />的 output 来简化故障排除。 This will reveal what's going on with your JSON format.这将揭示您的 JSON 格式发生了什么。

To do that, first create a self asserted technical profile and add <InputClaimsTransformation ReferenceId="GenerateRequestBody" /> as an output claim transformation to it.为此,首先创建一个自我断言的技术配置文件并将<InputClaimsTransformation ReferenceId="GenerateRequestBody" />作为 output 声明转换添加到它。 Your output claim should be the claim which you will use later in next step in the journey.您的 output 声明应该是您稍后将在旅程的下一步中使用的声明。

In the user journey, add a step that calls the self asserted technical profile.在用户旅程中,添加一个调用自我断言技术配置文件的步骤。 Add next step with App Insights to write the output claim to App Insights( https://docs.microsoft.com/en-us/azure/active-directory-b2c/analytics-with-application-insights )使用 App Insights 添加下一步以将 output 声明写入 App Insights ( https://docs.microsoft.com/en-us/azure/active-directory-b2c/analytics-with-application-insights )

This will document claim value that REST API is receiving.这将记录 REST API 正在接收的索赔价值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM