documentation/getting-started/rest/auth-tokens.mdx
In this section, we'll look at passing Authorization and Authentication information in our requests, by accessing the GitHub REST API.
Let's try making a GET request to the URL https://api.github.com/user.
You'll get the following response:
{
"message": "Requires authentication",
"documentation_url": "https://docs.github.com/rest/reference/users#get-the-authenticated-user"
}
This is because you are not authorized to access the API and to gain access you would need to authenticate yourself. We use tokens to authenticate a user and to do so we first need to generate an access token from GitHub.
To get access to the GitHub API, you first need to generate a personal access token. For our demonstration, we will generate one granting access to public repositories.
public_repo.<Tip>It is a recommended safe practice to have your auth details in environment variables rather than inputting them directly to the authorization tab.</Tip>
token and paste the token from GitHub as its value.Bearer from the dropdown list.<<token>>.You should now see the response including details about your GitHub account.