如何使用hasura中的claims_map正确映射以使"x-hasura-allowed-roles&quo



我有一个JWT令牌,看起来像

{
"aud": "xx",
"iss": "http://xx.com/adfs/services/trust",
"iat": 1649956864,
"exp": 1649960464,
"apptype": "xx",
"appid": "dcf6c0d8-7f3c-4904-a0c9-852c92c7624f",
"authmethod": "http://xx",
"auth_time": "2022-04-14T17:21:04.095Z",
"ver": "1.0"
}

我正在尝试使用Hasura中的claims_mapappid映射到x-hasura-allowed-roles字段中,作为数组的一项。

HASURA_GRAPHQL_JWT_SECRET: '{"jwk_url":"xx","claims_map":{"x-hasura-allowed-roles":{"path":"$.appid"},"x-hasura-default-role":{"path":"$.appid"}}}'

注意里面的这个部分:

"x-hasura-allowed-roles":{"path":"$.appid"}

当我查询时,我会得到这个错误

无效的x-hasura-allowed-roles;应该是角色列表:解析[]失败,应为Array,但遇到String

这是有道理的,因为x-hasura-allowed-roles需要是一个数组。

首次尝试(失败(

如果我改为

"x-hasura-allowed-roles":[{"path":"$.appid"}]

当我启动Hasura时,我会得到错误

致命错误:-环境变量HASURA_GRAPHQL_JWT_SECRET:$['claims_map'][0]中的错误:解析字符串失败,应为字符串,但遇到对象

第二次尝试(失败(

"x-hasura-allowed-roles":{"path":["$.appid"]}

致命错误:-环境变量HASURA_GRAPHQL_JWT_SECRET:$['claims_map']中的错误。路径:解析文本失败,应为字符串,但遇到数组

如何正确映射使x-hasura-allowed-roles字段成为数组?感谢

@Arjun Yelamanchili在https://github.com/hasura/graphql-engine/issues/8402


这是一个临时解决方案,我最终得到了像一样的硬编码x-hasura-allowed-roles

HASURA_GRAPHQL_JWT_SECRET: '{"jwk_url":"xx","claims_map":{"x-hasura-allowed-roles":["dcf6c0d8-7f3c-4904-a0c9-852c92c7624f"],"x-hasura-default-role":{"path":"$.appid"}}}'

它更严格。

然而,我觉得这可能没有必要,因为我们将在Hasura UI中定义每个appid权限。此外,每次安装新应用程序时,我都需要更新HASURA_GRAPHQL_JWT_SECRET

相关内容

最新更新