Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 | |
| 7 '''A set of utilities to interface with the Chrome Webstore API.''' | |
| 8 | |
| 9 import SimpleHTTPServer | |
| 10 import SocketServer | |
| 11 import httplib | |
| 12 import json | |
| 13 import re | |
| 14 import thread | |
| 15 import urllib | |
| 16 | |
| 17 PROJECT_ARGS = { | |
| 18 'client_id': '937534751394-gbj5334v9144c57qjqghl7d283plj5r4.apps.googleusercon tent.com', | |
| 19 '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
| |
| 20 'grant_type': 'authorization_code', | |
| 21 'redirect_uri': 'http://localhost:8000' | |
| 22 } | |
| 23 | |
| 24 PORT = 8000 | |
| 25 | |
| 26 class CodeRequestHandler(SocketServer.StreamRequestHandler): | |
| 27 def handle(self): | |
| 28 content = self.rfile.readline() | |
| 29 self.server.code = re.search('code=(.*) ', content).groups()[0] | |
| 30 self.rfile.close() | |
| 31 | |
| 32 def GetAuthCode(): | |
| 33 Handler = CodeRequestHandler | |
| 34 httpd = SocketServer.TCPServer(("", PORT), Handler) | |
| 35 print ('Please navigate to' | |
| 36 ' 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.
| |
| 37 'response_type=code&' | |
| 38 'scope=https://www.googleapis.com/auth/chromewebstore&' | |
| 39 'client_id=%(client_id)s&' | |
| 40 'redirect_uri=%(redirect_uri)s' % PROJECT_ARGS) | |
| 41 httpd.handle_request() | |
| 42 return httpd.code | |
| 43 | |
| 44 def GetOauthToken(code): | |
| 45 PROJECT_ARGS['code'] = code | |
| 46 body = urllib.urlencode(PROJECT_ARGS) | |
| 47 conn = httplib.HTTPSConnection('accounts.google.com') | |
| 48 conn.putrequest('POST', '/o/oauth2/token') | |
| 49 conn.putheader('content-type', 'application/x-www-form-urlencoded') | |
| 50 conn.putheader('content-length', len(body)) | |
| 51 conn.endheaders() | |
| 52 conn.send(body) | |
| 53 content = conn.getresponse().read() | |
| 54 json_content = json.loads(content) | |
| 55 return json_content | |
| 56 | |
| 57 def GetUploadStatus(): | |
| 58 code = GetAuthCode() | |
| 59 access_token = GetOauthToken(code) | |
| 60 url = 'www.googleapis.com' | |
| 61 publish_dogfood = '/chromewebstore/v1.1/items/kgejglhpjiefppelpmljglcjbhoiplfn ?projection=draft' | |
| 62 headers = {'Authorization': 'Bearer %(access_token)s' % access_token, | |
| 63 'x-goog-api-version': 2, | |
| 64 'Content-Length': 0 | |
| 65 } | |
| 66 | |
| 67 conn = httplib.HTTPSConnection(url) | |
| 68 conn.request('GET', publish_dogfood, '', headers) | |
| OLD | NEW |