Comments (4)
UserContextExtensions.GetClaims
is called within the resolve. BTW we are well off track from this having anything to do with GraphQL.EntityFramework, ie your current problem could be reproduced without using GraphQL.EntityFramework. Perhaps move the question to stackoverflow? Or i can quote you an hourly rate to help you debug further
from graphql.entityframework.
By passing the DataContext in on the UserContext, does this make it impossible to use authentication
yes. but nothing about GraphQL.EntityFramework forces u to take that approach. what u place in the graphql context, and how u read from it is up to u. So at my current client we have this model for the user context
public class GraphQlUserContext
{
public ElectorateDbContext DbContext { get; set; }
public ClaimsPrincipal User { get; set; }
}
then in the graphql controller we do
var options = new ExecutionOptions
{
Schema = schema,
Query = query,
OperationName = operationName,
Inputs = variables?.ToInputs(),
UserContext = new GraphQlUserContext
{
DbContext = dataContext,
User = User
},
CancellationToken = cancellation,
#if (DEBUG)
ExposeExceptions = true,
EnableMetrics = true,
#endif
};
then we have some helper extension methods
static class UserContextExtensions
{
public static ElectorateDbContext GetDataContext(this ResolveFieldContext<object> context)
{
var userContext = (GraphQlUserContext) context.UserContext;
return userContext.DbContext;
}
public static ElectorateDbContext GetDataContext<T>(this ResolveFieldContext<T> context)
{
var userContext = (GraphQlUserContext) context.UserContext;
return userContext.DbContext;
}
public static List<Claim> GetClaims(this ResolveFieldContext<object> context)
{
var userContext = (GraphQlUserContext)context.UserContext;
return userContext.User.Claims.ToList();
}
}
which enables a query like this
public class Query : EfObjectGraphType
{
public Query(IEfGraphQLService efGraphQlService) : base(efGraphQlService)
{
AddSingleField<ProgramGraph, Program>(
name:"program",
resolve: context =>
{
var dataContext = context.GetDataContext();
return dataContext.Programs;
});
from graphql.entityframework.
Hi Simon,
Thank you for the ultra-quick response :)
I have plumbed up as per your example, the dbcontext is working correctly.
I am missing something with the UserClaims as I keep getting the error message on my mutation:
GraphQL.Validation.ValidationError: You are not authorized to run this mutation.\nRequired claim 'role' with any value of 'Admin' is not present.
When I set a breakpoint on my:
var options = new ExecutionOptions
I can see that the User object has the correct claims, and my ValidationRule is being populated.
In you code, where are calling UserContextExtensions.GetClaims from?
Many thanks.
Jeremy
from graphql.entityframework.
closing this for now
from graphql.entityframework.
Related Issues (20)
- Can't register some classes into Autofac container HOT 2
- Documentation Request: Describe function behavior HOT 1
- Improvement: supporting contributions through more maintainable code HOT 3
- Remove AND + OR from Connector
- remove `Graph` suffic from build in graphs
- Putting 'where' on a sub graph doesn't evaluate at db HOT 14
- KeyNameExtractor creates collisions with many-to-many relationship HOT 1
- Quotes no longer required around where properties HOT 2
- Is it possible to use it for working without EF? HOT 3
- Add support for owned entities
- Make connection non nullable
- Fix SetField order
- 'Case' in where clause is throwing an error HOT 3
- Update to EF 6
- RegisterInContainer and Entity will have errors in different assembly HOT 2
- NO SCHEMA AVAILABLE HOT 1
- drop screaming caps from StringComparisonGraph
- nullable option to nav field
- Nullability Unknown for non-nullable context HOT 4
- Single will now throw a SingleEntityNotFoundException instead of an ExecutionError("Not found")
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql.entityframework.