简体   繁体   English

如何从 Azure ad b2c 中的自定义策略更改 rest api 调用中的内容类型?

[英]how to change content-type in rest api call from custom policies in Azure ad b2c?

I am trying to call a SMS provider through custom policies .我正在尝试通过自定义策略致电 SMS 提供商。 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. SMS 提供程序提供的 API 接受下面提到的JSON 有效负载格式的 JSON 有效负载我试图通过传递 JOSN 有效负载来调用此 API,但是当我运行此策略时,请求标头中的内容类型是 application/x-www -form-urlencoded 但 API 只接受 application/json。 Below is the code of the restful technical profile下面是restful技术配置文件的代码

<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 ?问题是如何更改请求的内容类型?

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.这可能是一个错误,请提出 MS 支持票。

I don't believe there is a way to change values of headers using RestfulProvider Technical profile in B2C Custom policy.我不相信有一种方法可以使用 B2C 自定义策略中的 RestfulProvider 技术配置文件来更改标头的值。 The only custom header we can add is for authentication which can be found here B2C Restful Cryptographic keys .我们可以添加的唯一自定义标头是用于身份验证,可以在此处找到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;我尝试调用一些记录标头的测试 api,并且 B2C 始终将内容类型发送为 'application/json; charset=utf-8' while using the Meta data charset=utf-8' 使用元数据时

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

However using Form instead of body produces the header 'content-type': 'application/x-www-form-urlencoded'但是使用 Form 而不是 body 会产生标题 '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.这是我的测试 api 调用以供参考。

<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.如果问题仍然存在,您可能需要向 Microsoft 提出支持请求。

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

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