-
-
Notifications
You must be signed in to change notification settings - Fork 744
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added allowAnnonymous directive (#6134)
- Loading branch information
1 parent
21e0228
commit ff14574
Showing
20 changed files
with
204 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/HotChocolate/Core/src/Authorization/AllowAnonymousAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Reflection; | ||
using HotChocolate.Types; | ||
using HotChocolate.Types.Descriptors; | ||
|
||
namespace HotChocolate.Authorization; | ||
|
||
/// <summary> | ||
/// Allows anonymous access to the annotated field. | ||
/// </summary> | ||
public sealed class AllowAnonymousAttribute : ObjectFieldDescriptorAttribute | ||
{ | ||
protected override void OnConfigure( | ||
IDescriptorContext context, | ||
IObjectFieldDescriptor descriptor, | ||
MemberInfo member) | ||
=> descriptor.AllowAnonymous(); | ||
} |
46 changes: 46 additions & 0 deletions
46
src/HotChocolate/Core/src/Authorization/AllowAnonymousDirectiveType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Collections.Generic; | ||
using HotChocolate.Language; | ||
using HotChocolate.Types; | ||
using HotChocolate.Types.Descriptors; | ||
using HotChocolate.Types.Descriptors.Definitions; | ||
using DirectiveLocation = HotChocolate.Types.DirectiveLocation; | ||
|
||
namespace HotChocolate.Authorization; | ||
|
||
internal sealed class AllowAnonymousDirectiveType | ||
: DirectiveType | ||
, ISchemaDirective | ||
{ | ||
public AllowAnonymousDirectiveType() | ||
{ | ||
Name = Names.AllowAnonymous; | ||
} | ||
|
||
protected override void Configure(IDirectiveTypeDescriptor descriptor) | ||
{ | ||
descriptor | ||
.Name(Names.AllowAnonymous) | ||
.Location(DirectiveLocation.FieldDefinition) | ||
.Repeatable() | ||
.Internal(); | ||
} | ||
|
||
public void ApplyConfiguration( | ||
IDescriptorContext context, | ||
DirectiveNode directiveNode, | ||
IDefinition definition, | ||
Stack<IDefinition> path) | ||
{ | ||
((IHasDirectiveDefinition)definition).Directives.Add(new(directiveNode)); | ||
|
||
if (definition is ObjectFieldDefinition fieldDef) | ||
{ | ||
fieldDef.ContextData[WellKnownContextData.AllowAnonymous] = true; | ||
} | ||
} | ||
|
||
public static class Names | ||
{ | ||
public const string AllowAnonymous = "allowAnonymous"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters