Skip to content

Commit d406b13

Browse files
Jon-MiaoJonathan Miaobmoffatt
authored
Add client certificate struct as field to APIGatewayRequestIdentity (#573)
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. Co-authored-by: Jonathan Miao <[email protected]> Co-authored-by: Bryan Moffatt <[email protected]>
1 parent 288af9e commit d406b13

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

events/apigw.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,20 @@ type APIGatewayV2HTTPResponse struct {
133133

134134
// APIGatewayRequestIdentity contains identity information for the request caller.
135135
type APIGatewayRequestIdentity struct {
136-
CognitoIdentityPoolID string `json:"cognitoIdentityPoolId,omitempty"`
137-
AccountID string `json:"accountId,omitempty"`
138-
CognitoIdentityID string `json:"cognitoIdentityId,omitempty"`
139-
Caller string `json:"caller,omitempty"`
140-
APIKey string `json:"apiKey,omitempty"`
141-
APIKeyID string `json:"apiKeyId,omitempty"`
142-
AccessKey string `json:"accessKey,omitempty"`
143-
SourceIP string `json:"sourceIp"`
144-
CognitoAuthenticationType string `json:"cognitoAuthenticationType,omitempty"`
145-
CognitoAuthenticationProvider string `json:"cognitoAuthenticationProvider,omitempty"`
146-
UserArn string `json:"userArn,omitempty"` //nolint: stylecheck
147-
UserAgent string `json:"userAgent"`
148-
User string `json:"user,omitempty"`
136+
CognitoIdentityPoolID string `json:"cognitoIdentityPoolId,omitempty"`
137+
AccountID string `json:"accountId,omitempty"`
138+
CognitoIdentityID string `json:"cognitoIdentityId,omitempty"`
139+
Caller string `json:"caller,omitempty"`
140+
APIKey string `json:"apiKey,omitempty"`
141+
APIKeyID string `json:"apiKeyId,omitempty"`
142+
AccessKey string `json:"accessKey,omitempty"`
143+
SourceIP string `json:"sourceIp"`
144+
CognitoAuthenticationType string `json:"cognitoAuthenticationType,omitempty"`
145+
CognitoAuthenticationProvider string `json:"cognitoAuthenticationProvider,omitempty"`
146+
UserArn string `json:"userArn,omitempty"` //nolint: stylecheck
147+
UserAgent string `json:"userAgent"`
148+
User string `json:"user,omitempty"`
149+
ClientCert *APIGatewayCustomAuthorizerRequestTypeRequestIdentityClientCert `json:"clientCert,omitempty"`
149150
}
150151

151152
// APIGatewayWebsocketProxyRequest contains data coming from the API Gateway proxy

events/apigw_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ func TestApiGatewayRequestMarshaling(t *testing.T) {
3333
t.Errorf("could not extract authorizer context: %v", authContext)
3434
}
3535

36+
clientCert := inputEvent.RequestContext.Identity.ClientCert
37+
if clientCert.ClientCertPem != "CERT_CONTENT" ||
38+
clientCert.SubjectDN != "www.example.com" ||
39+
clientCert.IssuerDN != "Example issuer" ||
40+
clientCert.SerialNumber != "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1" ||
41+
clientCert.Validity.NotBefore != "May 28 12:30:02 2019 GMT" ||
42+
clientCert.Validity.NotAfter != "Aug 5 09:36:04 2021 GMT" {
43+
t.Errorf("could not extract client certificate content: %v", clientCert)
44+
}
45+
3646
// serialize to json
3747
outputJSON, err := json.Marshal(inputEvent)
3848
if err != nil {

events/testdata/apigw-request.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,17 @@
7979
"cognitoAuthenticationProvider": "theCognitoAuthenticationProvider",
8080
"userArn": "theUserArn",
8181
"userAgent": "PostmanRuntime/2.4.5",
82-
"user": "theUser"
82+
"user": "theUser",
83+
"clientCert": {
84+
"clientCertPem": "CERT_CONTENT",
85+
"subjectDN": "www.example.com",
86+
"issuerDN": "Example issuer",
87+
"serialNumber": "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1",
88+
"validity": {
89+
"notBefore": "May 28 12:30:02 2019 GMT",
90+
"notAfter": "Aug 5 09:36:04 2021 GMT"
91+
}
92+
}
8393
},
8494
"authorizer": {
8595
"principalId": "admin",

0 commit comments

Comments
 (0)