用户流 - API 连接器无法解析响应

User Flow - API connector cannot parse response

我有一个 Azure B2C 用户流。它与指向 Azure 函数的 API 连接器相关联。函数 returns 具有扩展声明的 ResponseContent:

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; }
}

用户流的声明如下:

当我 运行 这个 Azure 函数使用 Postman 时,返回以下内容:

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

但是当我尝试 运行 Azure 上的用户流时,我得到

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

可能出了什么问题,如何诊断?

请检查以下几点是否有帮助:

  • JSON中的每个键值对都被当作字符串,字符串 集合或布尔值。

  • AADB2C 可能不会反序列化您发送的 JSON 中的声明。一个可能 需要反序列化 API 处的字符串,或者必须 return 没有转义字符的嵌套 JSON 对象。

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

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

参考文献:

  1. 使用 API 连接器向 Azure B2C 用户流添加额外的声明和 ASP.NET核心| (damienbod.com)

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