You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd be interested in working on a pull request for this fix, if the maintainers are open to it, I just need some help understanding the intent of the name/scheme properties in the custom auth provider.
Current Behavior
customAuthenticationProvider only works if the service has a single function
HttpServer.setAuthorizationStrategy loops over every function event and calls auth.scheme() on the custom auth provider, but auth.scheme() throws if you try to add the same scheme multiple times.
customAuthenticationProvider should still work if the service has more than one function
Environment
serverless version: 3.38.0
serverless-offline version: 13.6.0 - just reproduced the issue with master@5139c43fc
node.js version: v18.18.0
OS: Ubuntu 20.04
Possible Solution
Change HttpServer.setAuthorizationStrategy or auth.js : scheme() so that it either allows adding the same scheme multiple times, or so that it stops adding the same scheme over and over for each function
Additional context/Screenshots
Stack trace:
Error:
AssertError: Authentication schemenamealreadyexists: schemeatmodule.exports.internals.Auth.scheme(/home/hugo/projects/personal/serverless-offline/node_modules/@hapi/hapi/lib/auth.js:49:14)at #setAuthorizationStrategy (file:///home/hugo/projects/personal/serverless-offline/src/events/http/HttpServer.js:419:25)atHttpServer.createRoutes(file:///home/hugo/projects/personal/serverless-offline/src/events/http/HttpServer.js:1027:60)at #createEvent (file:///home/hugo/projects/personal/serverless-offline/src/events/http/Http.js:41:22)atfile:///home/hugo/projects/personal/serverless-offline/src/events/http/Http.js:46:24atArray.forEach(<anonymous>)
at Http.create (file:///home/hugo/projects/personal/serverless-offline/src/events/http/Http.js:45:12)
at #createHttp (file:///home/hugo/projects/personal/serverless-offline/src/ServerlessOffline.js:192:16)
at async Promise.all (index 0)
at async ServerlessOffline.start (file:///home/hugo/projects/personal/serverless-offline/src/ServerlessOffline.js:98:5)
at async #startWithExplicitEnd (file:///home/hugo/projects/personal/serverless-offline/src/ServerlessOffline.js:154:5)
at async PluginManager.runHooks (/home/hugo/projects/personal/serverless-offline/node_modules/serverless/lib/classes/plugin-manager.js:530:9)
at async PluginManager.invoke (/home/hugo/projects/personal/serverless-offline/node_modules/serverless/lib/classes/plugin-manager.js:564:9)
at async PluginManager.run (/home/hugo/projects/personal/serverless-offline/node_modules/serverless/lib/classes/plugin-manager.js:604:7)
at async Serverless.run (/home/hugo/projects/personal/serverless-offline/node_modules/serverless/lib/serverless.js:179:5)
at async /home/hugo/projects/personal/serverless-offline/node_modules/serverless/scripts/serverless.js:819:9
The text was updated successfully, but these errors were encountered:
humodz
changed the title
customAuthenticationProvider breaks if multiple functions use the same authorizer
customAuthenticationProvider breaks if the service has more than one function
Jun 7, 2024
Bug Report
I'd be interested in working on a pull request for this fix, if the maintainers are open to it, I just need some help understanding the intent of the name/scheme properties in the custom auth provider.
Current Behavior
customAuthenticationProvider only works if the service has a single function
HttpServer.setAuthorizationStrategy
loops over every function event and callsauth.scheme()
on the custom auth provider, butauth.scheme()
throws if you try to add the same scheme multiple times.Sample Code
https://github.com/humodz/serverless-offline/blob/master/tests/integration/custom-authentication/serverless.yml
Expected behavior/code
customAuthenticationProvider should still work if the service has more than one function
Environment
serverless
version: 3.38.0serverless-offline
version: 13.6.0 - just reproduced the issue with master@5139c43fcnode.js
version: v18.18.0OS
: Ubuntu 20.04Possible Solution
Change
HttpServer.setAuthorizationStrategy
orauth.js : scheme()
so that it either allows adding the same scheme multiple times, or so that it stops adding the same scheme over and over for each functionAdditional context/Screenshots
Stack trace:
The text was updated successfully, but these errors were encountered: