Take the 2-minute tour ×

This is a follow-up question for this question:

I have successfully created a private key and have read the various pages of Google documentation on the concepts of server to server authentication.

I need to create a JWT to authorize my App Engine application (Python) to access the Google calendar and post events in the calendar. From the source in oauth2client it looks like I need to use oauth2client.client.SignedJwtAssertionCredentials to create the JWT.

What I'm missing at the moment is a stylised bit of sample Python code of the various steps involved to create the JWT and use it to authenticate my App Engine application for Google Calendar. Also, from SignedJwtAssertionCredentials source it looks like I need some App Engine compatible library to perform the signing.

Can anybody shed some light on this?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

After some digging I found a couple of samples based on the OAuth2 authentication. From this I cooked up the following simple sample that creates a JWT to access the calendar API:

import httplib2
import pprint

from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials

# Get the private key from the Google supplied private key file.
f = file("your_private_key_file.p12", "rb")
key = f.read()

# Create the JWT
credentials = SignedJwtAssertionCredentials(
  "xxxxxxxxxx@developer.gserviceaccount.com", key,

# Create an authorized http instance
http = httplib2.Http()
http = credentials.authorize(http)

# Create a service call to the calendar API

# List all calendars.
lists = service.calendarList().list(pageToken=None).execute(http=http)

For this to work on Google App Engine you will need to enable PyCrypto for your app. This means adding the following to your app.yaml file:

- name: pycrypto
  version: "latest"
share|improve this answer
add comment

Your Answer


