0

I have an Azure B2C user flow. It is associated with an API Connector pointing to an Azure Function. The function returns a ResponseContent with extension claims:

public class ResponseContent
{
    public const string ApiVersion = "1.0.0";

    public ResponseContent()
    {
        this.version = ResponseContent.ApiVersion;
        this.action = "Continue";
    }

    public ResponseContent(string action, string userMessage)
    {
        this.version = ResponseContent.ApiVersion;
        this.action = action;
        this.userMessage = userMessage;
    }

    public ResponseContent(string userTypes, string accountIdentifiers, string pricebookAuthorized, string portalAuthorized)
    {
        this.version = ResponseContent.ApiVersion;
        this.action = "Continue";
        this.extension_UserTypes = userTypes;
        this.extension_AccountIdentifiers = accountIdentifiers;
        this.extension_PricebookAuthorized = pricebookAuthorized;
        this.extension_PortalAuthorized = portalAuthorized;
    }

    public string version { get; }
    public string action { get; set; }

    [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
    public string userMessage { get; set; }

    [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
    public string extension_UserTypes { get; set; }

    [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
    public string extension_AccountIdentifiers { get; set; }

    [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
    public string extension_PricebookAuthorized { get; set; }

    [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
    public string extension_PortalAuthorized { get; set; }
}

Here are the claims of the user flow:

enter image description here

When I run this Azure function using Postman, the following is returned:

{
  "version": "1.0.0",
  "action": "Continue",
  "extension_UserTypes": "",
  "extension_AccountIdentifiers": "",
  "extension_PricebookAuthorized": "",
  "extension_PortalAuthorized": ""
}

But when I try to run the user flow on Azure, I get

Microsoft.Identity.Client.MsalServiceException: AADB2C90261: The claims exchange 'PreSendClaimsRestful' specified in step '2' returned HTTP error response that could not be parsed.

What might be wrong, and how this can be diagnosed?

halfer
  • 19,824
  • 17
  • 99
  • 186
David Shochet
  • 5,035
  • 11
  • 57
  • 105

1 Answers1

0

Please check if below points can help:

  • Each key value pair in the JSON is treated as string, string collection or Boolean.

  • AADB2C may not deserialise the claim in the JSON you send. One may need to deserialise the string at the API, or will have to return a nested JSON object without the escape characters.

       string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
       dynamic data = JsonConvert.DeserializeObject(requestBody);
    

Reference: dotnet-external-identities-api-connector-azure-function-validate · GitHub

References:

  1. Azure B2C - REST API call Error

  2. Add extra claims to an Azure B2C user flow using API connectors and ASP.NET Core | (damienbod.com)

  3. how-to-parse-json-in-net-core

kavyaS
  • 8,026
  • 1
  • 7
  • 19
  • Thank you for your answer. Could you please clarify how I can apply this information? I don't parse the response in my code, in fact, for now I don't do anything with it. So where should I deserialise the claims? Also, my claims ARE strings (specifically, empty strings in my example), so it is not clear to me what the issue can be. And to collect Azure Active Directory B2C logs with Application Insights would be possible only with custom policy, which I don't use (I use user flow). – David Shochet Mar 15 '22 at 12:40
  • Hi @DavidShochet , have you got a chance to go through this [github sample API code](https://github.com/Azure-Samples/active-directory-dotnet-external-identities-api-connector-azure-function-validate) where you can see [signup validation http trigger function](https://github.com/Azure-Samples/active-directory-dotnet-external-identities-api-connector-azure-function-validate/blob/master/SignUpValidation.cs) and the references provided . – kavyaS Mar 15 '22 at 13:02
  • Yes, in fact, our code is very similar to the one in the example. Do you want to point to something particular there that I might have missed? – David Shochet Mar 15 '22 at 13:18
  • Oh, by the way, I use there the same code as the snippet you provided: string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); – David Shochet Mar 15 '22 at 13:28