0

I have a call to REST API that returns:

{
    "a": false,
    "b": 1,
    "student": {
        "person": {
            "name": "Complete name here"
            ...
        }
    }
}

In this way... I need extract person.name from student to a claim in B2C, but at moment, can only get student in this format below

"student": "{\r\n  \"studyShiftId\": 4,\r\n  \"academicActive\": true,\r\n  \"active\": true,\r\n  \"person\": {\r\n    \"documentCode\": \"041.407.671-03\",\r\n    \"name\": \"LEONARDO SOARES DOS SANTOS\",\r\n },\r\n  \"course\": [\r\n    {\r\n      \"name\": \"Direito - Bacharelado\",\r\n      \"type\": \"Presencial\",\r\n      \"enrollmentCode\": \"3699342283\",\r\n      \"alucod\": \"3699342\",\r\n      \"academicStateCode\": \"P\",\r\n      \"academicStateName\": \"Período de Matrícula\",\r\n      \"campus\": {\r\n        \"name\": \"UNICEN PRIMAVERA - UNIDADE NOVA\",\r\n        \"brand\": {\r\n          \"name\": \"Unic\",\r\n          \"urlImg\": \"https://stportaldoalunotst.blob.core.windows.net/unic.png\",\r\n          \"color\": \"#005397\"\r\n        }\r\n      }\r\n    }\r\n  ]\r\n}"
<ClaimType Id="student">
    <DataType>string</DataType>
</ClaimType>

I already tried use GetClaimFromJson / Microsoft Docs and raises me a fatal exception

Claim transformations:

<ClaimsTransformation Id="GetPersonalDataFromJson" TransformationMethod="GetClaimFromJson">
  <InputClaims>
    <InputClaim ClaimTypeReferenceId="student" TransformationClaimType="inputJson" />
  </InputClaims>
  <InputParameters>
    <InputParameter Id="claimToExtract" DataType="string" Value="person" />
  </InputParameters>
  <OutputClaims>
    <OutputClaim ClaimTypeReferenceId="extension_person" TransformationClaimType="extractedClaim" />
  </OutputClaims>
</ClaimsTransformation>

<ClaimsTransformation Id="GetEmailFromPersonalData" TransformationMethod="GetClaimFromJson">
  <InputClaims>
    <InputClaim ClaimTypeReferenceId="extension_person" TransformationClaimType="inputJson" />
  </InputClaims>
  <InputParameters>
    <InputParameter Id="claimToExtract" DataType="string" Value="email" />
  </InputParameters>
  <OutputClaims>
    <OutputClaim ClaimTypeReferenceId="email" TransformationClaimType="extractedClaim" />
  </OutputClaims>
</ClaimsTransformation>

In short: Extract claim inside child elements from JSON data, path like e.g: student.person.name

Appreciate any help.

Reni Dantas
  • 117
  • 10
  • Could you add the transform code you tried to use in the question? – juunas Dec 04 '20 at 08:08
  • I've edited.... – Reni Dantas Dec 04 '20 at 09:03
  • Could you try using `student.person.name` as the claimToExtract to get the claim at once? This kind of format works in the generate JSON transform, but not sure if it works with this. – juunas Dec 04 '20 at 09:09
  • Could you review again pls? – Reni Dantas Dec 04 '20 at 10:24
  • Can you please share the REST API technical profile configuration of your custom policy – Raghavendra beldona Dec 10 '20 at 17:51
  • You can share a example for this working [https://learn.microsoft.com/en-us/azure/active-directory-b2c/json-transformations#getclaimfromjson]? Can i enter StringCollection in Input to GetClaimFromJson? My API return a JSON data, stored in claim stringCollection how i extract claim from this? – Reni Dantas Dec 15 '20 at 20:37
  • While there is no official GitHub repo specifically for getting claims from a json array, [this sample B2C policy](https://github.com/Azure-Samples/active-directory-b2c-custom-policy-starterpack/blob/32f1dca1e87423ac190cb00e71c12ef699e351be/scenarios/linkedin-identity-provider/TrustFrameworkExtensions.xml#L118) shows an example of a policy that transforms json claims. – Raghavendra beldona Dec 17 '20 at 11:41
  • Thanks, it worked. – Reni Dantas Dec 18 '20 at 17:01

0 Answers0