{"action":"created","comment":{"url":"https://api.github.com/repos/freeCodeCamp/open-api/pulls/comments/183676914","pull_request_review_id":114717728,"id":183676914,"diff_hunk":"@@ -0,0 +1,73 @@\n+import fs from 'fs';\n+import path from 'path';\n+import { forEachField } from 'graphql-tools';\n+import { getArgumentValues } from 'graphql/execution/values';\n+import jwt from 'jsonwebtoken';\n+import debug from 'debug';\n+\n+import { AuthorizationError } from '../errors';\n+\n+const log = debug('fcc:resolvers:directives');\n+const certPath = process.cwd() + '/public.pem';\n+const cert = fs.readFileSync(certPath);\n+\n+function isAuth(ctx) {\n+  const token = ctx.headers.authorization;\n+  if (!token) {\n+    throw new AuthorizationError({\n+      message: 'You must supply a JSON Web Token for authorization!'\n+    });\n+  }\n+  try {\n+    return jwt.verify(token.replace('Bearer ', ''), cert);\n+  } catch (err) {\n+    return false;\n+  }\n+}\n+\n+const directiveResolvers = {\n+  isAuthenticatedOnField: (result, source, args, ctx) =>\n+    isAuth(ctx) ? result : null,\n+  isAuthenticatedOnQuery: (result, source, args, ctx) => {\n+    const hasAuth = isAuth(ctx);\n+    if (hasAuth) {\n+      return result;\n+    }\n+    throw new AuthorizationError({\n+      message: `You are not authorized. The required permission was not found.`\n+    });\n+  }\n+};\n+\n+// Credit: agonbina https://github.com/apollographql/graphql-tools/issues/212","path":"graphql/resolvers/directives.js","position":42,"original_position":42,"commit_id":"2483eeef52e9ca570c6d01b1c43bcba74ef0a28f","original_commit_id":"2483eeef52e9ca570c6d01b1c43bcba74ef0a28f","user":{"login":"Bouncey","id":18572518,"avatar_url":"https://avatars1.githubusercontent.com/u/18572518?v=4","gravatar_id":"","url":"https://api.github.com/users/Bouncey","html_url":"https://github.com/Bouncey","followers_url":"https://api.github.com/users/Bouncey/followers","following_url":"https://api.github.com/users/Bouncey/following{/other_user}","gists_url":"https://api.github.com/users/Bouncey/gists{/gist_id}","starred_url":"https://api.github.com/users/Bouncey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bouncey/subscriptions","organizations_url":"https://api.github.com/users/Bouncey/orgs","repos_url":"https://api.github.com/users/Bouncey/repos","events_url":"https://api.github.com/users/Bouncey/events{/privacy}","received_events_url":"https://api.github.com/users/Bouncey/received_events","type":"User","site_admin":false},"body":"I didn't even realise this was a thing inside `graphql-tools`, I will update the PR to let `graphql-tools` worry about the implementation","created_at":"2018-04-24T10:13:51Z","updated_at":"2018-04-24T10:13:51Z","html_url":"https://github.com/freeCodeCamp/open-api/pull/58#discussion_r183676914","pull_request_url":"https://api.github.com/repos/freeCodeCamp/open-api/pulls/58","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/freeCodeCamp/open-api/pulls/comments/183676914"},"html":{"href":"https://github.com/freeCodeCamp/open-api/pull/58#discussion_r183676914"},"pull_request":{"href":"https://api.github.com/repos/freeCodeCamp/open-api/pulls/58"}},"in_reply_to_id":183673097},"pull_request":{"url":"https://api.github.com/repos/freeCodeCamp/open-api/pulls/58","id":183570497,"html_url":"https://github.com/freeCodeCamp/open-api/pull/58","diff_url":"https://github.com/freeCodeCamp/open-api/pull/58.diff","patch_url":"https://github.com/freeCodeCamp/open-api/pull/58.patch","issue_url":"https://api.github.com/repos/freeCodeCamp/open-api/issues/58","number":58,"state":"open","locked":false,"title":"Add auth options :tada:","user":{"login":"Bouncey","id":18572518,"avatar_url":"https://avatars1.githubusercontent.com/u/18572518?v=4","gravatar_id":"","url":"https://api.github.com/users/Bouncey","html_url":"https://github.com/Bouncey","followers_url":"https://api.github.com/users/Bouncey/followers","following_url":"https://api.github.com/users/Bouncey/following{/other_user}","gists_url":"https://api.github.com/users/Bouncey/gists{/gist_id}","starred_url":"https://api.github.com/users/Bouncey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bouncey/subscriptions","organizations_url":"https://api.github.com/users/Bouncey/orgs","repos_url":"https://api.github.com/users/Bouncey/repos","events_url":"https://api.github.com/users/Bouncey/events{/privacy}","received_events_url":"https://api.github.com/users/Bouncey/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-04-23T22:05:52Z","updated_at":"2018-04-24T10:13:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5c30fbde5be528d6d2e63c7dab9c9c542ca8cbc1","assignee":null,"assignees":[],"requested_reviewers":[{"login":"raisedadead","id":1884376,"avatar_url":"https://avatars0.githubusercontent.com/u/1884376?v=4","gravatar_id":"","url":"https://api.github.com/users/raisedadead","html_url":"https://github.com/raisedadead","followers_url":"https://api.github.com/users/raisedadead/followers","following_url":"https://api.github.com/users/raisedadead/following{/other_user}","gists_url":"https://api.github.com/users/raisedadead/gists{/gist_id}","starred_url":"https://api.github.com/users/raisedadead/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raisedadead/subscriptions","organizations_url":"https://api.github.com/users/raisedadead/orgs","repos_url":"https://api.github.com/users/raisedadead/repos","events_url":"https://api.github.com/users/raisedadead/events{/privacy}","received_events_url":"https://api.github.com/users/raisedadead/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/freeCodeCamp/open-api/pulls/58/commits","review_comments_url":"https://api.github.com/repos/freeCodeCamp/open-api/pulls/58/comments","review_comment_url":"https://api.github.com/repos/freeCodeCamp/open-api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/freeCodeCamp/open-api/issues/58/comments","statuses_url":"https://api.github.com/repos/freeCodeCamp/open-api/statuses/2483eeef52e9ca570c6d01b1c43bcba74ef0a28f","head":{"label":"Bouncey:feat/auth","ref":"feat/auth","sha":"2483eeef52e9ca570c6d01b1c43bcba74ef0a28f","user":{"login":"Bouncey","id":18572518,"avatar_url":"https://avatars1.githubusercontent.com/u/18572518?v=4","gravatar_id":"","url":"https://api.github.com/users/Bouncey","html_url":"https://github.com/Bouncey","followers_url":"https://api.github.com/users/Bouncey/followers","following_url":"https://api.github.com/users/Bouncey/following{/other_user}","gists_url":"https://api.github.com/users/Bouncey/gists{/gist_id}","starred_url":"https://api.github.com/users/Bouncey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bouncey/subscriptions","organizations_url":"https://api.github.com/users/Bouncey/orgs","repos_url":"https://api.github.com/users/Bouncey/repos","events_url":"https://api.github.com/users/Bouncey/events{/privacy}","received_events_url":"https://api.github.com/users/Bouncey/received_events","type":"User","site_admin":false},"repo":{"id":130054263,"name":"open-api","full_name":"Bouncey/open-api","owner":{"login":"Bouncey","id":18572518,"avatar_url":"https://avatars1.githubusercontent.com/u/18572518?v=4","gravatar_id":"","url":"https://api.github.com/users/Bouncey","html_url":"https://github.com/Bouncey","followers_url":"https://api.github.com/users/Bouncey/followers","following_url":"https://api.github.com/users/Bouncey/following{/other_user}","gists_url":"https://api.github.com/users/Bouncey/gists{/gist_id}","starred_url":"https://api.github.com/users/Bouncey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bouncey/subscriptions","organizations_url":"https://api.github.com/users/Bouncey/orgs","repos_url":"https://api.github.com/users/Bouncey/repos","events_url":"https://api.github.com/users/Bouncey/events{/privacy}","received_events_url":"https://api.github.com/users/Bouncey/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Bouncey/open-api","description":"freeCodeCamp's open-api Intiative","fork":true,"url":"https://api.github.com/repos/Bouncey/open-api","forks_url":"https://api.github.com/repos/Bouncey/open-api/forks","keys_url":"https://api.github.com/repos/Bouncey/open-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Bouncey/open-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Bouncey/open-api/teams","hooks_url":"https://api.github.com/repos/Bouncey/open-api/hooks","issue_events_url":"https://api.github.com/repos/Bouncey/open-api/issues/events{/number}","events_url":"https://api.github.com/repos/Bouncey/open-api/events","assignees_url":"https://api.github.com/repos/Bouncey/open-api/assignees{/user}","branches_url":"https://api.github.com/repos/Bouncey/open-api/branches{/branch}","tags_url":"https://api.github.com/repos/Bouncey/open-api/tags","blobs_url":"https://api.github.com/repos/Bouncey/open-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Bouncey/open-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Bouncey/open-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/Bouncey/open-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Bouncey/open-api/statuses/{sha}","languages_url":"https://api.github.com/repos/Bouncey/open-api/languages","stargazers_url":"https://api.github.com/repos/Bouncey/open-api/stargazers","contributors_url":"https://api.github.com/repos/Bouncey/open-api/contributors","subscribers_url":"https://api.github.com/repos/Bouncey/open-api/subscribers","subscription_url":"https://api.github.com/repos/Bouncey/open-api/subscription","commits_url":"https://api.github.com/repos/Bouncey/open-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/Bouncey/open-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/Bouncey/open-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/Bouncey/open-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/Bouncey/open-api/contents/{+path}","compare_url":"https://api.github.com/repos/Bouncey/open-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Bouncey/open-api/merges","archive_url":"https://api.github.com/repos/Bouncey/open-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Bouncey/open-api/downloads","issues_url":"https://api.github.com/repos/Bouncey/open-api/issues{/number}","pulls_url":"https://api.github.com/repos/Bouncey/open-api/pulls{/number}","milestones_url":"https://api.github.com/repos/Bouncey/open-api/milestones{/number}","notifications_url":"https://api.github.com/repos/Bouncey/open-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Bouncey/open-api/labels{/name}","releases_url":"https://api.github.com/repos/Bouncey/open-api/releases{/id}","deployments_url":"https://api.github.com/repos/Bouncey/open-api/deployments","created_at":"2018-04-18T11:49:22Z","updated_at":"2018-04-21T13:13:05Z","pushed_at":"2018-04-24T09:48:03Z","git_url":"git://github.com/Bouncey/open-api.git","ssh_url":"git@github.com:Bouncey/open-api.git","clone_url":"https://github.com/Bouncey/open-api.git","svn_url":"https://github.com/Bouncey/open-api","homepage":"","size":308,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"staging"}},"base":{"label":"freeCodeCamp:staging","ref":"staging","sha":"2b950200ae7631548359c6adccc40cc7415e79db","user":{"login":"freeCodeCamp","id":9892522,"avatar_url":"https://avatars0.githubusercontent.com/u/9892522?v=4","gravatar_id":"","url":"https://api.github.com/users/freeCodeCamp","html_url":"https://github.com/freeCodeCamp","followers_url":"https://api.github.com/users/freeCodeCamp/followers","following_url":"https://api.github.com/users/freeCodeCamp/following{/other_user}","gists_url":"https://api.github.com/users/freeCodeCamp/gists{/gist_id}","starred_url":"https://api.github.com/users/freeCodeCamp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freeCodeCamp/subscriptions","organizations_url":"https://api.github.com/users/freeCodeCamp/orgs","repos_url":"https://api.github.com/users/freeCodeCamp/repos","events_url":"https://api.github.com/users/freeCodeCamp/events{/privacy}","received_events_url":"https://api.github.com/users/freeCodeCamp/received_events","type":"Organization","site_admin":false},"repo":{"id":55006901,"name":"open-api","full_name":"freeCodeCamp/open-api","owner":{"login":"freeCodeCamp","id":9892522,"avatar_url":"https://avatars0.githubusercontent.com/u/9892522?v=4","gravatar_id":"","url":"https://api.github.com/users/freeCodeCamp","html_url":"https://github.com/freeCodeCamp","followers_url":"https://api.github.com/users/freeCodeCamp/followers","following_url":"https://api.github.com/users/freeCodeCamp/following{/other_user}","gists_url":"https://api.github.com/users/freeCodeCamp/gists{/gist_id}","starred_url":"https://api.github.com/users/freeCodeCamp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freeCodeCamp/subscriptions","organizations_url":"https://api.github.com/users/freeCodeCamp/orgs","repos_url":"https://api.github.com/users/freeCodeCamp/repos","events_url":"https://api.github.com/users/freeCodeCamp/events{/privacy}","received_events_url":"https://api.github.com/users/freeCodeCamp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/freeCodeCamp/open-api","description":"freeCodeCamp's open-api Intiative","fork":false,"url":"https://api.github.com/repos/freeCodeCamp/open-api","forks_url":"https://api.github.com/repos/freeCodeCamp/open-api/forks","keys_url":"https://api.github.com/repos/freeCodeCamp/open-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/freeCodeCamp/open-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/freeCodeCamp/open-api/teams","hooks_url":"https://api.github.com/repos/freeCodeCamp/open-api/hooks","issue_events_url":"https://api.github.com/repos/freeCodeCamp/open-api/issues/events{/number}","events_url":"https://api.github.com/repos/freeCodeCamp/open-api/events","assignees_url":"https://api.github.com/repos/freeCodeCamp/open-api/assignees{/user}","branches_url":"https://api.github.com/repos/freeCodeCamp/open-api/branches{/branch}","tags_url":"https://api.github.com/repos/freeCodeCamp/open-api/tags","blobs_url":"https://api.github.com/repos/freeCodeCamp/open-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/freeCodeCamp/open-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/freeCodeCamp/open-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/freeCodeCamp/open-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/freeCodeCamp/open-api/statuses/{sha}","languages_url":"https://api.github.com/repos/freeCodeCamp/open-api/languages","stargazers_url":"https://api.github.com/repos/freeCodeCamp/open-api/stargazers","contributors_url":"https://api.github.com/repos/freeCodeCamp/open-api/contributors","subscribers_url":"https://api.github.com/repos/freeCodeCamp/open-api/subscribers","subscription_url":"https://api.github.com/repos/freeCodeCamp/open-api/subscription","commits_url":"https://api.github.com/repos/freeCodeCamp/open-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/freeCodeCamp/open-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/freeCodeCamp/open-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/freeCodeCamp/open-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/freeCodeCamp/open-api/contents/{+path}","compare_url":"https://api.github.com/repos/freeCodeCamp/open-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/freeCodeCamp/open-api/merges","archive_url":"https://api.github.com/repos/freeCodeCamp/open-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/freeCodeCamp/open-api/downloads","issues_url":"https://api.github.com/repos/freeCodeCamp/open-api/issues{/number}","pulls_url":"https://api.github.com/repos/freeCodeCamp/open-api/pulls{/number}","milestones_url":"https://api.github.com/repos/freeCodeCamp/open-api/milestones{/number}","notifications_url":"https://api.github.com/repos/freeCodeCamp/open-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/freeCodeCamp/open-api/labels{/name}","releases_url":"https://api.github.com/repos/freeCodeCamp/open-api/releases{/id}","deployments_url":"https://api.github.com/repos/freeCodeCamp/open-api/deployments","created_at":"2016-03-29T20:03:50Z","updated_at":"2018-04-24T10:03:50Z","pushed_at":"2018-04-24T10:03:48Z","git_url":"git://github.com/freeCodeCamp/open-api.git","ssh_url":"git@github.com:freeCodeCamp/open-api.git","clone_url":"https://github.com/freeCodeCamp/open-api.git","svn_url":"https://github.com/freeCodeCamp/open-api","homepage":"","size":205,"stargazers_count":26,"watchers_count":26,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":10,"mirror_url":null,"archived":false,"open_issues_count":14,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause"},"forks":10,"open_issues":14,"watchers":26,"default_branch":"staging"}},"_links":{"self":{"href":"https://api.github.com/repos/freeCodeCamp/open-api/pulls/58"},"html":{"href":"https://github.com/freeCodeCamp/open-api/pull/58"},"issue":{"href":"https://api.github.com/repos/freeCodeCamp/open-api/issues/58"},"comments":{"href":"https://api.github.com/repos/freeCodeCamp/open-api/issues/58/comments"},"review_comments":{"href":"https://api.github.com/repos/freeCodeCamp/open-api/pulls/58/comments"},"review_comment":{"href":"https://api.github.com/repos/freeCodeCamp/open-api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/freeCodeCamp/open-api/pulls/58/commits"},"statuses":{"href":"https://api.github.com/repos/freeCodeCamp/open-api/statuses/2483eeef52e9ca570c6d01b1c43bcba74ef0a28f"}},"author_association":"OWNER"}}
{"actor":{"display_login":"Bouncey"}}