Skip to content

Commit

Permalink
Authorization Refinements (#814)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Jun 3, 2019
1 parent 1c4548a commit e36ec3b
Show file tree
Hide file tree
Showing 12 changed files with 361 additions and 56 deletions.
9 changes: 1 addition & 8 deletions src/Server/AspNetCore.Authorization/AuthorizeDirective.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,8 @@ public AuthorizeDirective(
string policy,
IReadOnlyCollection<string> roles)
{
if (string.IsNullOrEmpty(policy)
&& (roles == null || roles.Count == 0))
{
throw new ArgumentException(
"Either policy or roles has to be set.");
}

Policy = policy;
Roles = (IReadOnlyCollection<string>)roles ?? Array.Empty<string>();
Roles = roles ?? Array.Empty<string>();
}

public AuthorizeDirective(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace HotChocolate.Types
{
public static class ObjectFieldDescriptorExtensions
public static class AuthorizeObjectFieldDescriptorExtensions
{
public static IObjectFieldDescriptor Authorize(
this IObjectFieldDescriptor self,
Expand All @@ -23,6 +23,17 @@ public static IObjectFieldDescriptor Authorize(
}

#if !ASPNETCLASSIC
public static IObjectFieldDescriptor Authorize(
this IObjectFieldDescriptor self)
{
if (self == null)
{
throw new ArgumentNullException(nameof(self));
}

return self.Directive(new AuthorizeDirective());
}

public static IObjectFieldDescriptor Authorize(
this IObjectFieldDescriptor self,
string policy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace HotChocolate.Types
{
public static class ObjectTypeDescriptorExtensions
public static class AuthorizeObjectTypeDescriptorExtensions
{
public static IObjectTypeDescriptor Authorize(
this IObjectTypeDescriptor self,
Expand All @@ -23,6 +23,17 @@ public static IObjectTypeDescriptor Authorize(
}

#if !ASPNETCLASSIC
public static IObjectTypeDescriptor Authorize(
this IObjectTypeDescriptor self)
{
if (self == null)
{
throw new ArgumentNullException(nameof(self));
}

return self.Directive(new AuthorizeDirective());
}

public static IObjectTypeDescriptor Authorize(
this IObjectTypeDescriptor self,
string policy)
Expand Down
Loading

0 comments on commit e36ec3b

Please sign in to comment.