Authorizing with GraphQL
In order to work with the Github GraphQL Application Programming Interface (API), we'll need to create an Authentication Token. It's a secret that will give an application access to the Github GraphQL from within React.
Before you do this make sure you're logged in and that your email has been verified.
- Go to the top right of the page and click on your account's icon.
- Go to
Developer Settings
on the left menu - Click on
Personal Access Tokens
- Click on
Generate New Token
- Under Note add a label
- Check the appropriate permissions
The permissions will give the application that you're trying to run access to the repo and you can control how much access you give my modifying these permissions.
[x] repo
[ ] admin:org
[x] read:org
[ ] admin:repo_hook
[x] read:repo_hook
[x] user
[ ] admin:gpg_key
[x] read:pgp_key
Once you do that, you'll see a personal access token. You can click on the icon to copy this to the clipboard. As it says, this is the only time you'll see this token so make sure you save it in a safe place.
Building a database entry file db.js
const github = {
baseURL: "https://api.github.com/graphql",
username: "USERNAME",
headers: {
"Content-Type": "application/json",
Authorization: "bearer ACCESS_TOKEN",
}
}
export default github
Because we added this file to our .gitignore document, this file will not be in the repository for this course. You'll have to create it locally on your own computer.