OAuth2 is a relatively common protocol for speaking with APIs. The golang.org/x/oauth2 package provides a pretty flexible client for working with OAuth2. It has subpackages that specify endpoints for various providers such as Facebook, Google, and GitHub.
This recipe will demonstrate how to create a new GitHub OAuth2 client and some of its basic usages.
Getting ready
After completing the initial setup steps mentioned in the Technical requirements section at the beginning of this chapter, proceed with the following steps:
- Configure an OAuth Client at https://github.com/settings/applications/new.
- Set the environment variables with your client ID and secret:
- export GITHUB_CLIENT="your_client"
- export GITHUB_SECRET="your_secret"
- Brush up on the GitHub API documentation at https://developer.github.com/v3/.
How to do it...
These steps cover writing and...