Azure B2C Client principal encoding documentation is incorrect?

mumbler_pso2 0 Reputation points
2023-09-23T12:28:55.3233333+00:00

I have a B2C tenant where we have a custom attribute called Player Name. I have a SvelteKit app running on Azure's Static Web Apps consuming the x-ms-client-principal. This field accepts pretty much any character but for our purposes we'd like to allow kanji characters like 漢字 .

When Sveltekit parses the header, I get this exception:

Exception while executing function: Functions.sk_render Result: Failure Exception: Unexpected token  in JSON at position 93 Stack: SyntaxError: Unexpected token  in JSON at position 93     at JSON.parse (<anonymous>)     at getClientPrincipalFromHeaders (/home/site/wwwroot/sk_render/index.js:117420:32)     at Object.index23 (/home/site/wwwroot/sk_render/index.js:117435:27)     at t.InvocationModel.<anonymous> (/azure-functions-host/workers/node/dist/src/worker-bundle.js:2:59683)     at Generator.next (<anonymous>)     at /azure-functions-host/workers/node/dist/src/worker-bundle.js:2:58008     at new Promise (<anonymous>)     at h (/azure-functions-host/workers/node/dist/src/worker-bundle.js:2:57753)     at t.InvocationModel.invokeFunction (/azure-functions-host/workers/node/dist/src/worker-bundle.js:2:59490)     at m.<anonymous> (/azure-functions-host/workers/node/dist/src/worker-bundle.js:2:37872) 
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,407 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Marilee Turscak-MSFT 36,836 Reputation points Microsoft Employee
    2023-09-25T21:36:34.7766667+00:00

    Hi @mumbler_pso2 ,

    Could you clarify which part of the documentation you are suggesting is incorrect?

    Supported languages for B2C are listed here: https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/active-directory-b2c/language-customization.md

    Azure AD B2C does support UTF-8 encoding for custom attributes though. So when you retrieve the custom attribute value using the Azure B2C Graph API or the x-ms-client-principal header, the value is returned as a JSON string. Since JSON uses UTF-8 encoding, Unicode characters in the custom attribute value should be properly encoded and decoded.

    Can you confirm which character is being flagged at that position? Based on your error message it's possible that there is something unsupported by JSON that is failing to parse (for example, a tab "\t" , slash "" , line break, etc).


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.