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

Add support for the @auth directive #188

Open
Andy2003 opened this issue Mar 8, 2021 · 0 comments
Open

Add support for the @auth directive #188

Andy2003 opened this issue Mar 8, 2021 · 0 comments
Labels
API-Alignment Align the API with the one defined by @neo4j/graphql

Comments

@Andy2003
Copy link
Collaborator

Andy2003 commented Mar 8, 2021

Add support for an @auth directive to fine tune access control to the schema.

The directive should look like:

# You can put the `@auth` directive also on a field with the `@cypher` directive.
# Functionality like allow and bind will not work but you can still utilize `isAuthenticated` and `roles`.
# Notice you don't need to specify operations for `@auth` directives on `@cypher` fields.
directive @auth(
  # You can have many rules for many operations.
  # We fallthrough each rule, on the corresponding operation, until a match.
  # On no match, an error is thrown. You can think of rules as a big OR.
  rules: [AuthRule!]!
) on FIELD_DEFINITION|OBJECT

input AuthRule{
  # Operations is an array, you can re-use the same rule for many operations.
  operations: [AuthOperations!]
  # This is the most basic of auth. Used to ensure that there is a valid decoded JWT in the request
  isAuthenticated: Boolean
  # Use the roles property to specify the allowed roles for an operation.
  roles: [String!]

  # Use allow to ensure, on matched nodes, a connection exists between a value on the JWT vs a property on each matched node.
  # Allow is used on the following operations:
  #  * read
  #  * update
  #  * connect
  #  * disconnect
  #  * delete
  # When you specify allow on a relationship you can select fields on the referenced node.
  # It's worth pointing out that allow on a relationship will perform an `ANY` on the matched nodes: to see if there is a match.
  # Allow works the same as it does on Type Definitions although its context is the Field.
  # So instead of enforcing auth rules when the node is matched and or upserted, it would instead be called when the Field is selected or upserted.
  allow: Object
  # Use bind to ensure, on creating or updating nodes, a connection exists between a value on the JWT vs a property on a matched node.
  # This validation is done after the operation but inside a transaction.
  # Bind is used on the following operations:
  #  * read
  #  * update
  #  * connect
  #  * disconnect
  #  * delete
  # There may be a reason where you need to traverse across relationships to satisfy your Auth implementation.
  # One example of this could be "Ensure that users only create Posts related to themselves"
  # When you specify `bind` on a relationship you can select fields on the referenced node.
  # It's worth pointing out that allow on a relationship will perform an `ALL` on the matched nodes; to see if there is a match.
  # This means you can only use `bind` to enforce a single relationship to a single node.
  # You can use bind on a field. The root is still considered the node.
  bind: Object
  OR: [AuthRule!]
  AND: [AuthRule!]
}

enum AuthOperations {
  # MATCH
  read
  # CREATE
  create
  # SET
  update
  # DELETE
  delete
  # MATCH & MERGE
  connect
  # MATCH & DELETE
  disconnect
  # permit for all operations
  all
}

scalar Object

Currently this directive cannot be handled by the graphql library used in this project due to following issues:

graphql-java/graphql-java#2238

graphql-java/graphql-java#2239

so before working on this issue we should wait for the related issues to be fixed.

@Andy2003 Andy2003 added the API-Alignment Align the API with the one defined by @neo4j/graphql label Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API-Alignment Align the API with the one defined by @neo4j/graphql
Projects
None yet
Development

No branches or pull requests

1 participant