Search code examples
.netauthenticationgoogle-calendar-apigoogle-oauth

Embed Google Calendar only users logged into my website (not necessarily through Google) can see


I have a .NET page which users can log into through various methods, including Google, Facebook, Twitter, and by creating a username and password directly on the site. I have a page that only logged-in users can see that has a calendar embedded.

Right now this calendar is not public, and can only be seen by Google users I authorize. I could of course make it public, but then once anyone knows the url of the calendar alone they could just go there and see it. I could also share it with anyone who's registered to my website through Google, but then it wouldn't be visible to people logged in through Facebook or some other way.

Question: How can I programmatically receive the calendar and display it to anyone who's logged into my website any way without having to make it public?

The two approaches that make sense to me are:

  1. Use my own site's authentication, maybe from the server side, to retrieve the calendar and display it somehow without giving the user that Google authentication they could take somewhere else
  2. Give non-Google users some kind of temporary Google authorization that's not good for anything but viewing that calendar.

Below is the page with a standard embed for the calendar as an example.

@{
    ViewBag.Title = "Calendar";
}

<h2>Calendar</h2>


<iframe src="https://calendar.google.com/calendar/embed?src=sharing.thelangschool.org_hrq83e34uldebnrcd4hptop0ps%40group.calendar.google.com&ctz=America/New_York" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>

Solution

  • You should use a service account https://developers.google.com/identity/protocols/OAuth2ServiceAccount and share your calendar with this service account's email address. Then your app can use the service account's credentials to display the events.