Inappropriate response from Google Calendar Push Notifications

69 Views Asked by At

I'm working on setting up Push Notifications for Google Calendar using Rails, specifically the google-api-client and V3 API. I've successfully obtained OAuth2.0 permission and can create, delete, and update events on Google from my application. Now, I'm trying to receive notifications in my application whenever a user makes changes to their Google Calendar. But I am not able to receive expected push notification message response.

Here's the code I'm using to set up the notification:

def sync_google_events
    client = Signet::OAuth2::Client.new(client_options(callback_url))
    client.update!(session[:authorization])
    service = set_calender_service(client)

    channel = Google::Apis::CalendarV3::Channel.new(address: 'ngrok_url', id: SecureRandom.uuid, kind: 'api#channel', type: 'web_hook', token: SecureRandom.uuid)
    response = service.watch_event('primary', channel, single_events: true)

  end

I have created this function which creates google channel object and passes the object in watch_event method.

In the response of this function I am getting this

@expiration = 1702980528000,
 @id="e5xxxxxxxxxxxxxxxxx",
 @kind="api#channel",
 @resource_id="xxxxxxxxxxxxxxxxxxx",
 @resource_uri="https://www.googleapis.com/calendar/v3/calendars/primary/events?alt=json&singleEvents=true",
 @token="xxxxxxxxxxxxxxxxxx"

and during the execution my applications webhook endpoint also gets invoked.

class WebhookController < ApplicationController
  skip_before_action :verify_authenticity_token, only: :webhook

  def webhook
    puts 'Some changes have been made in google calender'
  end
end

However, the issue is that I'm not receiving the expected headers (X-Goog-Channel-ID, X-Goog-Channel-Token, X-Goog-Resource-ID, X-Goog-Resource-URI) in the response. Even when creating a new event, there are no headers present.

The response I'm getting looks like this:

@cache_control={},
 @committed=false,
 @cv=#<MonitorMixin::ConditionVariable:0x00007fed0cef0b68 @cond=#<Thread::ConditionVariable:0x00007fed0cef0a78>, @monitor=#<Monitor:0x00007fed0cef0e10>>,
 @header=
  {"X-Frame-Options"=>"SAMEORIGIN",
   "X-XSS-Protection"=>"0",
   "X-Content-Type-Options"=>"nosniff",
   "X-Download-Options"=>"noopen",
   "X-Permitted-Cross-Domain-Policies"=>"none",
   "Referrer-Policy"=>"strict-origin-when-cross-origin"},
 @mon_data=#<Monitor:0x00007fed0cef0e10>,
 @mon_data_owner_object_id=370,
 @request=#<ActionDispatch::Request POST "894e.ngrok-free.app/webhook" for 74.125.210.10>,
 @sending=false,
 @sent=false,
 @status=200,
 @stream=#<ActionDispatch::Response::Buffer:0x00007fed0cef0c58 @buf=[], @closed=false, @response=#<ActionDispatch::Response:0x00007fed0cef0eb0 ...>, @str_body=nil>>

I'm unsure about the missing steps or configurations in my code. Can someone help me figure out what I might be missing in this setup?

0

There are 0 best solutions below