How to do it...

These steps cover writing and running your application:

  1. From your terminal/console application, create and navigate to the chapter6/client directory.
  2. Copy tests from https://github.com/agtorre/go-cookbook/tree/master/chapter6/oauthstore or use this as an exercise to write some of your own code.
  3. Create a file called config.go with the following content:
        package oauthstore        import (            "context"            "net/http"            "golang.org/x/oauth2"        )        // Config wraps the default oauth2.Config        // and adds our storage        type Config struct {            *oauth2.Config            Storage        }        // Exchange stores a token after retrieval        func (c *Config) Exchange(ctx context.Context, code string)             (*oauth2.Token, error) {            token, err := c.Config.Exchange(ctx, code)            if err != nil {

Get Go Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.