0

I have a rails app that has google Login. I am using a 'omniauth-google-oauth2' gem. After authorization from user, i am getting the credentials in the form of OmniAuth::AuthHash.

I am planning to use "google_contacts_api" to get the contacts for the user, This requires me to have a OAuth2::AccessToken to get contacts. And in order to create the same, i need OAuth2::Client to create the AccessToken. I was wondering

  1. How to create client using the OmniAuth Strategy and second
  2. Is there a better way to create OAuth2::AccessToken?

1 Answers1

0

1. How to create client using the OmniAuth Strategy?

Based from this documentation, you'll first need an API endpoint that will return the resource owner's credentials to create a strategy for your provider. You need to define the class and include the proper module. If you define your class in the OmniAuth::Strategies, namespace will allow it to be declared by symbolic name instead of class in an OmniAuth::Builder call.

require 'omniauth'

module OmniAuth
  module Strategies
    class Developer
      include OmniAuth::Strategy
    end
  end
end

Check this tutorial and related SO question.

2. Is there a better way to create OAuth2::AccessToken?

To use Oauth2, you must register your project in the Google API Console and enable the Contacts API service. You need to get a 'refresh token' that you use to 're-authenticate' with google each time you make an API call. You can check the steps here.

Hope this helps! :)

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59