The ideal workflow
When designing your application, you will want to utilize all of the tools and workflows at your disposal to achieve a user experience that is as seamless as possible. Now, given all of the information we have presented in this book thus far, we can create an optimal behavior workflow that our application can follow that makes the best use of the available workflows to minimize any user interactions that the user will have to do before your application can make API calls:
In the preceding flow diagram, we start with an access token. We continue to make API calls while the token is valid. Once the token becomes invalid (either because the API calls return with an invalid_token
error, or we calculated the time of expiry in anticipation of its invalidation), we must fetch a new access token. If we have a refresh token, we can use that. If that refresh request fails because the refresh token has itself expired, or if we don't have a refresh token at all, then we must resort...