【发布时间】:2019-10-07 14:20:44
【问题描述】:
我创建了一个自定义 lambda 授权器,用于验证 JWT 并返回 Allow 策略。
var context = new APIGatewayCustomAuthorizerContextOutput();
var tokenUse = ExtractClaims(claims, "token_use");
context["tokenType"] = tokenUse;
var response = new APIGatewayCustomAuthorizerResponse
{
PrincipalID = "asd",
PolicyDocument = new APIGatewayCustomAuthorizerPolicy
{
Version = "2012-10-17",
Statement = new List<APIGatewayCustomAuthorizerPolicy.IAMPolicyStatement>()
{
new APIGatewayCustomAuthorizerPolicy.IAMPolicyStatement
{
Action = new HashSet<string>() {"execute-api:Invoke"},
Effect = "Allow",
Resource = new HashSet<string>() {"***"} // resource arn here
}
},
},
Context = context
};
return response;
现在我需要在我的资源服务器上使用这个身份。
问题是我在授权人上下文中的声明直接出现在authorizer下
"authorizer": {
"cognito:groups": "Admin", ...
}
但我的Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction 期望那些在authorizer.claims 下的人。
像这样:
"authorizer": {
"claims": {
"cognito:groups": "Admin", ...
}
}
我知道这一点,因为当我使用内置的 Cognito 用户池授权器时它正在工作,它会像这样进行输入。
我设法发现不允许 Lambda Authorizer 将嵌套对象添加到上下文中(并测试如果我这样做它会抛出 authorizer error。)
我还发现APIGatewayProxyFunction 在提取身份时,它会查看 Authorizer.Claims。
所以我需要绕过Claims 属性在我的资源服务器上提取它们,或者将嵌套对象添加到授权方响应中,这是不允许的。
做什么?
【问题讨论】:
标签: asp.net-core asp.net-identity amazon-cognito aws-sdk-net lambda-authorizer