Google Oauth Authorization failure

658 views Asked by At

I am trying to use the 'google-api-ruby-client' gem in a rails app to be able to request a user for access to their Google Drive. I am successfully navigating to the request permissions page where a user clicks accept. I have a callback function in a controller that captures the code that is returned upon a user clicking accept. I am then trying to fetch an access token. This is where I am getting hung up. I am getting this error:

enter image description here

My current controller code looks like this:

require 'google/api_client'

class GoogleDriveController < ApplicationController

  def initialize
    @client = Google::APIClient.new(:application_name => '????',    :application_version => '1.0.0')
  end

  def auth
    @client.authorization.client_id = ENV["GOOGLE_CLIENT_ID"]
    @client.authorization.client_secret = ENV["GOOGLE_CLIENT_SECRET"]
    @client.authorization.redirect_uri = ENV["GOOGLE_REDIRECT_URI"]
    @client.authorization.scope =     'https://www.googleapis.com/auth/drive'
    authorize_url = @client.authorization.authorization_uri
    puts "https://#{authorize_url.host}#{authorize_url.path}?#{authorize_url.query}"
    render json: {google_auth_url: "https://#{authorize_url.host}#{authorize_url.path}?#{authorize_url.query}"}
  end

  def callback
    @client.authorization.code = params[:code] if params[:code]
    access_token = @client.authorization.fetch_access_token!
    @drive = @client.discovered_api('drive', 'v2')
  end

end

Any help or nudges in the right direction would be greatly appreciated.

Thanks!

1

There are 1 answers