The twitter-oauth app uses the mrjones/oauth library to demonstrate:
- How to do the oauth dance to authenticate your app to use a Twitter account.
- Fetching mentions for that Twitter account.
- Tweeting on behalf of that Twitter account.
Here are the contents of the app:
twitter-oauth/app/
models
user.go # User struct and in-memory data store
controllers
app.go # All code
OAuth Overview
The OAuth process is governed by this configuration:
var TWITTER = oauth.NewConsumer(
"VgRjky4dTA1U2Ck16MmZw",
"l8lOLyIF3peCFEvrEoTc8h4oFwieAFgPM6eeTRo30I",
oauth.ServiceProvider{
AuthorizeTokenUrl: "https://api.twitter.com/oauth/authorize",
RequestTokenUrl: "https://api.twitter.com/oauth/request_token",
AccessTokenUrl: "https://api.twitter.com/oauth/access_token",
},
)
Here’s an overview of the process:
- The app generates a “request token” and sends the user to Twitter.
- The user authorizes the app.
- Twitter redirects the user to the provided redirect url, including an “verifier” in the parameters.
- The app constructs a request to Twitter using the “request token” and the “verifier”, to which Twitter returns the “access token”.
- The app henceforth uses the access token to operate Twitter on the user’s behalf.