diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6c10299..efa6758 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,8 +30,7 @@ jobs: - ubuntu-latest - windows-latest graphqlversion: - - 4.2.0 - - 4.4.0 + - 4.6.1 steps: - name: Checkout source uses: actions/checkout@v2 diff --git a/src/GraphQL.Authorization.ApiTests/GraphQL.Authorization.approved.txt b/src/GraphQL.Authorization.ApiTests/GraphQL.Authorization.approved.txt index 8839758..63ab415 100644 --- a/src/GraphQL.Authorization.ApiTests/GraphQL.Authorization.approved.txt +++ b/src/GraphQL.Authorization.ApiTests/GraphQL.Authorization.approved.txt @@ -68,6 +68,11 @@ namespace GraphQL.Authorization public System.Collections.Generic.IEnumerable DisplayValues { get; } public System.Threading.Tasks.Task Authorize(GraphQL.Authorization.AuthorizationContext context) { } } + public static class GraphQLBuilderExtensions + { + public static void AddAuthorization(this GraphQL.DI.IGraphQLBuilder builder, System.Action configure) { } + public static void AddAuthorization(this GraphQL.DI.IGraphQLBuilder builder, System.Action configure) { } + } public interface IAuthorizationEvaluator { System.Threading.Tasks.Task Evaluate(System.Security.Claims.ClaimsPrincipal principal, System.Collections.Generic.IDictionary userContext, System.Collections.Generic.IReadOnlyDictionary inputs, System.Collections.Generic.IEnumerable requiredPolicies); diff --git a/src/GraphQL.Authorization.Tests/GraphQL.Authorization.Tests.csproj b/src/GraphQL.Authorization.Tests/GraphQL.Authorization.Tests.csproj index f7a6c63..6908334 100644 --- a/src/GraphQL.Authorization.Tests/GraphQL.Authorization.Tests.csproj +++ b/src/GraphQL.Authorization.Tests/GraphQL.Authorization.Tests.csproj @@ -3,7 +3,7 @@ net5;netcoreapp3.1 - 4.2.0 + 4.6.0 diff --git a/src/GraphQL.Authorization/GraphQL.Authorization.csproj b/src/GraphQL.Authorization/GraphQL.Authorization.csproj index ccd33b9..e51703b 100644 --- a/src/GraphQL.Authorization/GraphQL.Authorization.csproj +++ b/src/GraphQL.Authorization/GraphQL.Authorization.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/GraphQL.Authorization/GraphQLBuilderExtensions.cs b/src/GraphQL.Authorization/GraphQLBuilderExtensions.cs new file mode 100644 index 0000000..fb75850 --- /dev/null +++ b/src/GraphQL.Authorization/GraphQLBuilderExtensions.cs @@ -0,0 +1,30 @@ +using System; +using GraphQL.DI; + +namespace GraphQL.Authorization +{ + /// + public static class GraphQLBuilderExtensions + { + /// + /// Registers and within the + /// dependency injection framework and configures the validation rule to be added to the list of validation rules + /// within and + /// upon document execution. Configures authorization settings with the specified configuration delegate. + /// + public static void AddAuthorization(this IGraphQLBuilder builder, Action configure) + { + builder.TryRegister(ServiceLifetime.Singleton); + builder.AddValidationRule(true); + builder.Configure(configure); + } + + /// + public static void AddAuthorization(this IGraphQLBuilder builder, Action configure) + { + builder.TryRegister(ServiceLifetime.Singleton); + builder.AddValidationRule(true); + builder.Configure(configure); + } + } +} diff --git a/src/Harness/GraphQLAuthExtensions.cs b/src/Harness/GraphQLAuthExtensions.cs index 1e353b7..e844d88 100644 --- a/src/Harness/GraphQLAuthExtensions.cs +++ b/src/Harness/GraphQLAuthExtensions.cs @@ -9,7 +9,7 @@ namespace Harness /// /// Extension methods to add GraphQL authorization into DI container. /// - public static class GraphQLAuthExtensions + public static class GraphQLAuthExtensions // TODO: remove soon { /// /// Adds all necessary classes into provided diff --git a/src/Harness/Startup.cs b/src/Harness/Startup.cs index e03465e..6520869 100644 --- a/src/Harness/Startup.cs +++ b/src/Harness/Startup.cs @@ -39,6 +39,7 @@ type Query { return schema; }); + // TODO: change to IGraphQLBuilder // extension method defined in this project services.AddGraphQLAuth((settings, provider) => settings.AddPolicy("AdminPolicy", p => p.RequireClaim("role", "Admin")));