Code Monkey home page Code Monkey logo

Comments (4)

OpenSpacesAndPlaces avatar OpenSpacesAndPlaces commented on July 18, 2024

At least two ways I know of off the bat. (I'm sure there are more approaches)

You could do a soft filter with arguments:
https://graphql-dotnet.github.io/docs/getting-started/arguments

Or a hard filter by accessing meta-data from

ExecutionResult result = await _executer.ExecuteAsync(_ =>
{
...
_.UserContext = HttpContext.Current;
...
}
Resolve(ResolveFieldContext rfc)
{
....
rfc.UserContext.User.Identity.Name
//lookup role info
...
}

from authorization.

StefanSchoof avatar StefanSchoof commented on July 18, 2024

Thanks @OpenSpacesAndPlaces for your reply.
I was not able to figure out what do you mean by "soft filter". I am now going with the "hard filter".

from authorization.

OpenSpacesAndPlaces avatar OpenSpacesAndPlaces commented on July 18, 2024

By "soft filter" I meant something like your UI code sending " Top: 5 " as an argument.
I phrased this as "soft" because someone could just change the request to be "Top: 10".

The hard filter is running off information that's only server accessible.

from authorization.

StefanSchoof avatar StefanSchoof commented on July 18, 2024

Thank, I need a server enforced.

This is the code is use:

public DeviceType(IDocumentClient documentClient, IDataLoaderContextAccessor dataLoaderContextAccessor, IAuthorizationEvaluator evaluator)
{
...
            async Task<IEnumerable<Measurement>> measurementsResolve(ResolveFieldContext<Device> context)
            {
                var timespan = context.GetArgument("timespan", TimeSpan.FromDays(1));
                if (timespan > TimeSpan.FromDays(1))
                {
                    var user = context.UserContext as IProvideClaimsPrincipal;
                    var res = await evaluator.Evaluate(user.User, context.UserContext, null, new List<string> { "UserPolicy" });
                    if (!res.Succeeded)
                    {
                        context.Errors.AddRange(res.Errors.Select(e => new ExecutionError(e)));
                        return null;
                    }
                }
                var dataLoader = dataLoaderContextAccessor.Context
                    .GetOrAddCollectionBatchLoader("GetMeasurementsByDeviceId", GetMeasurementsByDeviceId(timespan));

                return await dataLoader.LoadAsync(context.Source.Id);
            }
            Field<ListGraphType<MeasurementType>>(
                "measurements",
                arguments: new QueryArguments(new QueryArgument<TimeSpanSecondsGraphType> { Name = "timespan" }),
                resolve: measurementsResolve
            );

from authorization.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.