Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field authorization defined in the Input Type field #1723

Open
bkostrowiecki opened this issue Jul 17, 2024 · 1 comment
Open

Field authorization defined in the Input Type field #1723

bkostrowiecki opened this issue Jul 17, 2024 · 1 comment
Labels
Community 👨‍👧 Something initiated by a community Enhancement 🆕 New feature or request
Milestone

Comments

@bkostrowiecki
Copy link

Is your feature request related to a problem? Please describe.
I would like to have a per field authorization on inputs, so users with the specific role can update some fields, and other users with different role can't.

Describe the solution you'd like

The ideal solution would be to have a possibility to mark certain fields in Input Type to require the authorization.

@InputType()
class UpdateUserInput {
    @Field()
    @Authorized(['ADMIN', 'CUSTOMER'])
    fullName: string;

    @Field()
    @Authorized('ADMIN')
    email: string;
}

If the user has a role 'ADMIN' and he tries to fire update mutation using UpdateUserInput, specifing email field
then the authorization should pass an access to this update mutation.

If the user has a role 'CUSTOMER' and he tries to fire update mutation using UpdateUserInput, specifing email field
then the authorization should block the user from performing this operation.

Describe alternatives you've considered
I considered creating different mutation resolvers for different roles.
The disadvantages of this approach are:

  • significant amount of duplicated code
  • it's hard to automize it with crud generators
  • it looks like mixing methods to do one thing, since@Authorized decorator is available for fields in Object Types

Please let me know what you think.

@carlocorradini
Copy link
Contributor

Have you seen graphql-auth-directive (NOTE: I'm the author)?
It's exactly what you want (see type-graphql integration) 🥳
It's missing the integration with input types but we can work together to implement it 🤞👍

@MichalLytek MichalLytek added Enhancement 🆕 New feature or request Community 👨‍👧 Something initiated by a community labels Jul 19, 2024
@MichalLytek MichalLytek added this to the 3.0.0 release milestone Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community 👨‍👧 Something initiated by a community Enhancement 🆕 New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants