简体   繁体   English

来自 REST API 调用的错误消息未显示在 B2C 自定义策略中

[英]Error messages from REST API call is not showing in B2C custom policy

I have a self asserted technical profile in my custom policy, it have a validation technical profile which is a REST API (azure function) call.我的自定义策略中有一个自我断言的技术配置文件,它有一个验证技术配置文件,它是一个 REST API(天蓝色函数)调用。 I'm not directly calling the azure function from policy, from policy will call azure APIM and APIM will pass the request to azure function. I'm not directly calling the azure function from policy, from policy will call azure APIM and APIM will pass the request to azure function.

The problem I'm facing is when my function returns a custom error message it is not showing as expected in policy.我面临的问题是,当我的 function 返回自定义错误消息时,它未按策略中的预期显示。

return new OkObjectResult(new ResponseContentModel
      {
       userMessage = "Sorry, Please provide valid information ",
       status = 409,
       retryCounter = data.RetryCounter
     });

My technical profile is as follows:我的技术简介如下:

<TechnicalProfile Id="Registration">
          <DisplayName>Email signup</DisplayName>
          <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.SelfAssertedAttributeProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
          <Metadata>
            <Item Key="IpAddressClaimReferenceId">IpAddress</Item>
            <Item Key="ContentDefinitionReferenceId">api.localaccountsignup</Item>
            <Item Key="language.button_continue">Activate Account</Item>
            <!-- Sample: Remove sign-up email verification -->
            <Item Key="EnforceEmailVerification">False</Item>
            <Item Key="setting.retryLimit">5</Item>
          </Metadata>
          <InputClaimsTransformations>
            <!--Sample: Copy the email to ReadOnlyEamil claim type-->  
            <InputClaimsTransformation ReferenceId="CreateReadOnlyEmailAddress" />
          </InputClaimsTransformations>
          <InputClaims>
            <InputClaim ClaimTypeReferenceId="email" />
            <InputClaim ClaimTypeReferenceId="givenName" />
            <InputClaim ClaimTypeReferenceId="surname" />
          </InputClaims>
          <OutputClaims>
            <OutputClaim ClaimTypeReferenceId="objectId" DefaultValue="123" />
            <OutputClaim ClaimTypeReferenceId="newPassword" Required="true" />
            <OutputClaim ClaimTypeReferenceId="reenterPassword" Required="true" />
            <OutputClaim ClaimTypeReferenceId="tncCheckbox" Required="true" />

            <OutputClaim ClaimTypeReferenceId="retryCounter" DefaultValue="0" />
            <OutputClaim ClaimTypeReferenceId="isFound" DefaultValue="false" />
            <OutputClaim ClaimTypeReferenceId="executed-SelfAsserted-Input" DefaultValue="true" />
            <OutputClaim ClaimTypeReferenceId="authenticationSource" DefaultValue="localAccountAuthentication"/>
            <OutputClaim ClaimTypeReferenceId="newUser" DefaultValue="true" />
          </OutputClaims>
          <ValidationTechnicalProfiles>
            <ValidationTechnicalProfile ReferenceId="API-Validate-UserInfo" />
            <ValidationTechnicalProfile ReferenceId="AAD-UserWriteUsingLogonEmail" />
          </ValidationTechnicalProfiles>
          <UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
        </TechnicalProfile>

The REST API validation technical profile is as follows: REST API验证技术简介如下:

<TechnicalProfile Id="API-Validate-UserInfo">
                <DisplayName>User OTP Notifications</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://myapimurl</Item>
                  <Item Key="SendClaimsIn">Body</Item>                        
                  <Item Key="AuthenticationType">ClientCertificate</Item>
                </Metadata>
                <CryptographicKeys>
                    <Key Id="ClientCertificate" StorageReferenceId="B2C_1A_APIMClientCertificate" />
                </CryptographicKeys>
                <InputClaims>
                    <InputClaim ClaimTypeReferenceId="givenName" PartnerClaimType="GivenName" />
                    <InputClaim ClaimTypeReferenceId="surname" PartnerClaimType="SurName"/>
                    <InputClaim ClaimTypeReferenceId="email" PartnerClaimType="Email"/>
                    <InputClaim ClaimTypeReferenceId="retryCounter" PartnerClaimType="RetryCounter"/>
                </InputClaims>
                <OutputClaims>
                  <OutputClaim ClaimTypeReferenceId="retryCounter" />
                  <OutputClaim ClaimTypeReferenceId="isFound" />
                </OutputClaims>
                <UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
            </TechnicalProfile>

Error message showing in the UI is: UI 中显示的错误消息是:

The claims exchange 'API-Validate-UserInfo' specified in step '5' returned HTTP error response with Code 'BadRequest' and Reason 'Bad Request'.步骤“5”中指定的声明交换“API-Validate-UserInfo”返回 HTTP 错误响应,代码为“BadRequest”,原因为“Bad Request”。

About the function, i'm using .net core 3.1 and function runtime version is ~3关于 function,我使用的是.net 核心 3.1和 function 运行时版本是~3

Found the issue referred this article.发现这个问题提到了这篇文章。 Need to include version into the response message version, status and userMessage are mandatory fields for error response message.需要在响应消息中包含 version,status 和 userMessage 是错误响应消息的必填字段。

{
  version = "1.0.0",
  userMessage = "Sorry, Something happened unexpectedly. Please try after sometime.",
  status = 409,
 }

Following this documentation, this is the required error structure:在本文档之后,这是所需的错误结构:

Returning validation error message 返回验证错误消息

further more, make sure that the response should has http error code corresponding to the content error code:此外,请确保响应应具有与内容错误代码对应的 http 错误代码:

return StatusCode(409, new ResponseContent { userMessage = ex.Message });

where ResponseContent has the following structure:其中 ResponseContent 具有以下结构:

        public class ResponseContent : IResult
    {
        public string version { get; set; }
        public int status { get; set; }
        public string code { get; set; }
        public string userMessage { get; set; }
        public string developerMessage { get; set; }
        public string requestId { get; set; }
        public string moreInfo { get; set; }

        public ResponseContent()
        {
            version = "1.0.0";
            status = 409;
            code = "API12345";
            requestId = "50f0bd91-2ff4-4b8f-828f-00f170519ddb";
            userMessage = "Message for the user";
            developerMessage = "Verbose description of problem and how to fix it.";
            moreInfo = "https://docs.microsoft.com/en-us/azure/active-directory-b2c/restful-technical-profile#returning-validation-error-message";
        }
    }

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

相关问题 Rest API 在 Azure AD B2C 中调用自定义策略 - Rest API call in custom policy in Azure AD B2C 如何处理 B2C 自定义策略中的 REST API 错误? - How to handle REST API error in a B2C custom policy? 从我的 Web 应用程序发送数据以从 B2C 自定义策略调用 REST API 服务 - Sending data from my web application to call a REST API service from a B2C custom policy Azure B2C 自定义策略 REST API CALL 不适用于 Microsoft 帐户 - Azure B2C custom policy REST API CALL not working for Microsoft account Rest API 在自定义策略中调用 Azure AD B2C 登录 - Rest API call during Azure AD B2C SignIN in Custom Policy AAD B2C IEF:如何使用 costom 策略将错误代码和消息从 REST API 传递到应用程序? - AAD B2C IEF: How to pass error code and message from REST API to the application with costom policy? B2C:来自 REST API 的消息的本地化 - B2C: Localization for messages originating from REST API 如何从 Azure ad b2c 中的自定义策略更改 rest api 调用中的内容类型? - how to change content-type in rest api call from custom policies in Azure ad b2c? Azure B2c 安全组授权通过自定义策略使用 Rest 后调用 - Azure B2c security groups authorization through custom policy using Rest Post call AAD B2C 迁移 - ROPC 登录自定义策略与 Rest-API 集成和旧版 IDP - 是否支持? - AAD B2C Migration - ROPC Sign In Custom Policy with Rest-API Integ with Legacy IDP - Is that supported?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM