#api-gateway graphql guard

8 messages · Page 1 of 1 (latest)

vast comet
#

Hi,
I'm using api-gateway graphql and I would like to setup auth on that -> https://docs.nestjs.com/graphql/federation

I've got guard like this -> https://codesandbox.io/s/azure-ad-nestjs-zykko?file=/src/azure-ad.guard.ts

However I'm not sure how could I apply this guard/strategy for api-gateway. Any ideas on how to do that?

Nest TypeScript starter repository

gusty blade
#

Do you want guards for resolvers or for /graphql? Because a Middleware might be easier than

vast comet
#

@gusty blade I want for whole /graphql and all endpoints

gusty blade
#

Then I would advise to look into Middleware

vast comet
#

@gusty blade I'm guessing that in graphql api gateway case I could simply do something like this in server:

context: handleAuth,

where handleAuth is something like const handleAuth = ({ req }) => { -> so like a middleware.
I was thinking if there is a way to use passport strategy like in codesandbox for this -> https://codesandbox.io/s/azure-ad-nestjs-zykko?file=/src/azure-ad.guard.ts

but it might just be wrong approach.

Nest TypeScript starter repository

gusty blade
#

Depends. Actually you could do that in the app module already

vast comet
#

@gusty blade can you explain to me how could I do that in app module?

gusty blade