I have a user flow B2C_1_singupsingin1 I added an api connector, embed it in this stream and the endpoint url for the API call. Used article: https://docs.microsoft.com/en-us/azure/active-directory-b2c/add-api-connector-token-enrichment?pivots=b2c-user-flow
It is clear from the article that the API connector materializes as an HTTP POST request, sending custom attributes.
My web api has an endpoint with the code:
[HttpPost("enrich")]
public IActionResult Enrich([FromBody] JsonElement body)
{
var responseProperties = new Dictionary<string, object> //for example
{
{ "version", "1.0.0" },
{ "action", "Continue" },
{ "postalCode", "12349" },
{ "userId", 123 }
};
return new JsonResult(responseProperties) { StatusCode = 200 };
}
When I start a custom flow everything works, I get to that endpoint in api.
But there is a problem JsonElement body does't contain custom attributes. Inside I see body.ValueKind = Undefined
.
Tell me what am I doing wrong?
Also, after all, I wanted to add a custom "userId" claim with some value from my database. So that it is contained in the token issued in the subsequent. Would the code above be correct for this?
Your code is fine. Just add "extension_" in front of postalCode and userId.
[HttpPost("log")]
public IActionResult Log([FromBody] JsonElement body)
{
var responseProperties = new Dictionary<string, object>
{
{ "version", "1.0.0" },
{ "action", "Continue" },
{ "extension_Role", "admin" },
};
return new JsonResult(responseProperties) { StatusCode = 200 };
}
In my Azure AD B2C I have a custom attribute called "Role".
But in debug mode I saw that for all the custom attributes extension_ is set as prefix...
So by adding this to responseProperties it seems to be working.