Search code examples
node.jsgoogle-apigoogle-contacts-apihapi.js

Consume google contacts api using hapi.js and bell login with offline access


I'm working on a project to connect Google Apps (Contacts, Gmail, etc.) to our own private software.

I'd like to use Hapi.js in order to achieve this, but since I have no expertise in the matter (OAuth, Google, etc) I found it to be quite challenging.

I wonder if it's posible to use Hapijs and Bell to handle the "ask permission" flow, and once authorized save the credentials to long-term uses.

Also, is it possible to use Bell to handle token refresh and consume api? (like requesting http://www.google.com/m8/feeds/contacts/default/full)


Solution

  • In the documentation for Bell, there's an example for twitter, basically you need to change the provider to Google: https://www.npmjs.com/package/bell

    When you request access, you can add the parameter access_type with a value of offline. The server will response also with a refresh token that you can use in further requests to the API's without asking for the user credentials again.

    You won't be able to store the actual user's credentials since it wouldn't be secure.

    You can use the Google OAuth playground to learn more about the authentication process, here is the link https://developers.google.com/oauthplayground/

    Here you can find more information and examples of using node.js and the Google API's