Register Authentication strategy in graphql #7916
Unanswered
dineshkuncham7
asked this question in
Q&A
Replies: 1 comment 6 replies
-
@dineshkuncham7 I suppose you are using this.bind(GraphQLBindings.GRAPHQL_AUTH_CHECKER).to(
async (resolverData: any) => {
// get your request object
const Request = resolverData?.context?.req;
// bind it
this.bind(RestBindings.Http.REQUEST).to(Request);
// get your service to do authentication
const jwtService = await this.get<JwtService>(
ServiceBindings.JWT_SERVICE.key,
);
// end result would be a boolean.
return jwtService.authenticate(resolverData?.context?.req?.headers);
},
);
and enforce security in your resolvers like: @authorized() // this would trigger authorization
@query(() => Recipes, {nullable: true})
async recipes() {
} |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In Loopback rest we can register authentication strategy with 'registerAuthenticationStrategy' from @loopback/authentication, similarly how can we do it for graphql resolvers?
Beta Was this translation helpful? Give feedback.
All reactions