Skip to content

Commit

Permalink
Authorization Refinements (ChilliCream#6107)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored and martindisch committed May 5, 2023
1 parent c2328c3 commit 87bb76e
Show file tree
Hide file tree
Showing 48 changed files with 518 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ schema {
}

type Query {
foo: String @authorize(apply: BEFORE_RESOLVER)
foo: String @authorize
}

enum ApplyPolicy {
Expand All @@ -12,4 +12,4 @@ enum ApplyPolicy {
VALIDATION
}

directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = VALIDATION) repeatable on OBJECT | FIELD_DEFINITION
directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = BEFORE_RESOLVER) repeatable on OBJECT | FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ enum ApplyPolicy {
VALIDATION
}

directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = VALIDATION) repeatable on OBJECT | FIELD_DEFINITION
directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = BEFORE_RESOLVER) repeatable on OBJECT | FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ schema {
}

type Query {
foo: String @authorize(apply: BEFORE_RESOLVER)
foo: String @authorize
}

enum ApplyPolicy {
Expand All @@ -12,4 +12,4 @@ enum ApplyPolicy {
VALIDATION
}

directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = VALIDATION) repeatable on OBJECT | FIELD_DEFINITION
directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = BEFORE_RESOLVER) repeatable on OBJECT | FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ schema {
}

type Query {
foo: String @authorize
foo: String @authorize(apply: VALIDATION)
}

enum ApplyPolicy {
Expand All @@ -12,4 +12,4 @@ enum ApplyPolicy {
VALIDATION
}

directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = VALIDATION) repeatable on OBJECT | FIELD_DEFINITION
directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = BEFORE_RESOLVER) repeatable on OBJECT | FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ schema {
}

type Query {
foo: String @authorize(policy: "MyPolicy", apply: BEFORE_RESOLVER)
foo: String @authorize(policy: "MyPolicy")
}

enum ApplyPolicy {
Expand All @@ -12,4 +12,4 @@ enum ApplyPolicy {
VALIDATION
}

directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = VALIDATION) repeatable on OBJECT | FIELD_DEFINITION
directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = BEFORE_RESOLVER) repeatable on OBJECT | FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ enum ApplyPolicy {
VALIDATION
}

directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = VALIDATION) repeatable on OBJECT | FIELD_DEFINITION
directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = BEFORE_RESOLVER) repeatable on OBJECT | FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ schema {
}

type Query {
foo: String @authorize(policy: "MyPolicy", apply: BEFORE_RESOLVER)
foo: String @authorize(policy: "MyPolicy")
}

enum ApplyPolicy {
Expand All @@ -12,4 +12,4 @@ enum ApplyPolicy {
VALIDATION
}

directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = VALIDATION) repeatable on OBJECT | FIELD_DEFINITION
directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = BEFORE_RESOLVER) repeatable on OBJECT | FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ schema {
}

type Query {
foo: String @authorize(policy: "MyPolicy")
foo: String @authorize(policy: "MyPolicy", apply: VALIDATION)
}

enum ApplyPolicy {
Expand All @@ -12,4 +12,4 @@ enum ApplyPolicy {
VALIDATION
}

directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = VALIDATION) repeatable on OBJECT | FIELD_DEFINITION
directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = BEFORE_RESOLVER) repeatable on OBJECT | FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ enum ApplyPolicy {
VALIDATION
}

directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = VALIDATION) repeatable on OBJECT | FIELD_DEFINITION
directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = BEFORE_RESOLVER) repeatable on OBJECT | FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ schema {
query: Query
}

type Query @authorize(apply: BEFORE_RESOLVER) {
type Query @authorize {
foo: String
}

Expand All @@ -12,4 +12,4 @@ enum ApplyPolicy {
VALIDATION
}

directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = VALIDATION) repeatable on OBJECT | FIELD_DEFINITION
directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = BEFORE_RESOLVER) repeatable on OBJECT | FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ schema {
query: Query
}

type Query @authorize(policy: "MyPolicy", apply: BEFORE_RESOLVER) {
type Query @authorize(policy: "MyPolicy") {
foo: String
}

Expand All @@ -12,4 +12,4 @@ enum ApplyPolicy {
VALIDATION
}

directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = VALIDATION) repeatable on OBJECT | FIELD_DEFINITION
directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = BEFORE_RESOLVER) repeatable on OBJECT | FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ enum ApplyPolicy {
VALIDATION
}

directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = VALIDATION) repeatable on OBJECT | FIELD_DEFINITION
directive @authorize("The name of the authorization policy that determines access to the annotated resource." policy: String "Roles that are allowed to access the annotated resource." roles: [String!] "Defines when when the authorize directive shall be applied.By default the authorize directives are applied during the validation phase." apply: ApplyPolicy! = BEFORE_RESOLVER) repeatable on OBJECT | FIELD_DEFINITION
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
{
"data": {
"bar": "bar"
}
"errors": [
{
"message": "The current user is not authorized to access this resource.",
"locations": [
{
"line": 1,
"column": 3
}
],
"path": [
"bar"
],
"extensions": {
"code": "AUTH_NOT_AUTHORIZED"
}
}
]
}
4 changes: 2 additions & 2 deletions src/HotChocolate/Core/src/Abstractions/WellKnownMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ public static class WellKnownMiddleware
public const string MutationErrorNull = "HotChocolate.Types.Mutations.Errors.Null";

/// <summary>
///The key identifies the mutation result middleware.
/// The key identifies the mutation result middleware.
/// </summary>
public const string MutationResult = "HotChocolate.Types.Mutations.Result";

/// <summary>
///The key identifies the authorization middleware.
/// The key identifies the authorization middleware.
/// </summary>
public const string Authorization = "HotChocolate.Authorization";
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ namespace HotChocolate.Authorization;
/// </summary>
public class AuthorizationOptions
{
/// <summary>
/// Gets or sets a delegate that can be used to prevent authorization
/// directives from being applied to the node field.
/// </summary>
public Func<AuthorizeDirective, bool> SkipNodeFields { get; set; } = _ => false;

/// <summary>
/// Gets or sets a hook that can be used to apply authorization
/// policies to the node and nodes field.
Expand Down
Loading

0 comments on commit 87bb76e

Please sign in to comment.