completecoding / serverless-auto-swagger

79 stars 48 forks source link

Issue with shared authorizers #107

Open AdriaFret opened 1 year ago

AdriaFret commented 1 year ago

Hello! We are having some troubles trying to implement the lambdaAuthorizer in the swagger endpoints. We have a microservices architechture, our authorizer is in a separated microservice and we can use this authorizer ( via output variable) in our lambdas. Here is a code snipet of how we use this authorizer in our lambdas:

image

The idea that we had is to reuse this authorizer for the lambdaAuthorizer section but we can't figure it out why it ain't working (maybe we are missunderstanding or doing something wrong).

Thank you for your time in advance.

bfaulk96 commented 1 year ago

Could you please show your serverless-auto-swagger custom config in your Serverless file?

AdriaFret commented 1 year ago

Yes for sure, thats how we tried to configure it but we couldn't figure it out a way to make it work:

image
bfaulk96 commented 1 year ago

Could you try making lambdaAuthorizer the same object that you're using in your http events, i.e.

custom:
  ...
  customAuthorizer:
    type: COGNITO_USER_POOLS
    authorizerId: !ImportValue authorizer
  autoswagger:
    ...
    lambdaAuthorizer: ${self:custom.customAuthorizer}

functions:
  ...
  test:
    ...
    events:
      - http:
          ...
          authorizer: ${self:custom.customAuthorizer}

This was my use-case when I added this feature. If this doesn't work, I honestly don't know a ton about authorizers, so I don't know if more complex scenarios are possible.

(also, careful with the indentation in my example – treat that as pseudo-code, as I simply typed it up in GitHub markdown code)

arijitsarkar2k14 commented 1 year ago

I have tried the same. But after running sls offline start, it is generated swagger.js file with "securityDefinitions": {}, and hence my custom authorizer is not working in the swagger UI