Skip to content
Discussion options

You must be logged in to vote

Handled it with the DefaultHttpRequestInterceptor from hotchocolate.
public class AuthenticationInterceptor : DefaultHttpRequestInterceptor
{
public override ValueTask OnCreateAsync(HttpContext context, IRequestExecutor requestExecutor,
IQueryRequestBuilder requestBuilder,
CancellationToken cancellationToken)
{
var authenticationService = context.RequestServices.GetService();
var task = authenticationService.AuthenticateAsync(context, "Api");
task.Wait(cancellationToken);
var result = task.Result;
if (!result.Succeeded)
{
throw new QueryException(
ErrorBuilder.New()
.SetMessage("Resource is restricted to authenticated users")
.SetCode("UNAUTHENTICATED")
.Build());
}
return base.OnCreateAs…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Mordsspass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant