diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-25 20:11:22 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-25 20:11:22 +0000 |
commit | fc9bc05353e26d7d169402aeb4d4f248403cb420 (patch) | |
tree | 3170b0aa9c0601703e4ac09e5ae71b9be98a4868 /remoting/webapp | |
parent | 3fa29ca5ebc800d5eb187ace26dedd996485a39a (diff) | |
download | chromium_src-fc9bc05353e26d7d169402aeb4d4f248403cb420.zip chromium_src-fc9bc05353e26d7d169402aeb4d4f248403cb420.tar.gz chromium_src-fc9bc05353e26d7d169402aeb4d4f248403cb420.tar.bz2 |
Wire in OAuth2 support into non-sandboxed connections in libjingle.
BUG=none
TEST=can connect w/o ClientLogin token.
Review URL: http://codereview.chromium.org/7008003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86685 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/webapp')
-rw-r--r-- | remoting/webapp/me2mom/choice.html | 14 | ||||
-rw-r--r-- | remoting/webapp/me2mom/remoting.js | 51 | ||||
-rw-r--r-- | remoting/webapp/me2mom/remoting_session.html | 6 | ||||
-rw-r--r-- | remoting/webapp/me2mom/remoting_session.js | 3 |
4 files changed, 55 insertions, 19 deletions
diff --git a/remoting/webapp/me2mom/choice.html b/remoting/webapp/me2mom/choice.html index 3c44172..768e314 100644 --- a/remoting/webapp/me2mom/choice.html +++ b/remoting/webapp/me2mom/choice.html @@ -33,7 +33,16 @@ found in the LICENSE file. <input type="text" name="oauth2_code" id="oauth2_code" /> <input type="submit"/> </form> - <div id="xmpp_div"> + <div id="email_div"> + Current Email: <span id="current_email"></span> + <form id='new_email_form' action="" + onsubmit="setEmail(this); return false;"> + <label for="new_email">New Email:</label> + <input type="text" name="new_email" id="new_email" /> + <input type="submit" name="Set E-mail"/> + </form> + </div> + <div id="xmpp_div" style="display:none;"> XMPP Token: <span id="xmpp_status"></span> <button onclick="clearXmpp();" id="xmpp_clear" style="display:none;"> Clear @@ -130,7 +139,8 @@ found in the LICENSE file. To connect to another computer, enter the access code provided to you by that computer's user. </p> - <form action="" onsubmit="tryConnect(this); return false;"> + <form action="" onsubmit="tryConnect(this['access_code_entry'].value); + return false;"> <input type="text" id="access_code_entry"/> <button type="submit"> diff --git a/remoting/webapp/me2mom/remoting.js b/remoting/webapp/me2mom/remoting.js index 76dd63f2..7b1adde 100644 --- a/remoting/webapp/me2mom/remoting.js +++ b/remoting/webapp/me2mom/remoting.js @@ -31,13 +31,20 @@ function updateAuthStatus_() { document.getElementById('xmpp_form').style.display = 'none'; xmpp_status.innerText = 'OK'; xmpp_status.style.color = 'green'; - remoting.xmppAuthToken = remoting.getItem(XMPP_TOKEN_NAME); } else { document.getElementById('xmpp_clear').style.display = 'none'; document.getElementById('xmpp_form').style.display = 'inline'; xmpp_status.innerText = 'Unauthorized'; xmpp_status.style.color = 'red'; } + var current_email = document.getElementById('current_email'); + if (remoting.getItem(XMPP_LOGIN_NAME)) { + oauth2_status.style.color = 'green'; + current_email.innerText = remoting.getItem(XMPP_LOGIN_NAME); + } else { + oauth2_status.style.color = 'red'; + current_email.innerText = 'missing e-mail'; + } } function clientLoginError_(xhr) { @@ -139,6 +146,11 @@ function authorizeXmpp(form) { xhr.send(post_data); } +function setEmail(form) { + remoting.setItem(XMPP_LOGIN_NAME, form['new_email'].value); + updateAuthStatus_(); +} + function authorizeOAuth2(code) { remoting.oauth2.exchangeCodeForToken(code, updateAuthStatus_); } @@ -194,6 +206,17 @@ function setClientMode(mode) { } function tryShare() { + if (remoting.oauth2.needsNewAccessToken()) { + remoting.oauth2.refreshAccessToken(function() { + if (remoting.oauth2.needsNewAccessToken()) { + // If we still need it, we're going to infinite loop. + throw "Unable to get access token"; + } + tryShare(); + }); + return; + } + var div = document.getElementById('plugin_wrapper'); var plugin = document.createElement('embed'); plugin.setAttribute('type', 'HOST_PLUGIN_MIMETYPE'); @@ -202,7 +225,7 @@ function tryShare() { div.appendChild(plugin); plugin.onStateChanged = onStateChanged_; plugin.connect(remoting.getItem(XMPP_LOGIN_NAME), - remoting.getItem(XMPP_TOKEN_NAME)); + 'oauth2:' + remoting.oauth2.getAccessToken()); } function onStateChanged_() { @@ -287,8 +310,19 @@ function resolveSupportId(support_id) { xhr.send(null); } -function tryConnect(form) { - remoting.accessCode = normalizeAccessCode(form['access_code_entry'].value); +function tryConnect(accessCode) { + if (remoting.oauth2.needsNewAccessToken()) { + remoting.oauth2.refreshAccessToken(function() { + if (remoting.oauth2.needsNewAccessToken()) { + // If we still need it, we're going to infinite loop. + throw "Unable to get access token"; + } + tryConnect(accessCode); + }); + return; + } + + remoting.accessCode = accessCode; // TODO(jamiewalch): Since the mapping from (SupportId, HostSecret) to // AccessCode is not yet defined, assume it's hyphen-separated for now. var parts = remoting.accessCode.split('-'); @@ -296,14 +330,7 @@ function tryConnect(form) { showConnectError_(404); } else { setClientMode('connecting'); - if (remoting.oauth2.needsNewAccessToken()) { - remoting.oauth2.refreshAccessToken(function() { - resolveSupportId(parts[0]); - }); - return; - } else { - resolveSupportId(parts[0]); - } + resolveSupportId(parts[0]); } } diff --git a/remoting/webapp/me2mom/remoting_session.html b/remoting/webapp/me2mom/remoting_session.html index ec2cad1..8059a46 100644 --- a/remoting/webapp/me2mom/remoting_session.html +++ b/remoting/webapp/me2mom/remoting_session.html @@ -9,10 +9,8 @@ found in the LICENSE file. <head> <title id="title">Remoting Session</title> <link rel="stylesheet" type="text/css" href="main.css" /> - <script type="text/javascript"> - </script> - <script type="text/javascript" src="remoting_session.js"> - </script> + <script type="text/javascript" src="oauth2.js"></script> + <script type="text/javascript" src="remoting_session.js"></script> </head> <body class="remoting_body" onload="init();"> <div id="status_msg_div"> diff --git a/remoting/webapp/me2mom/remoting_session.js b/remoting/webapp/me2mom/remoting_session.js index da251c4..23e8ea7 100644 --- a/remoting/webapp/me2mom/remoting_session.js +++ b/remoting/webapp/me2mom/remoting_session.js @@ -146,7 +146,8 @@ function init() { registerConnection(); } else { plugin.connectUnsandboxed(remoting.hostjid, remoting.username, - remoting.xmppAuthToken, remoting.accessCode); + 'oauth2:' + remoting.oauth2.getAccessToken(), + remoting.accessCode); } } else { addToDebugLog('ERROR: remoting plugin not loaded'); |