dherault / dherault/serverless-offline
How to use $context in the lambda authoriser identitySource?
- Dominant language
- JavaScript
- Stars
- 5.3k
- Forks
- 811
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 3
Description
Hello all, I am writing a lambda authoriser and want to use `context.identity.sourceIp, method.request.headers.Authorization` as `identitySource`. When I deploy the application to AWS, the authorizer is set up correctly and things are working fine.
But when I run my code locally, I get the error `Serverless Offline only supports retrieving tokens from the headers (λ: auth)`. If I remove the `context.identity.sourceIp` from `identitySource` then it will work fine. If AWS is accepting the values it means these values are correct.
Do I need to do some extra things to make it work?
Here is the complete code.
```yaml
functions:
auth:
handler: handlers/auth.auth
vpc: ${self:custom.vpc}
lambda-trigger:
handler: handlers/lambda-trigger.lambdaTrigger
timeout: 10
events:
- http:
method: post
path: /lambda-trigger
cors: true
authorizer:
name: auth
type: REQUEST
identitySource: method.request.header.Authorization, context.identity.sourceIp
resultTtlInSeconds: 0
```
Contributor guide
Research direction
Start by reproducing the issue with the supplied serverless.yml and inspect serverless-offline's REQUEST authorizer handling for identitySource values. Done means local execution accepts the header and context.identity.sourceIp combination, with coverage or documentation reflecting the supported behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, javascript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100