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

feat: Add support for context and multiple identity sources #1642

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

00Greenwood
Copy link

@00Greenwood 00Greenwood commented Jan 5, 2023

Description

This PR adds support for request authorizers to handle context based identity sources. But seeing as context is set by us, I am not throwing an error if context required is not set.
Also added support for request authorizers to handle multiple identity sources, all of them are now check and required for the authorization function to be called.

Motivation and Context

Following on from #1610, my personal project requires a request authorizer which use a context identity source along with a header identity source. AWS supports this by defining the identity sources as a list of comma separated strings XXX, YYY, ZZZ.

How Has This Been Tested?

Ran locally with my Serverless Project which has a request authorizer which requires context and header identity sources.
Added some integration tests for checking the new mixed case.

Screenshots (if appropriate):

@00Greenwood 00Greenwood changed the title feat: Add support for context and multiple authorizer identity sources feat: Add support for context and multiple identity sources Jan 5, 2023
@00Greenwood 00Greenwood marked this pull request as ready for review January 6, 2023 14:42
@airdrummingfool
Copy link

@00Greenwood thanks for this PR! Support for multiple fields in identitySource is a big improvement to Serverless Offline.

I wanted to add a comment for anyone trying to use this with the authorizer payload version 2.0: the identitySource field in v1 is a String, but in v2 it is an Array. I had to add a small check and join to make my array identitySource work.

diff --git a/src/events/http/createAuthScheme.js b/src/events/http/createAuthScheme.js
--- a/src/events/http/createAuthScheme.js
+++ b/src/events/http/createAuthScheme.js
@@ -284,8 +284,9 @@ export default function createAuthScheme(authorizerOptions, provider, lambda) {
       'g',
     )
 
+    const identitySourceString = Array.isArray(authorizerOptions.identitySource) ? authorizerOptions.identitySource.join(',') : authorizerOptions.identitySource;
     const identitySourceMatches =
-      authorizerOptions.identitySource.matchAll(identitySourceRegExp)
+      identitySourceString.matchAll(identitySourceRegExp)
 
     const typesAndFields = []
     for (const match of identitySourceMatches) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants