Skip to content

Commit 65e0376

Browse files
committed
Attempt to get basic auth working
1 parent 08a0736 commit 65e0376

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

postcode_lookup/lambda_basic_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def lambda_handler(event, context):
2525
return _allow("basic-auth")
2626

2727
print("Not authed, raising")
28-
raise Exception("Unauthorized")
28+
return {"principalId": "anonymous", "policyDocument": {"Version": "2012-10-17", "Statement": [{"Action": "execute-api:Invoke", "Effect": "Deny", "Resource": "*"}]}}
2929

3030

3131
def _ip_in_allowlist(client_ip: str) -> bool:

template.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ Resources:
135135
RestApiId: !Ref ECPostcodeLookupFunctionApiGateway
136136
StatusCode: '401'
137137

138+
139+
AccessDeniedGatewayResponse:
140+
Condition: UseBasicAuth
141+
Type: AWS::ApiGateway::GatewayResponse
142+
Properties:
143+
ResponseParameters:
144+
gatewayresponse.header.www-authenticate: "'Basic realm=\"Restricted\"'"
145+
ResponseType: ACCESS_DENIED
146+
RestApiId: !Ref ECPostcodeLookupFunctionApiGateway
147+
StatusCode: '401'
138148
BasicAuthFunction:
139149
Type: AWS::Serverless::Function
140150
Metadata:

0 commit comments

Comments
 (0)