{"id":15192438,"url":"https://github.com/grand-stack/graphql-auth-directives","last_synced_at":"2025-10-02T07:30:43.935Z","repository":{"id":34076700,"uuid":"153198606","full_name":"grand-stack/graphql-auth-directives","owner":"grand-stack","description":"Add authorization to your GraphQL API using schema directives.","archived":true,"fork":false,"pushed_at":"2022-02-09T23:22:34.000Z","size":1484,"stargazers_count":113,"open_issues_count":21,"forks_count":27,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-03T08:13:22.713Z","etag":null,"topics":["authentication","authorization","graphql","graphql-api","graphql-directive","schema-directives"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/graphql-auth-directives","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/grand-stack.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-16T00:23:14.000Z","updated_at":"2024-08-14T07:00:06.000Z","dependencies_parsed_at":"2022-08-08T00:00:41.898Z","dependency_job_id":null,"html_url":"https://github.com/grand-stack/graphql-auth-directives","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/grand-stack/graphql-auth-directives","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grand-stack%2Fgraphql-auth-directives","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grand-stack%2Fgraphql-auth-directives/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grand-stack%2Fgraphql-auth-directives/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grand-stack%2Fgraphql-auth-directives/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grand-stack","download_url":"https://codeload.github.com/grand-stack/graphql-auth-directives/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grand-stack%2Fgraphql-auth-directives/sbom","scorecard":{"id":443469,"data":{"date":"2025-08-11","repo":{"name":"github.com/grand-stack/graphql-auth-directives","commit":"c1659a4949faf00b3afc0e29df2868e4382128d4"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2,"checks":[{"name":"Code-Review","score":2,"reason":"Found 5/20 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"project is archived","details":["Warn: Repository is archived."],"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":9,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Warn: project license file does not contain an FSF or OSI license."],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 15 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"58 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-qm7x-rc44-rrqw","Warn: Project is vulnerable to: GHSA-2p3c-p3qw-69r4","Warn: Project is vulnerable to: GHSA-j5g3-5c8r-7qfx","Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5","Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-wm7h-9275-46v2","Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc","Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3","Warn: Project is vulnerable to: MAL-2023-462","Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6","Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j","Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-8cf7-32gw-wr33","Warn: Project is vulnerable to: GHSA-hjrf-2m68-5959","Warn: Project is vulnerable to: GHSA-qwph-4952-7xr6","Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g","Warn: Project is vulnerable to: GHSA-px4h-xg32-q955","Warn: Project is vulnerable to: GHSA-v39p-96qg-c8rf","Warn: Project is vulnerable to: GHSA-8v63-cqqc-6r2c","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg","Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p","Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9","Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw","Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc","Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh","Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-38fc-wpqx-33j7","Warn: Project is vulnerable to: GHSA-332q-7ff2-57h2","Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T06:07:46.334Z","repository_id":34076700,"created_at":"2025-08-19T06:07:46.335Z","updated_at":"2025-08-19T06:07:46.335Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277974403,"owners_count":25908396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-02T02:00:08.890Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","authorization","graphql","graphql-api","graphql-directive","schema-directives"],"created_at":"2024-09-27T21:23:31.992Z","updated_at":"2025-10-02T07:30:43.676Z","avatar_url":"https://github.com/grand-stack.png","language":"JavaScript","readme":"# graphql-auth-directives\n\n[![CircleCI](https://circleci.com/gh/grand-stack/graphql-auth-directives.svg?style=svg)](https://circleci.com/gh/grand-stack/graphql-auth-directives)\n\nAdd authentication to your GraphQL API with schema directives.\n\n## Schema directives for authorization\n\n- [ ] `@isAuthenticated`\n- [ ] `@hasRole`\n- [ ] `@hasScope`\n\n## Quick start\n\n```sh\nnpm install --save graphql-auth-directives\n```\n\nThen import the schema directives you'd like to use and attach them during your GraphQL schema construction. For example using [neo4j-graphql.js' `makeAugmentedSchema`](https://grandstack.io/docs/neo4j-graphql-js-api.html#makeaugmentedschemaoptions-graphqlschema):\n\n\n```js\nimport { IsAuthenticatedDirective, HasRoleDirective, HasScopeDirective } from \"graphql-auth-directives\";\n\nconst augmentedSchema = makeAugmentedSchema({\n  typeDefs,\n  schemaDirectives: {\n    isAuthenticated: IsAuthenticatedDirective,\n    hasRole: HasRoleDirective,\n    hasScope: HasScopeDirective\n  }\n});\n```\n\nThe `@hasRole`, `@hasScope`, and `@isAuthenticated` directives will now be available for use in your GraphQL schema:\n\n```\ntype Query {\n    userById(userId: ID!): User @hasScope(scopes: [\"User:Read\"])\n    itemById(itemId: ID!): Item @hasScope(scopes: [\"Item:Read\"])\n}\n```\n\nBe sure to inject the request headers into the GraphQL resolver context. For example, with Apollo Server:\n\n```js\nconst server = new ApolloServer({\n  schema,\n  context: ({ req }) =\u003e {\n    return req;\n  }\n});\n```\n\nIn the case that the token was decoded with no errors the `context.user` will store the payload from the token\n\n```js\nme: (parent, args, context) =\u003e {\n      console.log(context.user.id);\n}\n```\n\nA JWT must then be included in each GraphQL request in the Authorization header. For example, with Apollo Client:\n\n```js\nimport { createHttpLink } from 'apollo-link-http';\nimport { setContext } from 'apollo-link-context';\nimport { InMemoryCache } from 'apollo-cache-inmemory';\nimport { ApolloClient } from 'apollo-client';\n\n\nconst httpLink = createHttpLink({\n    uri: \u003cYOUR_GRAPHQL_API_URI\u003e\n});\n\nconst authLink = setContext((_, { headers }) =\u003e {\n    const token = localStorage.getItem('id_token'); // here we are storing the JWT in localStorage\n    return {\n        headers: {\n            ...headers,\n            authorization: token ? `Bearer ${token}` : \"\",\n        }\n    }\n});\n\nconst client = new ApolloClient({\n    link: authLink.concat(httpLink),\n    cache: new InMemoryCache()\n});\n```\n\n## Configure\n\nConfiguration is done via environment variables.\n\n(required)\nThere are two variables to control how tokens are processed.\nIf you would like the server to verify the tokens used in a request, you must provide the secret used to encode the token in the `JWT_SECRET` variable. Otherwise you will need to set `JWT_NO_VERIFY` to true.\n\n```sh\nexport JWT_NO_VERIFY=true //Server does not have the secret, but will need to decode tokens\n```\nor\n```sh\nexport JWT_SECRET=\u003e\u003cYOUR_JWT_SECRET_KEY_HERE\u003e //Server has the secret and will verify authenticity\n```\n\n(optional)\nBy default `@hasRole` will validate the `roles`, `role`, `Roles`, or `Role` claim (whichever is found first). You can override this by setting `AUTH_DIRECTIVES_ROLE_KEY` environment variable. For example, if your role claim is stored in the JWT like this\n\n```sh\n\"https://grandstack.io/roles\": [\n    \"admin\"\n]\n```\n\nSet:\n\n```sh\nexport AUTH_DIRECTIVES_ROLE_KEY=https://grandstack.io/roles\n```\n\n## Running Tests Locally\n\n1. create ./test/helpers/.env\n2. add relevant values\n3. run the test server\n```sh\nnpx babel-node test/helpers/test-setup.js\n```\n4. run the tests\n```sh\nnpx ava test/*.js\n```\n\n\n## Test JWTs\n\nScopes: user:CRUD\n\n~~~\nkey: qwertyuiopasdfghjklzxcvbnm123456\n~~~\n\n~~~\neyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJHUkFORHN0YWNrIiwiaWF0IjoxNTQ5MTQ1Mjk0LCJleHAiOjE2OTE3ODEzMDcsImF1ZCI6ImdyYW5kc3RhY2suaW8iLCJzdWIiOiJib2JAbG9ibGF3LmNvbSIsIlJvbGUiOiJBRE1JTiIsIlNjb3BlIjpbIlVzZXI6UmVhZCIsIlVzZXI6Q3JlYXRlIiwiVXNlcjpVcGRhdGUiLCJVc2VyOkRlbGV0ZSJdfQ.WJffOec05r8KuzW76asax1iCzv5q4rwRv9kvFyw7c_E\n~~~\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrand-stack%2Fgraphql-auth-directives","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrand-stack%2Fgraphql-auth-directives","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrand-stack%2Fgraphql-auth-directives/lists"}