Moved OAuth discovery data into future.json

This commit is contained in:
Joe Gregorio
2010-09-09 15:15:56 -04:00
parent 4292c6e6d6
commit a2f56e7ec5
10 changed files with 259 additions and 61 deletions

View File

@@ -4,4 +4,4 @@ syntax: glob
.*.swp .*.swp
*/.git/* */.git/*
.gitignore .gitignore
oauth_token.dat samples/cmdline/*.dat

View File

@@ -3,6 +3,59 @@
"buzz": { "buzz": {
"v1": { "v1": {
"baseUrl": "https://www.googleapis.com/", "baseUrl": "https://www.googleapis.com/",
"auth": {
"request": {
"url": "https://www.google.com/accounts/OAuthGetRequestToken",
"parameters": {
"xoauth_displayname": {
"parameterType": "query",
"required": false
},
"domain": {
"parameterType": "query",
"required": true
},
"scope": {
"parameterType": "query",
"required": true
}
}
},
"authorize": {
"url": "https://www.google.com/buzz/api/auth/OAuthAuthorizeToken",
"parameters": {
"oauth_token": {
"parameterType": "query",
"required": true
},
"iconUrl": {
"parameterType": "query",
"required": false
},
"domain": {
"parameterType": "query",
"required": true
},
"scope": {
"parameterType": "query",
"required": true
}
}
},
"access": {
"url": "https://www.google.com/accounts/OAuthGetAccessToken",
"parameters": {
"domain": {
"parameterType": "query",
"required": true
},
"scope": {
"parameterType": "query",
"required": true
}
}
}
},
"resources": { "resources": {
"activities": { "activities": {
"methods": { "methods": {

View File

@@ -3,6 +3,59 @@
"latitude": { "latitude": {
"v1": { "v1": {
"baseUrl": "https://www.googleapis.com/", "baseUrl": "https://www.googleapis.com/",
"auth": {
"request": {
"url": "https://www.google.com/accounts/OAuthGetRequestToken",
"parameters": {
"xoauth_displayname": {
"parameterType": "query",
"required": False
},
"domain": {
"parameterType": "query",
"required": True
},
"scope": {
"parameterType": "query",
"required": True
},
},
},
"authorize": {
"url": "https://www.google.com/latitude/apps/OAuthAuthorizeToken",
"parameters": {
"oauth_token": {
"parameterType": "query",
"required": True
},
"iconUrl": {
"parameterType": "query",
"required": False
},
"domain": {
"parameterType": "query",
"required": True
},
"scope": {
"parameterType": "query",
"required": True
},
},
},
"access": {
"url": "https://www.google.com/accounts/OAuthGetAccessToken",
"parameters": {
"domain": {
"parameterType": "query",
"required": True
},
"scope": {
"parameterType": "query",
"required": True
},
},
},
},
"resources": { "resources": {
"currentLocation": { "currentLocation": {
"methods": { "methods": {

View File

@@ -3,6 +3,59 @@
"moderator": { "moderator": {
"v1": { "v1": {
"baseUrl": "https://www.googleapis.com/", "baseUrl": "https://www.googleapis.com/",
"auth": {
"request": {
"url": "https://www.google.com/accounts/OAuthGetRequestToken",
"parameters": {
"xoauth_displayname": {
"parameterType": "query",
"required": false
},
"domain": {
"parameterType": "query",
"required": false
},
"scope": {
"parameterType": "query",
"required": true
}
}
},
"authorize": {
"url": "https://www.google.com/accounts/OAuthAuthorizeToken",
"parameters": {
"oauth_token": {
"parameterType": "query",
"required": true
},
"iconUrl": {
"parameterType": "query",
"required": false
},
"domain": {
"parameterType": "query",
"required": false
},
"scope": {
"parameterType": "query",
"required": true
}
}
},
"access": {
"url": "https://www.google.com/accounts/OAuthGetAccessToken",
"parameters": {
"domain": {
"parameterType": "query",
"required": false
},
"scope": {
"parameterType": "query",
"required": true
}
}
}
},
"resources": { "resources": {
"profiles": { "profiles": {
"methods": { "methods": {

View File

@@ -112,6 +112,7 @@ def build(serviceName, version, http=httplib2.Http(),
d = simplejson.load(f) d = simplejson.load(f)
f.close() f.close()
future = d['data'][serviceName][version]['resources'] future = d['data'][serviceName][version]['resources']
auth_discovery = d['data'][serviceName][version]['auth']
base = service['baseUrl'] base = service['baseUrl']
resources = service['resources'] resources = service['resources']
@@ -124,6 +125,9 @@ def build(serviceName, version, http=httplib2.Http(),
self._baseUrl = base self._baseUrl = base
self._model = model self._model = model
def auth_discovery(self):
return auth_discovery
def createMethod(theclass, methodName, methodDesc, futureDesc): def createMethod(theclass, methodName, methodDesc, futureDesc):
def method(self, **kwargs): def method(self, **kwargs):

View File

@@ -29,61 +29,6 @@ def _abstract():
raise NotImplementedError('You need to override this function') raise NotImplementedError('You need to override this function')
buzz_discovery = {
'request': {
'url': 'https://www.google.com/accounts/OAuthGetRequestToken',
'parameters': {
'xoauth_displayname': {
'parameterType': 'query',
'required': False
},
'domain': {
'parameterType': 'query',
'required': True
},
'scope': {
'parameterType': 'query',
'required': True
},
},
},
'authorize': {
'url': 'https://www.google.com/buzz/api/auth/OAuthAuthorizeToken',
'parameters': {
'oauth_token': {
'parameterType': 'query',
'required': True
},
'iconUrl': {
'parameterType': 'query',
'required': False
},
'domain': {
'parameterType': 'query',
'required': True
},
'scope': {
'parameterType': 'query',
'required': True
},
},
},
'access': {
'url': 'https://www.google.com/accounts/OAuthGetAccessToken',
'parameters': {
'domain': {
'parameterType': 'query',
'required': True
},
'scope': {
'parameterType': 'query',
'required': True
},
},
},
}
def _oauth_uri(name, discovery, params): def _oauth_uri(name, discovery, params):
"""Look up the OAuth UR from the discovery """Look up the OAuth UR from the discovery
document and add query parameters based on document and add query parameters based on

View File

@@ -19,7 +19,7 @@ import pickle
def main(): def main():
f = open("oauth_token.dat", "r") f = open("buzz.dat", "r")
credentials = pickle.loads(f.read()) credentials = pickle.loads(f.read())
f.close() f.close()

View File

@@ -0,0 +1,33 @@
#!/usr/bin/python2.4
# -*- coding: utf-8 -*-
#
# Copyright 2010 Google Inc. All Rights Reserved.
"""Simple command-line example for Buzz.
Command-line application that retrieves the users
latest content and then adds a new entry.
"""
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
from apiclient.discovery import build
import httplib2
import pickle
def main():
f = open("moderator.dat", "r")
credentials = pickle.loads(f.read())
f.close()
http = httplib2.Http()
http = credentials.authorize(http)
p = build("moderator", "v1", http=http)
print p.submissions().list(seriesId="7035", topicId="64")
if __name__ == '__main__':
main()

View File

@@ -22,11 +22,13 @@ other example apps in the same directory.
__author__ = 'jcgregorio@google.com (Joe Gregorio)' __author__ = 'jcgregorio@google.com (Joe Gregorio)'
from apiclient.oauth import buzz_discovery from apiclient.discovery import build
from apiclient.oauth import FlowThreeLegged from apiclient.oauth import FlowThreeLegged
import pickle import pickle
buzz_discovery = build("buzz", "v1").auth_discovery()
flow = FlowThreeLegged(buzz_discovery, flow = FlowThreeLegged(buzz_discovery,
consumer_key='anonymous', consumer_key='anonymous',
consumer_secret='anonymous', consumer_secret='anonymous',
@@ -48,6 +50,6 @@ verification = raw_input('What is the verification code? ').strip()
credentials = flow.step2_exchange(verification) credentials = flow.step2_exchange(verification)
f = open('oauth_token.dat', 'w') f = open('buzz.dat', 'w')
f.write(pickle.dumps(credentials)) f.write(pickle.dumps(credentials))
f.close() f.close()

View File

@@ -0,0 +1,55 @@
# Copyright (C) 2010 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Do the OAuth 1.0a three legged dance.
Do the OAuth 1.0a three legged dance for
a Buzz command line application. Store the generated
credentials in a common file that is used by
other example apps in the same directory.
"""
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
from apiclient.discovery import build
from apiclient.oauth import FlowThreeLegged
import pickle
moderator_discovery = build("moderator", "v1").auth_discovery()
flow = FlowThreeLegged(moderator_discovery,
consumer_key='anonymous',
consumer_secret='anonymous',
user_agent='google-api-client-python-mdrtr-cmdline/1.0',
domain='anonymous',
scope='https://www.googleapis.com/auth/moderator',
xoauth_displayname='Google API Client Example App')
authorize_url = flow.step1_get_authorize_url()
print 'Go to the following link in your browser:'
print authorize_url
print
accepted = 'n'
while accepted.lower() == 'n':
accepted = raw_input('Have you authorized me? (y/n) ')
verification = raw_input('What is the verification code? ').strip()
credentials = flow.step2_exchange(verification)
f = open('moderator.dat', 'w')
f.write(pickle.dumps(credentials))
f.close()