Skip to content

Commit

Permalink
Add client certificate struct as field to APIGatewayRequestIdentity
Browse files Browse the repository at this point in the history
As seen in the docs https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html this field should be present. Used a pointer so that field is omitted when not set.
  • Loading branch information
Jonathan Miao committed Nov 6, 2024
1 parent 8e674da commit 19fb53e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
27 changes: 14 additions & 13 deletions events/apigw.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,20 @@ type APIGatewayV2HTTPResponse struct {

// APIGatewayRequestIdentity contains identity information for the request caller.
type APIGatewayRequestIdentity struct {
CognitoIdentityPoolID string `json:"cognitoIdentityPoolId,omitempty"`
AccountID string `json:"accountId,omitempty"`
CognitoIdentityID string `json:"cognitoIdentityId,omitempty"`
Caller string `json:"caller,omitempty"`
APIKey string `json:"apiKey,omitempty"`
APIKeyID string `json:"apiKeyId,omitempty"`
AccessKey string `json:"accessKey,omitempty"`
SourceIP string `json:"sourceIp"`
CognitoAuthenticationType string `json:"cognitoAuthenticationType,omitempty"`
CognitoAuthenticationProvider string `json:"cognitoAuthenticationProvider,omitempty"`
UserArn string `json:"userArn,omitempty"` //nolint: stylecheck
UserAgent string `json:"userAgent"`
User string `json:"user,omitempty"`
CognitoIdentityPoolID string `json:"cognitoIdentityPoolId,omitempty"`
AccountID string `json:"accountId,omitempty"`
CognitoIdentityID string `json:"cognitoIdentityId,omitempty"`
Caller string `json:"caller,omitempty"`
APIKey string `json:"apiKey,omitempty"`
APIKeyID string `json:"apiKeyId,omitempty"`
AccessKey string `json:"accessKey,omitempty"`
SourceIP string `json:"sourceIp"`
CognitoAuthenticationType string `json:"cognitoAuthenticationType,omitempty"`
CognitoAuthenticationProvider string `json:"cognitoAuthenticationProvider,omitempty"`
UserArn string `json:"userArn,omitempty"` //nolint: stylecheck
UserAgent string `json:"userAgent"`
User string `json:"user,omitempty"`
ClientCert *APIGatewayCustomAuthorizerRequestTypeRequestIdentityClientCert `json:"clientCert,omitempty"`
}

// APIGatewayWebsocketProxyRequest contains data coming from the API Gateway proxy
Expand Down
10 changes: 10 additions & 0 deletions events/apigw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ func TestApiGatewayRequestMarshaling(t *testing.T) {
t.Errorf("could not extract authorizer context: %v", authContext)
}

clientCert := inputEvent.RequestContext.Identity.ClientCert
if clientCert.ClientCertPem != "CERT_CONTENT" ||
clientCert.SubjectDN != "www.example.com" ||
clientCert.IssuerDN != "Example issuer" ||
clientCert.SerialNumber != "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1" ||
clientCert.Validity.NotBefore != "May 28 12:30:02 2019 GMT" ||
clientCert.Validity.NotAfter != "Aug 5 09:36:04 2021 GMT" {
t.Errorf("could not extract client certificate content: %v", clientCert)
}

// serialize to json
outputJSON, err := json.Marshal(inputEvent)
if err != nil {
Expand Down
12 changes: 11 additions & 1 deletion events/testdata/apigw-request.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,17 @@
"cognitoAuthenticationProvider": "theCognitoAuthenticationProvider",
"userArn": "theUserArn",
"userAgent": "PostmanRuntime/2.4.5",
"user": "theUser"
"user": "theUser",
"clientCert": {
"clientCertPem": "CERT_CONTENT",
"subjectDN": "www.example.com",
"issuerDN": "Example issuer",
"serialNumber": "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1",
"validity": {
"notBefore": "May 28 12:30:02 2019 GMT",
"notAfter": "Aug 5 09:36:04 2021 GMT"
}
}
},
"authorizer": {
"principalId": "admin",
Expand Down

0 comments on commit 19fb53e

Please sign in to comment.