Giter Site home page Giter Site logo

littlesmilelove / graphql-authorization-aspnetcore Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 0.0 21 KB

A toolset for Asp.net core authorizing integrate to graph types for GraphQL .NET

License: MIT License

C# 100.00%
asp-net-core authorization graphql

graphql-authorization-aspnetcore's People

Contributors

littlesmilelove avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

graphql-authorization-aspnetcore's Issues

InvalidOperationException: Cannot consume scoped service 'Microsoft.AspNetCore.Identity.UserManager'

I tried using your library together with GraphQL.Server.Transports.AspNetCore.
When accessing the GrapQL endpoint, I get InvalidOperationException: Cannot consume scoped service 'Microsoft.AspNetCore.Identity.UserManager`1[CUSTOM_USER_CLASS]' from singleton 'GraphQL.Authorization.AspNetCore.IAuthorizationEvaluator'.

Startup.cs (ConfigureServices):

services.AddGraphQLAuth();
services.AddScoped<IDependencyResolver>(s => new FuncDependencyResolver(s.GetRequiredService));
services.AddScoped<AppSchema>();
services.AddGraphQL(o => { o.ExposeExceptions = false; })
    .AddGraphTypes(ServiceLifetime.Scoped)
    .AddUserContextBuilder(context => new GraphQLUserContext { User = context.User } );

services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

Startup.cs (Configure):

app.UseGraphQL<AppSchema>();
app.UseGraphQLPlayground(options: new GraphQLPlaygroundOptions());

My policies are generated using an Excel sheet, so I don't think showing that code is necessary. The AuthorizationHandler i wrote for these policies is never triggered.

Creating a policy to use with Authorization

Hi, thanks for making this.

One thing left out of the documentation is how to create a policy.

           services.AddAuthorization(options =>
            {
                options.AddPolicy("AdminPolicy", policy =>
                    policy.RequireRole("Admin"));
            });

The above placed in Startup.cs ConfigureServices is an example of how to create one.

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.