-
Notifications
You must be signed in to change notification settings - Fork 33
Add Authorizer struct to APIGateway Event #34
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
Add Authorizer struct to APIGateway Event #34
Conversation
looks good. can we update / add a test? |
@swift-server-bot test this please |
Oh sure! Sorry, in hindsight, I should have done that. I'll add a test and update the PR. |
@swift-server-bot test this please |
thanks for this @richwolf looks like the soundness job is failing due to formatting issue. you can run it locally to get this all lined up:
|
Yeah, it doesn't surprise me that there could be a formatting issue. I have my Xcode set to 2 space tabs, but notice that the project is 4 spaces ... uh ... spaces. I thought I caught all the tabs, but maybe not? Running the soundness thingy now. Very cool tool. :) |
@swift-server-bot test this please |
thanks @richwolf |
Add an
Authorizer
struct to theAPIGateway
(v1) eventMotivation:
When setting up an API Gateway REST API (as opposed to the v2 HTTP API) with Lambda integration, a resource endpoint can be configured to use "Lambda Proxy Integration"…which results in the v1-style
APIGatewayRequest
event object being sent to a Swift Lambda handler (as opposed to theAPIGatewayV2Request
object, which gets sent whenever API Gateway is configured as an "HTTP" API). TheAPIGatewayRequest
event struct does not decode anauthorizer
…which is included within Lambda Proxy Integration JSON whenever Cognito is attached to REST endpoints. Theauthorizer
contains aclaims
dictionary (very much like the one found in theAPIGatewayV2Request
object):Just as with the
APIGatewayV2
event, the claims dictionary would be useful to Swift Lambda event handlers (particularly because it contains the Cognito username authorized to invoke an API endpoint).Modifications:
I added an (optional)
Authorizer
struct to theAPIGatewayRequest
object. The struct contains a single public property…an optionalclaims
object (dictionary of type[String: String]
in a way that mirrors the authorizer implementation in theAPIGatewayV2Request
object.Result:
The
APIGatewayRequest
object now successfully decodes theauthorizer
sent by the Lambda Proxy Integration JSON and can be used within a Swift Lambda event handler.