Skip to content

Add APIGatewayv2 Lambda Authorizer support in events #399

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

Merged
merged 10 commits into from
Mar 29, 2022
50 changes: 50 additions & 0 deletions events/apigw.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,50 @@ type APIGatewayV2HTTPRequestContextAuthenticationClientCertValidity struct {
NotBefore string `json:"notBefore"`
}

type APIGatewayV2CustomAuthorizerV1RequestTypeRequestContext struct {
Path string `json:"path"`
AccountID string `json:"accountId"`
ResourceID string `json:"resourceId"`
Stage string `json:"stage"`
RequestID string `json:"requestId"`
Identity APIGatewayCustomAuthorizerRequestTypeRequestIdentity `json:"identity"`
ResourcePath string `json:"resourcePath"`
HTTPMethod string `json:"httpMethod"`
APIID string `json:"apiId"`
}

type APIGatewayV2CustomAuthorizerV1Request struct {
Version string `json:"version"`
Type string `json:"type"`
MethodArn string `json:"methodArn"` //nolint: stylecheck
IdentitySource string `json:"identitySource"`
AuthorizationToken string `json:"authorizationToken"`
Resource string `json:"resource"`
Path string `json:"path"`
HTTPMethod string `json:"httpMethod"`
Headers map[string]string `json:"headers"`
QueryStringParameters map[string]string `json:"queryStringParameters"`
PathParameters map[string]string `json:"pathParameters"`
StageVariables map[string]string `json:"stageVariables"`
RequestContext APIGatewayV2CustomAuthorizerV1RequestTypeRequestContext `json:"requestContext"`
}

type APIGatewayV2CustomAuthorizerV2Request struct {
Version string `json:"version"`
Type string `json:"type"`
RouteArn string `json:"routeArn"` //nolint: stylecheck
IdentitySource []string `json:"identitySource"`
RouteKey string `json:"routeKey"`
RawPath string `json:"rawPath"`
RawQueryString string `json:"rawQueryString"`
Cookies []string `json:"cookies"`
Headers map[string]string `json:"headers"`
QueryStringParameters map[string]string `json:"queryStringParameters"`
RequestContext APIGatewayV2HTTPRequestContext `json:"requestContext"`
PathParameters map[string]string `json:"pathParameters"`
StageVariables map[string]string `json:"stageVariables"`
}

// APIGatewayCustomAuthorizerContext represents the expected format of an API Gateway custom authorizer response.
// Deprecated. Code should be updated to use the Authorizer map from APIGatewayRequestIdentity. Ex: Authorizer["principalId"]
type APIGatewayCustomAuthorizerContext struct {
Expand Down Expand Up @@ -291,6 +335,12 @@ type APIGatewayV2CustomAuthorizerSimpleResponse struct {
Context map[string]interface{} `json:"context,omitempty"`
}

type APIGatewayV2CustomAuthorizerIAMPolicyResponse struct {
PrincipalID string `json:"principalId"`
PolicyDocument APIGatewayCustomAuthorizerPolicy `json:"policyDocument"`
Context map[string]interface{} `json:"context,omitempty"`
}

// APIGatewayCustomAuthorizerPolicy represents an IAM policy
type APIGatewayCustomAuthorizerPolicy struct {
Version string
Expand Down