Skip to content

Commit

Permalink
Make compatible with oauth2client v2.0.0
Browse files Browse the repository at this point in the history
The v2.0.0 release moved a few modules to a subpackage of oauth2client
called contrib. Among these was the locked_file module necessary for
credential storage.

Sample code for Django, App Engine and Service Accounts needed updates
as well.
  • Loading branch information
adrian-the-git committed Feb 18, 2016
1 parent d83246e commit 2122d3c
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion googleapiclient/discovery_cache/file_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import tempfile
import threading

from oauth2client.locked_file import LockedFile
from oauth2client.contrib.locked_file import LockedFile

from . import base
from ..discovery_cache import DISCOVERY_DOC_MAX_AGE
Expand Down
2 changes: 1 addition & 1 deletion samples/appengine/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import pickle

from googleapiclient import discovery
from oauth2client import appengine
from oauth2client import client
from oauth2client.contrib import appengine
from google.appengine.api import memcache

import webapp2
Expand Down
4 changes: 2 additions & 2 deletions samples/django_sample/plus/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from django.contrib.auth.models import User
from django.db import models

from oauth2client.django_orm import FlowField
from oauth2client.django_orm import CredentialsField
from oauth2client.contrib.django_orm import FlowField
from oauth2client.contrib.django_orm import CredentialsField


class CredentialsModel(models.Model):
Expand Down
2 changes: 1 addition & 1 deletion samples/django_sample/plus/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from django_sample import settings
from oauth2client import xsrfutil
from oauth2client.client import flow_from_clientsecrets
from oauth2client.django_orm import Storage
from oauth2client.contrib.django_orm import Storage

# CLIENT_SECRETS, name of a file containing the OAuth 2.0 information for this
# application, including client_id and client_secret, which are found
Expand Down
26 changes: 11 additions & 15 deletions samples/service_account/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,19 @@
import sys

from googleapiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
from oauth2client.service_account import ServiceAccountCredentials

def main(argv):
# Load the key in PKCS 12 format that you downloaded from the Google API
# Console when you created your Service account.
f = file('key.p12', 'rb')
key = f.read()
f.close()

# Create an httplib2.Http object to handle our HTTP requests and authorize it
# with the Credentials. Note that the first parameter, service_account_name,
# is the Email address created for the Service account. It must be the email
# address associated with the key that was created.
credentials = SignedJwtAssertionCredentials(
'141491975384@developer.gserviceaccount.com',
key,
scope='https://www.googleapis.com/auth/tasks')
# Load the json format key that you downloaded from the Google API
# Console when you created your service account. For p12 keys, use the
# from_p12_keyfile method of ServiceAccountCredentials and specify the
# service account email address, p12 keyfile, and scopes.
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'service-account-abcdef123456.json',
scopes='https://www.googleapis.com/auth/tasks')

# Create an httplib2.Http object to handle our HTTP requests and authorize
# it with the Credentials.
http = httplib2.Http()
http = credentials.authorize(http)

Expand Down
2 changes: 1 addition & 1 deletion samples/storage_serviceaccount_appengine/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
from oauth2client.appengine import AppAssertionCredentials
from oauth2client.contrib.appengine import AppAssertionCredentials

# Constants for the XSL stylesheet and the Google Cloud Storage URI.
XSL = '\n<?xml-stylesheet href="/listing.xsl" type="text/xsl"?>\n';
Expand Down
2 changes: 1 addition & 1 deletion samples/tasks_appengine/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from webapp2_extras import jinja2

from googleapiclient.discovery import build
from oauth2client.appengine import OAuth2Decorator
from oauth2client.contrib.appengine import OAuth2Decorator

import settings

Expand Down

0 comments on commit 2122d3c

Please sign in to comment.