Implementing an OAuth2 token storage interface
In the previous recipe, we retrieved a token for our client and performed API requests. The downside of this approach is that we have no long-term storage for our token. In an HTTP server, for example, we'd like to have consistent storage of the token between requests.
This recipe will explore modifying the OAuth2 client to store a token between requests and retrieve them at will using a key. For the sake of simplicity, this key will be a file, but it could also be a database, Redis, and so on.
Getting ready
Refer to the Getting ready section of the Making use of OAuth2 clients recipe.
How to do it...
These steps cover writing and running your application:
- From your terminal/console application, create and navigate to the
chapter6/client
directory. - 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.
- Create a file called
config.go
with the following content...