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.

Browse Source

Here are the contents of the app:

		user.go   # User struct and in-memory data store
		app.go    # All code

OAuth Overview

The OAuth process is governed by this configuration:

var TWITTER = oauth.NewConsumer(
		AuthorizeTokenUrl: "",
		RequestTokenUrl:   "",
		AccessTokenUrl:    "",

Here’s an overview of the process:

  1. The app generates a “request token” and sends the user to Twitter.
  2. The user authorizes the app.
  3. Twitter redirects the user to the provided redirect url, including an “verifier” in the parameters.
  4. The app constructs a request to Twitter using the “request token” and the “verifier”, to which Twitter returns the “access token”.
  5. The app henceforth uses the access token to operate Twitter on the user’s behalf.