Storing tokens
For a repeat request, we can avoid having the user go through a permission workflow again by reusing the token we've been issued. The token that's returned by conf.Exchange() can be persisted and used in subsequent requests. This token contains a reference to refresh the token, which means that, even if the token has expired, the application can probably request a new token automatically.
To store and retrieve the token, we shall use a JSON serialization that's already set up on the oauth2.Token type. When the token is originally issued, we'll save it to a file (this could be a database or any other persistence your application has access to). As the client object we're using to issue Get() requests is shared; we don't need ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access