Chromium Code Reviews| Index: chrome/browser/resources/chromeos/chromevox/tools/webstore_util.py |
| diff --git a/chrome/browser/resources/chromeos/chromevox/tools/webstore_util.py b/chrome/browser/resources/chromeos/chromevox/tools/webstore_util.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..a25d22e30e89714d29f2b5b32ffe9c1990aa570f |
| --- /dev/null |
| +++ b/chrome/browser/resources/chromeos/chromevox/tools/webstore_util.py |
| @@ -0,0 +1,68 @@ |
| +#!/usr/bin/env python |
| + |
| +# Copyright 2014 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +'''A set of utilities to interface with the Chrome Webstore API.''' |
| + |
| +import SimpleHTTPServer |
| +import SocketServer |
| +import httplib |
| +import json |
| +import re |
| +import thread |
| +import urllib |
| + |
| +PROJECT_ARGS = { |
| + 'client_id': '937534751394-gbj5334v9144c57qjqghl7d283plj5r4.apps.googleusercontent.com', |
| + 'client_secret': 'A9OhIdmTcUX9zdvRINwySHol', |
|
dmazzoni
2014/07/23 18:52:42
Is this something we can safely check in?
David Tseng
2014/07/23 22:45:31
Not sure, but it's sent in the clear as a GET quer
David Tseng
2014/07/23 23:02:50
I take that back; it's sent as a body of a post me
|
| + 'grant_type': 'authorization_code', |
| + 'redirect_uri': 'http://localhost:8000' |
| +} |
| + |
| +PORT = 8000 |
| + |
| +class CodeRequestHandler(SocketServer.StreamRequestHandler): |
| + def handle(self): |
| + content = self.rfile.readline() |
| + self.server.code = re.search('code=(.*) ', content).groups()[0] |
| + self.rfile.close() |
| + |
| +def GetAuthCode(): |
| + Handler = CodeRequestHandler |
| + httpd = SocketServer.TCPServer(("", PORT), Handler) |
| + print ('Please navigate to' |
| + ' https://accounts.google.com/o/oauth2/auth?' |
|
dmazzoni
2014/07/23 18:52:42
Put this url in a constant at the top
David Tseng
2014/07/23 22:45:31
Done.
|
| + 'response_type=code&' |
| + 'scope=https://www.googleapis.com/auth/chromewebstore&' |
| + 'client_id=%(client_id)s&' |
| + 'redirect_uri=%(redirect_uri)s' % PROJECT_ARGS) |
| + httpd.handle_request() |
| + return httpd.code |
| + |
| +def GetOauthToken(code): |
| + PROJECT_ARGS['code'] = code |
| + body = urllib.urlencode(PROJECT_ARGS) |
| + conn = httplib.HTTPSConnection('accounts.google.com') |
| + conn.putrequest('POST', '/o/oauth2/token') |
| + conn.putheader('content-type', 'application/x-www-form-urlencoded') |
| + conn.putheader('content-length', len(body)) |
| + conn.endheaders() |
| + conn.send(body) |
| + content = conn.getresponse().read() |
| + json_content = json.loads(content) |
| + return json_content |
| + |
| +def GetUploadStatus(): |
| + code = GetAuthCode() |
| + access_token = GetOauthToken(code) |
| + url = 'www.googleapis.com' |
| + publish_dogfood = '/chromewebstore/v1.1/items/kgejglhpjiefppelpmljglcjbhoiplfn?projection=draft' |
| + headers = {'Authorization': 'Bearer %(access_token)s' % access_token, |
| + 'x-goog-api-version': 2, |
| + 'Content-Length': 0 |
| + } |
| + |
| + conn = httplib.HTTPSConnection(url) |
| + conn.request('GET', publish_dogfood, '', headers) |