У меня есть самопровозглашенный технический профиль в моей настраиваемой политике, у него есть технический профиль проверки, который является вызовом REST API (функция Azure). Я не вызываю функцию azure напрямую из политики, из политики вызовет azure APIM, а APIM передаст запрос в функцию azure.
Проблема, с которой я сталкиваюсь, заключается в том, что моя функция возвращает настраиваемое сообщение об ошибке, которое не отображается так, как ожидалось в политике.
return new OkObjectResult(new ResponseContentModel
{
userMessage = "Sorry, Please provide valid information ",
status = 409,
retryCounter = data.RetryCounter
});
Мой технический профиль следующий:
<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>
Технический профиль валидации 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>
В пользовательском интерфейсе отображается сообщение об ошибке:
Обмен утверждений API-Validate-UserInfo, указанный на шаге 5, вернул HTTP-ответ об ошибке с кодом BadRequest и причиной «Плохой запрос».
Что касается функции, я использую .net core 3.1, а версия выполнения функции - ~ 3.