OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """API endpoints to get around javascript's single-origin restriction.""" | 7 """API endpoints to get around javascript's single-origin restriction.""" |
8 | 8 |
9 import logging | 9 import logging |
10 | 10 |
11 from django.utils import simplejson as json | 11 from django.utils import simplejson as json |
12 | 12 |
13 from google.appengine.api import urlfetch | 13 from google.appengine.api import urlfetch |
14 from google.appengine.ext import webapp | 14 from google.appengine.ext import webapp |
15 from google.appengine.ext.webapp import util | 15 from google.appengine.ext.webapp import util |
16 from google.appengine.ext.webapp.util import login_required | 16 from google.appengine.ext.webapp.util import login_required |
17 import auth | 17 import auth |
18 | 18 |
19 | 19 |
20 class GetXmppTokenHandler(webapp.RequestHandler): | 20 class GetClientLoginTokenHandler(webapp.RequestHandler): |
21 """Retrieves the user's XMPP token.""" | 21 """Retrieves the user's ClientLogin token.""" |
22 @login_required | 22 @login_required |
23 def get(self): | 23 def get(self): |
24 try: | 24 try: |
25 self.response.headers['Content-Type'] = 'application/json' | 25 self.response.headers['Content-Type'] = 'application/json' |
26 self.response.out.write( | 26 self.response.out.write( |
27 json.dumps({'xmpp_token': auth.GetXmppToken().token})) | 27 json.dumps({'xmpp_token': auth.GetClientLoginToken().token})) |
Jamie
2011/05/23 19:24:12
Does the name of the token also need to change fro
awong
2011/05/23 20:43:23
Apparently no one even calls this. I've just remov
| |
28 except auth.NotAuthenticated: | 28 except auth.NotAuthenticated: |
29 self.response.out.write('User has not authenticated') | 29 self.response.out.write('User has not authenticated') |
30 self.set_status(400) | 30 self.set_status(400) |
31 | 31 |
32 | 32 |
33 class GetHostListHandler(webapp.RequestHandler): | 33 class GetHostListHandler(webapp.RequestHandler): |
34 """Proxies the host-list handlers on the Chromoting directory.""" | 34 """Proxies the host-list handlers on the Chromoting directory.""" |
35 @login_required | 35 @login_required |
36 def get(self): | 36 def get(self): |
37 if not auth.HasOAuth2Tokens(): | 37 if not auth.HasOAuth2Tokens(): |
38 self.response.set_status(403) | 38 self.response.set_status(403) |
39 self.response.headers['Content-Type'] = 'application/json' | 39 self.response.headers['Content-Type'] = 'application/json' |
40 self.response.out.write( | 40 self.response.out.write( |
41 '{"error": { "code": -1, "message": "No OAuth2 token" }}') | 41 '{"error": { "code": -1, "message": "No OAuth2 token" }}') |
42 return | 42 return |
43 result = urlfetch.fetch( | 43 result = urlfetch.fetch( |
44 url = 'https://www.googleapis.com/chromoting/v1/@me/hosts', | 44 url = 'https://www.googleapis.com/chromoting/v1/@me/hosts', |
45 method = urlfetch.GET, | 45 method = urlfetch.GET, |
46 headers = {'Authorization': 'OAuth ' + auth.GetAccessToken()}) | 46 headers = {'Authorization': 'OAuth ' + auth.GetOAuth2AccessToken()}) |
47 self.response.set_status(result.status_code) | 47 self.response.set_status(result.status_code) |
48 for i in result.headers: | 48 for i in result.headers: |
49 self.response.headers[i] = result.headers[i] | 49 self.response.headers[i] = result.headers[i] |
50 self.response.out.write(result.content) | 50 self.response.out.write(result.content) |
51 | 51 |
52 | 52 |
53 def main(): | 53 def main(): |
54 application = webapp.WSGIApplication( | 54 application = webapp.WSGIApplication( |
55 [ | 55 [ |
56 ('/api/get_xmpp_token', GetXmppTokenHandler), | 56 ('/api/get_clientlogin_token', GetClientLoginTokenHandler), |
57 ('/api/get_host_list', GetHostListHandler) | 57 ('/api/get_host_list', GetHostListHandler) |
58 ], | 58 ], |
59 debug=True) | 59 debug=True) |
60 util.run_wsgi_app(application) | 60 util.run_wsgi_app(application) |
61 | 61 |
62 | 62 |
63 if __name__ == '__main__': | 63 if __name__ == '__main__': |
64 main() | 64 main() |
OLD | NEW |