{"id":16296490,"url":"https://github.com/maticzav/graphql-server-github-auth-example","last_synced_at":"2026-01-28T17:38:14.045Z","repository":{"id":66336253,"uuid":"114807707","full_name":"maticzav/graphql-server-github-auth-example","owner":"maticzav","description":"GraphQL Server examples: Authentication","archived":false,"fork":false,"pushed_at":"2022-06-26T09:19:15.000Z","size":75,"stargazers_count":20,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-01T15:49:27.513Z","etag":null,"topics":["github-authentication","graphcool","graphql","graphql-server"],"latest_commit_sha":null,"homepage":"https://medium.com/@maticzavadlal/graphcool-1-0-example-series-authentication-282f274b8343","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maticzav.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-12-19T20:23:05.000Z","updated_at":"2023-01-03T17:32:06.000Z","dependencies_parsed_at":"2023-05-27T04:39:53.682Z","dependency_job_id":null,"html_url":"https://github.com/maticzav/graphql-server-github-auth-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/maticzav/graphql-server-github-auth-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maticzav%2Fgraphql-server-github-auth-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maticzav%2Fgraphql-server-github-auth-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maticzav%2Fgraphql-server-github-auth-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maticzav%2Fgraphql-server-github-auth-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maticzav","download_url":"https://codeload.github.com/maticzav/graphql-server-github-auth-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maticzav%2Fgraphql-server-github-auth-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28847951,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T15:15:36.453Z","status":"ssl_error","status_checked_at":"2026-01-28T15:15:13.020Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["github-authentication","graphcool","graphql","graphql-server"],"created_at":"2024-10-10T20:22:55.397Z","updated_at":"2026-01-28T17:38:14.018Z","avatar_url":"https://github.com/maticzav.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GraphQL Server - Github Auth\n\nThis example shows how to implement Github Authentication with GraphQL Server,\nusing `graphql-yoga` and other tools.\n\n## Getting started\n\n### Initializing the Prisma Database service\n\n```sh\nprisma deploy # copy simple API endpoint into the `PRISMA_ENPOINT` env var in .env\n```\n\n### Setting up the Github OAuth2\n\nYou need to configure these credentials from a new Github OAuth2 app as environment variables:\n\n* `GITHUB_CLIENT_ID`\n* `GITHUB_CLIENT_SECRET`\n\n1. Go to [github.com](github.com) and navigate to your profile. Click on your profile icon in the upper right corner and enter `Settings`.\n2. In the lower left side find _Developer Settings_ and navigate to _OAuth Apps_.\n3. Click `New OAuth App` and give your app a nice name. For the purposes of the example, it is best to set the _Homepage URL_ to `http://localhost:8000` and _Authorization callback URL_ to `http://localhost:8000/login`. (Application description is optional).\n4. Register the application.\n5. Copy _Client ID_ and _Client Secret_ to the __.env__ file.\n\n#### Testing with WEB\n\n* Replace `__CLIENT_ID__` in `login.html`\n* Serve `login.html`, for example by using `python -m SimpleHTTPServer`\n* Open `https://localhost:8000/login.html` in a browser, open the DevTools and authenticate with your Github account\n* Copy the code printed in the Console of your DevTools\n\n#### Testing with \"simple hack\"\n\nIn order to obtain `Github code` you can also use this little hack.\n\n1. Navigate to `https://github.com/login/oauth/authorize?client_id={GITHUB_CLIENT_ID}\u0026scope=user` and replace `{GITHUB_CLIENT_ID}` with your Github client ID.\n2. Authorise access to the account and you will be redirected to `localhost:8000/login.html?code={GITHUB_CODE}`.\n3. Copy the `{GITHUB_CODE}` part of `localhost:8000/login.html?code={GITHUB_CODE}` url to your GraphQL playground where you can test authentication.\n\n#### Queries and Mutations\n1. To authenticate the user use `Mutation authenticate`:\n```gql\nmutation LoginOrSignup {\n    authenticate(githubCode: \"mygithubcode\") {\n        token\n        user {\n            name\n            notes\n        }\n    }\n}\n```\nEvery time `authenticate` is called user info is loaded from Github server using provided code. If code is valid, user id is compared against existing users. If no user with such id exists, new one is created, otherwise the existsing one is returned.\n\n2. To get info about currently authenticated user use `Query me`:\n```gql\nquery Me {\n    me {\n        name\n        bio\n        public_repos\n        notes {\n            id\n            text\n        }\n    }\n}\n```\nServer will use the token, provided under `Authorization: Bearer \u003ctoken\u003e` http header, to identify userId and will search the database for an existsing user.\n\n3. To create a Note use `Mutation createNote`, this will create a note connected with your profile.\n```gql\nmutation NewNote {\n    createNote(text: \"Super cool text.\") {\n        id\n        text\n    }\n}\n\nquery MyProfile {\n    me {\n        id\n        notes { # \u003c- Note will appear here\n            id\n            text\n        }\n    }\n}\n```\n\n4. To read, delete or update Note you will have to be authenticated, otherwise __*NotAuthorized*__ Error will be returned.\n```gql\nquery MyNote($id: ID!) {\n    note(id: $id) { text }\n}\n```\n\n### Starting the Server\n\n```sh\nyarn install\nyarn start\n# Open http://localhost:5000/\n```\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaticzav%2Fgraphql-server-github-auth-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaticzav%2Fgraphql-server-github-auth-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaticzav%2Fgraphql-server-github-auth-example/lists"}