Fellow Stranger Fellow Stranger -5 years ago 193
Ruby Question

Use Google::Auth::Stores::FileTokenStore with database

I'm trying to implement a 3 legged authentication in my app to the Google API, to be able to access registered users' Google Calendars.

In the quickstart Ruby guide, this command comes up that as far as I understand should point to the user's tokens:

token_store = Google::Auth::Stores::FileTokenStore.new(file: CREDENTIALS_PATH)

It expects the tokens stored in a file (or Redis), but (of course) I store each user's tokens in my database (Postgres).

Have I understand the purpose of the command wrongly or otherwise - how do I use it with a database store?

Official documentation

Answer Source

Implement it yourself, according to the the readme:

Custom storage implementations can also be used. See token_store.rb for additional details.

It shouldn't be too hard to implement the load(id), store(id, token) and delete(id) with ActiveRecord (or another ORM) by the looks of the mentioned files.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download