diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-24 00:19:10 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-24 00:19:10 +0000 |
commit | 7da22145ff36bd85ea468ca53ca73b9387d2a0c4 (patch) | |
tree | c6c18eccb7c6eb184d3e412f34a617d5b88857c0 /remoting/client | |
parent | 5325cfc2a21464f783d7026f2496a26bfe2bd91b (diff) | |
download | chromium_src-7da22145ff36bd85ea468ca53ca73b9387d2a0c4.zip chromium_src-7da22145ff36bd85ea468ca53ca73b9387d2a0c4.tar.gz chromium_src-7da22145ff36bd85ea468ca53ca73b9387d2a0c4.tar.bz2 |
Add in support for connecting with just the OAuth2 token. Default to OAuth2.
BUG=none
TEST=local appengine instance connects via OAuth2 and ClientLogin
Review URL: http://codereview.chromium.org/7054029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86374 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/client')
-rw-r--r-- | remoting/client/appengine/api.py | 16 | ||||
-rw-r--r-- | remoting/client/appengine/auth.py | 39 | ||||
-rw-r--r-- | remoting/client/appengine/chromoting_session.html | 2 | ||||
-rw-r--r-- | remoting/client/appengine/hostlist.html | 45 | ||||
-rw-r--r-- | remoting/client/appengine/main.py | 10 | ||||
-rw-r--r-- | remoting/client/appengine/static_files/chromoting_session.js | 8 | ||||
-rw-r--r-- | remoting/client/appengine/static_files/client.js | 31 |
7 files changed, 93 insertions, 58 deletions
diff --git a/remoting/client/appengine/api.py b/remoting/client/appengine/api.py index e1e2ddb..959aaab 100644 --- a/remoting/client/appengine/api.py +++ b/remoting/client/appengine/api.py @@ -17,19 +17,6 @@ from google.appengine.ext.webapp.util import login_required import auth -class GetXmppTokenHandler(webapp.RequestHandler): - """Retrieves the user's XMPP token.""" - @login_required - def get(self): - try: - self.response.headers['Content-Type'] = 'application/json' - self.response.out.write( - json.dumps({'xmpp_token': auth.GetXmppToken().token})) - except auth.NotAuthenticated: - self.response.out.write('User has not authenticated') - self.set_status(400) - - class GetHostListHandler(webapp.RequestHandler): """Proxies the host-list handlers on the Chromoting directory.""" @login_required @@ -43,7 +30,7 @@ class GetHostListHandler(webapp.RequestHandler): result = urlfetch.fetch( url = 'https://www.googleapis.com/chromoting/v1/@me/hosts', method = urlfetch.GET, - headers = {'Authorization': 'OAuth ' + auth.GetAccessToken()}) + headers = {'Authorization': 'OAuth ' + auth.GetOAuth2AccessToken()}) self.response.set_status(result.status_code) for i in result.headers: self.response.headers[i] = result.headers[i] @@ -53,7 +40,6 @@ class GetHostListHandler(webapp.RequestHandler): def main(): application = webapp.WSGIApplication( [ - ('/api/get_xmpp_token', GetXmppTokenHandler), ('/api/get_host_list', GetHostListHandler) ], debug=True) diff --git a/remoting/client/appengine/auth.py b/remoting/client/appengine/auth.py index 54be383..63dce6a 100644 --- a/remoting/client/appengine/auth.py +++ b/remoting/client/appengine/auth.py @@ -43,7 +43,7 @@ class NotAuthenticated(Exception): pass -class XmppToken(db.Model): +class ClientLoginToken(db.Model): auth_token = db.StringProperty() @@ -61,7 +61,7 @@ def HasOAuth2Tokens(throws=True): return False; -def GetAccessToken(throws=True): +def GetOAuth2AccessToken(throws=True): oauth2_tokens = OAuth2Tokens.get_or_insert(GetUserId()) if not oauth2_tokens.refresh_token: @@ -93,8 +93,8 @@ def GetAccessToken(throws=True): return oauth2_tokens.access_token -def GetXmppToken(throws=True): - """Retrieves the XMPP for Chromoting. +def GetClientLoginToken(throws=True): + """Retrieves the ClientLogin for Chromoting. Args: throws: bool (optional) Default is True. Throws if no token. @@ -102,15 +102,15 @@ def GetXmppToken(throws=True): Returns: The auth token for the current user. """ - xmpp_token = XmppToken.get_or_insert(GetUserId()) - if throws and not xmpp_token.auth_token: + clientlogin_token = ClientLoginToken.get_or_insert(GetUserId()) + if throws and not clientlogin_token.auth_token: raise NotAuthenticated() - return xmpp_token.auth_token + return clientlogin_token.auth_token -def ClearXmppToken(): +def ClearClientLoginToken(): """Clears all Chromoting ClientLogin token state from the datastore.""" - db.delete(db.Key.from_path('XmppToken', GetUserId())) + db.delete(db.Key.from_path('ClientLoginToken', GetUserId())) def ClearOAuth2Token(): @@ -137,7 +137,7 @@ def GetUserId(): return user.user_id() -class XmppAuthHandler(webapp.RequestHandler): +class ClientLoginAuthHandler(webapp.RequestHandler): """Prompts Google Accounts credentials and retrieves a ClientLogin token. This class takes the user's plaintext username and password, and then @@ -151,7 +151,7 @@ class XmppAuthHandler(webapp.RequestHandler): """ @login_required def get(self): - ClearXmppToken() + ClearClientLoginToken() path = os.path.join(os.path.dirname(__file__), 'client_login.html') self.response.out.write(template.render(path, {})) @@ -178,17 +178,18 @@ class XmppAuthHandler(webapp.RequestHandler): self.response.set_status(result.status_code) return - xmpp_token = XmppToken(key_name = GetUserId()) - xmpp_token.auth_token = re.search("Auth=(.*)", result.content).group(1) - xmpp_token.put() + clientlogin_token = ClientLoginToken(key_name = GetUserId()) + clientlogin_token.auth_token = re.search( + "Auth=(.*)", result.content).group(1) + clientlogin_token.put() self.redirect('/') -class ClearXmppTokenHandler(webapp.RequestHandler): - """Endpoint for dropping the user's Xmpp token.""" +class ClearClientLoginTokenHandler(webapp.RequestHandler): + """Endpoint for dropping the user's ClientLogin token.""" @login_required def get(self): - ClearXmppToken() + ClearClientLoginToken() self.redirect('/') @@ -248,8 +249,8 @@ class OAuth2ReturnHandler(webapp.RequestHandler): def main(): application = webapp.WSGIApplication( [ - ('/auth/xmpp_auth', XmppAuthHandler), - ('/auth/clear_xmpp_token', ClearXmppTokenHandler), + ('/auth/clientlogin_auth', ClientLoginAuthHandler), + ('/auth/clear_clientlogin_token', ClearClientLoginTokenHandler), ('/auth/clear_oauth2_token', ClearOAuth2TokenHandler), ('/auth/oauth2_return', OAuth2ReturnHandler) ], diff --git a/remoting/client/appengine/chromoting_session.html b/remoting/client/appengine/chromoting_session.html index 6197d6a..4d99999 100644 --- a/remoting/client/appengine/chromoting_session.html +++ b/remoting/client/appengine/chromoting_session.html @@ -13,7 +13,7 @@ found in the LICENSE file. <!-- // TODO(ajwong): Total Hack. We should be able to read the URL parameters // from JS, and also avoid passing in the connection tokens here. - document.xmppAuthToken="{{xmpp_token}}"; + document.talkToken="{{talk_token}}"; document.httpXmppProxy="{{http_xmpp_proxy}}"; document.username="{{username}}"; document.hostname="{{hostname}}"; diff --git a/remoting/client/appengine/hostlist.html b/remoting/client/appengine/hostlist.html index 10138fe..ee2a9de 100644 --- a/remoting/client/appengine/hostlist.html +++ b/remoting/client/appengine/hostlist.html @@ -24,10 +24,39 @@ found in the LICENSE file. <div id="mainview-content"> <div class="page"> <section> - <h3>Http Xmpp Proxy</h3> - <input type="text" id="http_xmpp_proxy" - value="https://chromoting-httpxmpp-dev.corp.google.com" - size="50" /> + <h3>Http Xmpp Proxy Config </h3> + <div> + <table> + <tr> + <td align="right"> + <label for="clientlogin_proxy">Client Login Proxy</label> + </td> + <td><input type="text" name="clientlogin_proxy" id="clientlogin_proxy" + value="https://chromoting-httpxmpp-dev.corp.google.com" + size="60" /> + </td> + </tr> + <tr> + <td align="right"> + <label for="oauth2_proxy">OAuth2 Proxy</label> + </td> + <td><input type="text" name="oauth2_proxy" id="oauth2_proxy" + value="https://chromoting-httpxmpp-oauth2-dev.corp.google.com" + size="60" /> + </td> + </tr> + </table> + <div> + <input type="radio" name="token_type" id="use_oauth2" + value="oauth2" checked> + <label for="use_oauth2">Use OAuth2</label> + </input> + <input type="radio" name="token_type" id="use_clientlogin" + value="clientlogin"> + <label for="use_clientlogin">Use Client Login</label> + </input> + </div> + </div> </section> <section> <h3>Host List</h3> @@ -66,18 +95,18 @@ found in the LICENSE file. </div> </section> <section> - <h3>Xmpp Token</h3> + <h3>Client Login Token</h3> <div> -{% ifnotequal xmpp_token None %} +{% ifnotequal clientlogin_token None %} <div>Token Authenticated</div> <button id="subitem" - onclick="window.location='/auth/clear_xmpp_token'"> + onclick="window.location='/auth/clear_clientlogin_token'"> Clear Token </button> {% else %} <div class="error-msg">Token Not Authenticated</div> <button id="subitem" - onclick="window.location='/auth/xmpp_auth'"> + onclick="window.location='/auth/clientlogin_auth'"> Authenticate Token </button> {% endifnotequal %} diff --git a/remoting/client/appengine/main.py b/remoting/client/appengine/main.py index 878e71e..7d4b7b6 100644 --- a/remoting/client/appengine/main.py +++ b/remoting/client/appengine/main.py @@ -23,7 +23,7 @@ class HostListHandler(webapp.RequestHandler): def get(self): template_params = { 'has_oauth2_tokens': auth.HasOAuth2Tokens(), - 'xmpp_token': auth.GetXmppToken(throws=False) + 'clientlogin_token': auth.GetClientLoginToken(throws=False) } path = os.path.join(os.path.dirname(__file__), 'hostlist.html') self.response.out.write(template.render(path, template_params)) @@ -33,13 +33,19 @@ class ChromotingSessionHandler(webapp.RequestHandler): """Renders one Chromoting session.""" @login_required def get(self): + token_type = self.request.get('token_type') + if token_type == 'clientlogin': + talk_token = auth.GetClientLoginToken() + else: + talk_token = auth.GetOAuth2AccessToken() + template_params = { 'hostname': self.request.get('hostname'), 'username': users.get_current_user().email(), 'hostjid': self.request.get('hostjid'), 'connect_method': self.request.get('connect_method'), 'insecure': self.request.get('insecure'), - 'xmpp_token': auth.GetXmppToken(), + 'talk_token': talk_token, 'http_xmpp_proxy': self.request.get('http_xmpp_proxy') } path = os.path.join(os.path.dirname(__file__), 'chromoting_session.html') diff --git a/remoting/client/appengine/static_files/chromoting_session.js b/remoting/client/appengine/static_files/chromoting_session.js index 6a95f7d..b6960df 100644 --- a/remoting/client/appengine/static_files/chromoting_session.js +++ b/remoting/client/appengine/static_files/chromoting_session.js @@ -55,7 +55,7 @@ function registerConnection() { chromoting.plugin.sendIq = sendIq; // TODO:(jamiewalch): Pass in the correct nonce. - chromoting.plugin.connectSandboxed(clientjid, chromoting.hostjid, ''); + chromoting.plugin.connectSandboxed(clientjid, chromoting.hostjid); // TODO(ajwong): This should just be feedIq(); window.setTimeout(feedIq, 1000); } else { @@ -67,7 +67,7 @@ function registerConnection() { } xhr.send('host_jid=' + encodeURIComponent(chromoting.hostjid) + '&username=' + encodeURIComponent(chromoting.username) + - '&password=' + encodeURIComponent(chromoting.xmppAuthToken)); + '&password=' + encodeURIComponent(chromoting.talkToken)); setClientStateMessage("Connecting") } @@ -102,7 +102,7 @@ function init() { chromoting.username = document.username; chromoting.hostname = document.hostname; chromoting.hostjid = document.hostjid; - chromoting.xmppAuthToken = document.xmppAuthToken; + chromoting.talkToken = document.talkToken; chromoting.connectMethod = document.connectMethod; // Only allow https connections to the httpXmppProxy unless we're running in @@ -134,7 +134,7 @@ function init() { } else { // TODO:(jamiewalch): Pass in the correct nonce. plugin.connect(chromoting.username, chromoting.hostjid, - chromoting.xmppAuthToken, ''); + chromoting.talkToken, ''); } } else { addToDebugLog('ERROR: chromoting plugin not loaded'); diff --git a/remoting/client/appengine/static_files/client.js b/remoting/client/appengine/static_files/client.js index e2ed6f8..d5a1acc 100644 --- a/remoting/client/appengine/static_files/client.js +++ b/remoting/client/appengine/static_files/client.js @@ -171,6 +171,23 @@ function appendHostLinks(hostlist) { } } +function openSession(hostname, hostjid, method) { + var proxy = document.getElementById('oauth2_proxy').value; + var token_type = 'oauth2'; + if (document.getElementById('use_clientlogin').checked) { + proxy = document.getElementById('clientlogin_proxy').value; + token_type = 'clientlogin'; + } + + var url = 'session?hostname=' + encodeURIComponent(hostname) + + '&hostjid=' + encodeURIComponent(hostjid) + + '&http_xmpp_proxy=' + encodeURIComponent(proxy) + + '&token_type=' + encodeURIComponent(token_type) + + '&connect_method=' + encodeURIComponent(method); + + window.open(url); +} + // Create a single host description element. function addHostInfo(host) { var hostEntry = document.createElement('div'); @@ -189,21 +206,17 @@ function addHostInfo(host) { connect.setAttribute('type', 'button'); connect.setAttribute('value', 'Connect'); - connect.setAttribute('onclick', "window.open('session?hostname=" + - encodeURIComponent(host.hostName) + - "&hostjid=" + encodeURIComponent(host.jabberId) + - "');"); + connect.setAttribute('onclick', + "openSession('" + host.hostName + "', " + + "'" + host.jabberId + "', 'direct');"); span.appendChild(connect); var connectSandboxed = document.createElement('input'); connectSandboxed.setAttribute('type', 'button'); connectSandboxed.setAttribute('value', 'Connect Sandboxed'); connectSandboxed.setAttribute('onclick', - "window.open('session?hostname=" + encodeURIComponent(host.hostName) + - "&hostjid=" + encodeURIComponent(host.jabberId) + - "&http_xmpp_proxy=" + encodeURIComponent( - document.getElementById('http_xmpp_proxy').value) + - "&connect_method=sandboxed');"); + "openSession('" + host.hostName + "', " + + "'" + host.jabberId + "', 'sandboxed');"); span.appendChild(connectSandboxed); hostEntry.appendChild(span); |