For my most recent Elixir project I decided to use OAuth2Ex, which is an OAuth package.

Here’s how to create a custom storage module to save, load, and refresh tokens.

By default, OAuth2Ex has: the File Storage and Encrypted Storage modules. This is great when you can store files in the file system, unlike heroku, which is what I’m using as hosting. I wanted an easy way to store the token in my Repo without having to write a ton of extra code, since the system is in place for doing that for me.

For this project, I have a site-wide google account, which is stored in the Setting model. I created a custom Storage Module to save/load tokens from the Repo using a specific key, which you can configure.

Good luck with the Google API! If you have any questions, throw it in the comments section 🙂