I'm trying to find a way to allow guest mode in custom authorizer in AWS.
Basically, what I want to achieve is the following scenario:
- if there is no
Authorizationheader in request then trigger lambda function that responds with some data - if there is
Authorizationheader then my custom authorizer should check JWT token and eitherAlloworDeny. Then trigger lambda ifcustom-authorizerreturnedAllow
I see I can achieve either but not both, i.e. I can open the endpoint (remove authorizer completely) which works okay or I can put authorizer which again works okay.
Yet, I don't see a way to by-pass custom-authorizer when there is no Authorization header.
Example configuration in serverless:
functions:
hello:
handler: handler.hello
events:
- http:
path: /hello
method: get
private: true
authorizer:
identitySource: method.request.header.Authorization # Can this be optional?
name: custom-authorizer
custom-authorizer:
handler: authorizer.handler
From my testing I can confirm that once authorization is there and there is no Authorization header in request then my custom-authorizer is not triggered at all and API gateway responds straight away with 401 Unauthorized.
Please take into account that in my guest mode I don't want to get custom API gateway response (this is possible and works). I want to trigger lambda function just like there was no authorization at all.
I'm coming to conclusion this is impossible and the only workaround is to remove authorization and then do some custom code in lambda.
Any advice?