从ADB2C中的自定义策略返回简单的字符串声明 [英] Return simple string claim from custom policies in ADB2C
问题描述
我关注了这篇文章其中说明了如何使用Active Directory B2C实施自定义策略.一切工作正常,我唯一关心的是自定义声明的返回像序列化对象一样.让我更好地解释一下.我成功创建了返回自定义声明的Azure函数.编码后的结果JWT类似于以下内容(请关注" userPermissions "值):
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
}
如您所见," userPermissions "声明是序列化JSON".我想拥有一个像以下这样的JWT:
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
}
如您所见,"test1"是一个简单的字符串.您可能会想:来吧BrianEnno!这非常简单,而不是返回序列化JSON".您的Azure函数应返回字符串".好吧,如果我尝试返回一个(格式正确的)字符串,则会收到此错误:
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:在步骤"4"中指定的声明交换"GetPermissions"返回了无法解析的HTTP错误响应.
ServerError: AADB2C90261: The claims exchange 'GetPermissions' specified in step '4' returned HTTP error response that could not be parsed.
有没有办法让它工作?
推荐答案
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;
}
这篇关于从ADB2C中的自定义策略返回简单的字符串声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!