Skip to content
Cyprien Autexier edited this page Sep 1, 2017 · 5 revisions

Welcome to the gl-dotnet-authorizations wiki!

Getting Started

First reference GeekLearning.Authorizations.AspNetCore package in your project.json file.

Then you need to register services provided by the library:

   services.Configure<ModelBuilderOptions>(Configuration.GetSection("AuthorizationsModelBuilderOptions"));
   services.AddAclAuthorizationHandlers();

Then you can start using it in your regular Authorization Policies:

            services.AddAuthorization(options =>
            {
                options.AddPolicy("myapp-backoffice-user", builder =>
                {
                    builder
                        .RequireAuthenticatedUser()
                        .RequireRightUnderScope(Domain.Security.RightNames.Write, Domain.Aggregates.MyApp.RootScopeName);
                });

                options.AddPolicy("myapp-backoffice-admin", builder =>
                {
                    builder
                        .RequireAuthenticatedUser()
                        .RequireRightOnScope(Domain.Security.RightNames.Administer, Domain.Aggregates.MyApp.RootScopeName);
                });

                options.AddPolicy("myapp-api-user", builder =>
                {
                    builder.AddAuthenticationSchemes("Bearer")
                           .RequireAuthenticatedUser()
                           .RequireRightUnderScope(Domain.Security.RightNames.Read, Domain.Aggregates.MyApp.RootScopeName);
                });
            });
Clone this wiki locally