ChilliCream / ChilliCream/graphql-platform

Authorize with one or another policies

Open
#7,168 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🌶️ hot chocolate Area: Authorization
Dominant language
C#
Stars
5.8k
Forks
810
Avg merge
15h 39m
Merged PRs (30d)
98

Description

Product

Hot Chocolate

Is your feature request related to a problem?

I have an API that i need to acces when the user has one or another Permission.

Iam adding a Claim called permissions to the token that is a list of strings.
This is the way iam handling the Authorization

var permissionsClaim = context.User.FindFirst(c => c.Type == "permissions")?.Value;

if (permissionsClaim == null)
{
    return Task.CompletedTask;
}

var permissions = !string.IsNullOrEmpty(permissionsClaim) ?
    JsonConvert.DeserializeObject<List<string>>(permissionsClaim) :
    new List<string>();

if (permissions.Contains(requirement.Permission) || permissions.Contains("SUPERADMIN"))
{
    context.Succeed(requirement);
}

return Task.CompletedTask;

This is my API

[Authorize(Policy = "BRANCH.GET")]
public async Task<List<BranchResponse>> GetBranch(CancellationToken cancellationToken)
{
    return await _mediator.Send(new GetBranchCommand(), cancellationToken);
}

I want to acces this endpoint if the user has as permission BRANCH.GET or BRANCH.CREATE, but i didnt found a way to do so.

The solution you'd like

The best solution would be something like this

[Authorize(Policy = "BRANCH.GET", BRANCH.CREATE)]
API 

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository files or tests are identified in the issue. Start by tracing how the shown C# Authorize policy is handled for Hot Chocolate endpoints, then determine how multiple policies should express OR semantics and verify access when either BRANCH.GET or BRANCH.CREATE is present.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, authorization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.