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 all commits
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
31 changes: 17 additions & 14 deletions src/events/http/createAuthScheme.js
Expand Up @@ -77,19 +77,17 @@ export default function createAuthScheme(authorizerOptions, provider, lambda) {
authorization = queryStringParameters[identitySourceField]
break
}
case IDENTITY_SOURCE_TYPE_NONE: {
break
}
default: {
throw new Error(
`No Authorization source has been specified. This should never happen. (λ: ${authFunName})`,
)
break
}
}

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

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

if (authorizerOptions.identitySource) {
// Only validate the first of N possible headers.
const headerRegExp = /^(method.|\$)request.header.((?:\w+-?)+\w+).*$/
const queryStringRegExp =
Expand All @@ -298,9 +299,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})`,
)
}
}

if (authorizerOptions.resultTtlInSeconds === 0) {
Expand Down