public async Task BeforeHandleAsync(MessageHandlingContext context) { var httpContext = _httpContextAccessor.HttpContext; if (httpContext != null) { if (httpContext.WebSockets.IsWebSocketRequest && (!httpContext.User.Identity.IsAuthenticated)) { await _webSocketPreHandler.PrepareContext(httpContext); } var userContext = new GraphQLUserContext { User = httpContext.User }; // if the default auth scheme is cookies // users from remote clients that pass bearer token are not automatically authenticated if (!httpContext.User.Identity.IsAuthenticated) { var result = await httpContext.AuthenticateAsync("Bearer"); if (result.Succeeded) { userContext.User = result.Principal; } } context.Properties.TryAdd("UserContext", userContext); } }
public static async Task <GraphQLUserContext> BuildUserContext(HttpContext context) { var userContext = new GraphQLUserContext { User = context.User }; // if the default auth scheme is cookies // users from remote clients that pass bearer token are not automatically authenticated if (!context.User.Identity.IsAuthenticated) { var result = await context.AuthenticateAsync("Bearer"); if (result.Succeeded) { userContext.User = result.Principal; } } return(userContext); }