-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong response type returned for Custom Authorizer using Minimal API #1666
Comments
@vladyslav-sosnov Good afternoon. Please refer #1527 (reply in thread). The response type appears to be correct based on below findings:
What does your Function Handler (using the Top-Level statements) looks like? Per other issue #1665, I guess your handler looks like this in your top level statements: var handler = (APIGatewayHttpApiV2ProxyRequest request, ILambdaContext lambdaContext) =>
{
var userId = "12345";
// ISSUE: 'httpContext' is always null and therefore, the session can not be accessed.
var session = httpContext.Session;
var sessionData = ObjectSerializer.Deserialize<SessionPermissions>(session.GetString(userId));
// An example of a typical response from the authorizer to invoke the requested Lambda.
var response = new APIGatewayCustomAuthorizerResponse
{
PolicyDocument = new APIGatewayCustomAuthorizerPolicy
{
Version = "2012-10-17",
Statement = new List<APIGatewayCustomAuthorizerPolicy.IAMPolicyStatement>
{
new()
{
Action = new HashSet<string> {"execute-api:Invoke"},
Effect = "Allow",
Resource = new HashSet<string> { $"arn:aws:execute-api:{lambdaContext.InvokedFunctionArn}:{request.RequestContext.AccountId}:{request.RequestContext.ApiId}/$default/*" }
}
},
},
PrincipalID = userId,
Context = new APIGatewayCustomAuthorizerContextOutput
{
["data"] = sessionData.Data
}
};
}; Here, the Lambda expression CCing @normj for additional inputs. Thanks, |
@ashishdhingra The Function Handler (using the Top-Level statements) approach can not be used as per this comment in the code:
That is why a separate issue #1665 was raised. For the current (Minimal API) approach, as described in this issue, another type is returned. |
@vladyslav-sosnov Per analysis in #1666 (comment), it is returning the correct type. I'm unsure if it's possible to return different type in case of minimal API. This needs to be discussed with the team. |
I had never thought of using an ASP.NET Core Lambda function as the implementer of an API Gateway authorizer. The bridge library assumes the incoming event is either The library is designed where there is a separate subclass for request/response pairing. For example when using API Gateway HTTP V2 as the event source the The TLDR here is this would require substantial architecture changes that I'm not really comfortable making. Unless not till we have more asks for this type of feature. Seems like your reasoning for needing this to be part of an ASP.NET Core Lambda function is access to session data. Since you can't use an in memory session store where are you storing session data? Is it possible to right a light weight Lambda function without ASP.NET Core that can access the session data and then you have control over the response format? |
This issue has not received a response in 5 days. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled. |
Describe the bug
Custom Authorizers return AWS Lambda proxy integration response using Minimal API approach instead of API Gateway Lambda authorizer response
For comparison, the Function Handler approach returns the correct response type, however, can not inject HttpContext (Raised separate issue)
Expected Behavior
API Gateway Lambda Custom authorizer response should return a 'API Gateway Lambda authorizer response' when using Minimal API.
Example of EXPECTED response
Current Behavior
API Gateway Lambda Custom authorizer returns a AWS Lambda proxy integration response when using Minimal API. The expected payload is wrapped in the
body
property.Example of ACTUAL response
Reproduction Steps
Code sample illustrating the return of an incorrect response.
Possible Solution
No response
Additional Information/Context
Alternatively, a Function Handler (using the Top-Level statements) approach was trialed where the response type was correct, however, the HttpContext was null.
AWS .NET SDK and/or Package version used
Targeted .NET Platform
.Net 6
Operating System and version
AWS Lambda
The text was updated successfully, but these errors were encountered: