Home > Net >  how to change content-type in rest api call from custom policies in Azure ad b2c?
how to change content-type in rest api call from custom policies in Azure ad b2c?

Time:05-21

I am trying to call a SMS provider through custom policies . the API provided by SMS provider accepts a JSON payload in the format mentioned below JSON Payload format I am trying to call this API by passing the JOSN payload, however when I run this policy the content type in the request header is application/x-www-form-urlencoded but the API only accepts application/json. Below is the code of the restful technical profile

<TechnicalProfile Id="SendOtp">
          <DisplayName>Use SMS api to send the code the the user</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://japi.instaalerts.zone/httpapi/JsonReceiver</Item>
            <Item Key="AuthenticationType">None</Item>
            <Item Key="SendClaimsIn">Body</Item>
            <Item Key="ClaimUsedForRequestPayload">RequestBody</Item>
            <!-- <Item Key="DefaultUserMessageIfRequestFailed">Default</Item>
            <Item Key="UserMessageIfCircuitOpen">Not Reachable</Item>
            <Item Key="UserMessageIfDnsResolutionFailed">DNS Failed</Item>
            <Item Key="UserMessageIfRequestTimeout">Timeout</Item> -->
          </Metadata>
          <InputClaimsTransformations>
            <InputClaimsTransformation ReferenceId="FormatOTPmsg" />
            <!-- <InputClaimsTransformation ReferenceId="createDestArray" /> -->
            <InputClaimsTransformation ReferenceId="RequestBody" />
          </InputClaimsTransformations>
           <InputClaims>
            <InputClaim ClaimTypeReferenceId="RequestBody"/>
          </InputClaims>
        </TechnicalProfile>

Question is how to change the content type of the request ?

CodePudding user response:

You cannot control the content type header, it should respect the method used to send the payload. This might be a bug, raise a MS support ticket.

CodePudding user response:

I don't believe there is a way to change values of headers using RestfulProvider Technical profile in B2C Custom policy. The only custom header we can add is for authentication which can be found here B2C Restful Cryptographic keys. It's obviously not applicable here.

I tried calling some test apis which logs headers and B2C is always sending content-type as 'application/json; charset=utf-8' while using the Meta data

<Item Key="SendClaimsIn">Body</Item>

However using Form instead of body produces the header 'content-type': 'application/x-www-form-urlencoded'

<Item Key="SendClaimsIn">Form</Item>

I am not able to reproduce your issue right now. This is my test api call for reference.

<TechnicalProfile Id="TestEchoJson">
  <DisplayName>Test Echo</DisplayName>
  <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.RestfulProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
  <Metadata>
    <Item Key="ServiceUrl">{Settings:TestApiUrl}</Item>
    <Item Key="AuthenticationType">None</Item>
    <Item Key="SendClaimsIn">Body</Item>
    <Item Key="ClaimUsedForRequestPayload">emailRequestBody</Item>
  </Metadata>
  <InputClaimsTransformations>
    <InputClaimsTransformation ReferenceId="GenerateEmailRequestBody" />
  </InputClaimsTransformations>
  <InputClaims>
    <InputClaim ClaimTypeReferenceId="emailRequestBody" />
  </InputClaims>
</TechnicalProfile>

You might have to raise support ticket with Microsoft if the issue persists.

  • Related