Return simple string claim from custom policies in ADB2C

Viewed 563

I followed this article where it explains how to implement a custom policy using Active Directory B2C. Everything is working great, the only concern I have is that the custom claim is returned like a serialized object. Let me explain a little bit better. I successfully created the Azure Function which return the custom claim. The encoded resulting JWT is like the following (please focus on the "userPermissions" value):

{
  "exp": 1594560277,
  "nbf": 1594556677,
  "ver": "1.0",
  "auth_time": 1594556677,
  "userPermissions": "{\r\n \"permissions\":\"test1\"\r\n}" <============= HERE
}

As you can see the "userPermissions" claim is a "serialized JSON". I would like to have a JWT like the following:

{
  "exp": 1594560277,
  "nbf": 1594556677,
  "ver": "1.0",
  "auth_time": 1594556677,
  "userPermissions": "test1" <============ HERE
}

As you can see the "test1" is a simple string. You may think: come on BrianEnno! This is very simple, instead of returning a "serialized JSON" your Azure Function should return a "string". Well, if I try to return a (well formed) string I received this error:

ServerError: AADB2C90261: The claims exchange 'GetPermissions' specified in step '4' returned HTTP error response that could not be parsed.

Is there a way to let it work?

1 Answers
using Microsoft.AspNetCore.Mvc;
[HttpGet]
        public async Task<JsonResult> Groups(string objectId)
        { 
            string userPermissions = "test1";
            
            //!!!!!This is the trick if I sent plain json I got the error
            
            JsonResult o = new JsonResult(
                new
                {
                    userPermissions;
                });

            return o;
}  
 
Related