Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Empty Identity Source for Request Lambda Authorisers #1720

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 16 additions & 12 deletions src/events/http/createAuthScheme.js
Expand Up @@ -71,13 +71,12 @@ export default function createAuthScheme(authorizerOptions, provider, lambda) {
} else if (identitySourceType === IDENTITY_SOURCE_TYPE_QUERYSTRING) {
const queryStringParameters = parseQueryStringParameters(url) ?? {}
authorization = queryStringParameters[identitySourceField]
} else {
throw new Error(
`No Authorization source has been specified. This should never happen. (λ: ${authFunName})`,
)
}

if (authorization === undefined) {
if (
authorization === undefined &&
authorizerOptions.type !== 'request'
) {
log.error(
`Identity Source is null for ${identitySourceType} ${identitySourceField} (λ: ${authFunName})`,
)
Expand Down Expand Up @@ -266,10 +265,13 @@ export default function createAuthScheme(authorizerOptions, provider, lambda) {
return identitySourceMatch[expectedLength - 1]
}

if (
authorizerOptions.type !== 'request' ||
authorizerOptions.identitySource
) {
if (authorizerOptions.identitySource === '') {
identitySourceField = null
identitySourceType = null
return finalizeAuthScheme()
}

if (authorizerOptions.identitySource) {
const headerRegExp = /^(method.|\$)request.header.((?:\w+-?)+\w+)$/
const queryStringRegExp =
/^(method.|\$)request.querystring.((?:\w+-?)+\w+)$/
Expand All @@ -291,9 +293,11 @@ export default function createAuthScheme(authorizerOptions, provider, lambda) {
return finalizeAuthScheme()
}

throw new Error(
`Serverless Offline only supports retrieving tokens from headers and querystring parameters (λ: ${authFunName})`,
)
if (authorizerOptions.type !== 'request') {
throw new Error(
`Serverless Offline only supports retrieving tokens from headers and querystring parameters (λ: ${authFunName})`,
)
}
}

return finalizeAuthScheme()
Expand Down