Extract boolean element from JSON with custom policy

Viewed 70

I want to ask if there is a way to extract a boolean element from a JSON response from REST API.

I have a claim that contains a JSON:

{
    "customerEntity": {
        "role": {
            "id": 1
        }
    },
    "settings": {
        "isAdmin": false,
        "isBlocked": false
    }
}

I already tried the following ClaimsTransformations: GetClaimFromJson, GetSingleItemFromJson however it returns an error during the upload to Identity Experience Framework since the expected extracted claim is a String.

Would greatly appreciate your help.

1 Answers

The simplest solution would be to map the response to a claim from the REST API technical profile.

I'll add a simple example that I used for testing

Technical Profile

      <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="ResolveJsonPathsInJsonTokens">true</Item>
          <Item Key="SendClaimsIn">QueryString</Item>
        </Metadata>
        <OutputClaims>
          <OutputClaim ClaimTypeReferenceId="isAdmin" PartnerClaimType="settings.isAdmin" />
          <OutputClaim ClaimTypeReferenceId="customProperty" PartnerClaimType="settings.customProperty" />
        </OutputClaims>
      </TechnicalProfile>

The Claim schema

      <ClaimType Id="customProperty">
        <DisplayName>customProperty</DisplayName>
        <DataType>string</DataType>
      </ClaimType>
      
      <ClaimType Id="isAdmin">
        <DisplayName>isAdmin</DisplayName>
        <DataType>boolean</DataType>
      </ClaimType>

Mock Api used for testing

app.get('/echo', async (req, res) => {

    let jsonResponse = {
        "customerEntity": {
            "role": {
                "id": 1
            }
        },
        "settings": {
            "isAdmin": false,
            "isBlocked": false,
            "customProperty": "Hello there"
        },
    };

    res.json(jsonResponse);
});
Related