Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Unified Diff: remoting/webapp/oauth2.js

Issue 23891005: Fix OAuth "trampoline" content script to send a message with the oauth results rather than using a … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refresh window on new refresh token Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/webapp/jscompiler_hacks.js ('k') | remoting/webapp/oauth2_callback.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/oauth2.js
diff --git a/remoting/webapp/oauth2.js b/remoting/webapp/oauth2.js
index 6cc4b939d61f4774e0e036457256d81af1ba68b7..ce0da2d0bf80712370ed43026c40fe96195e70a7 100644
--- a/remoting/webapp/oauth2.js
+++ b/remoting/webapp/oauth2.js
@@ -267,6 +267,8 @@ remoting.OAuth2.prototype.onTokens_ =
* @return {void} Nothing.
*/
remoting.OAuth2.prototype.doAuthRedirect = function() {
+ /** @type {remoting.OAuth2} */
+ var that = this;
var xsrf_token = remoting.generateXsrfToken();
window.localStorage.setItem(this.KEY_XSRF_TOKEN_, xsrf_token);
var GET_CODE_URL = this.getOAuth2AuthEndpoint_() + '?' +
@@ -279,7 +281,34 @@ remoting.OAuth2.prototype.doAuthRedirect = function() {
'access_type': 'offline',
'approval_prompt': 'force'
});
- window.location.replace(GET_CODE_URL);
+
+ /**
+ * Processes the results of the oauth flow.
+ *
+ * @param {Object.<string, string>} message Dictionary containing the parsed
+ * OAuth redirect URL parameters.
+ */
+ function oauth2MessageListener(message) {
+ if ('code' in message && 'state' in message) {
+ var onDone = function() {
+ window.location.reload();
+ };
+ that.exchangeCodeForToken(
+ message['code'], message['state'], onDone);
+ } else {
+ if ('error' in message) {
+ console.error(
+ 'Could not obtain authorization code: ' + message['error']);
+ } else {
+ // We intentionally don't log the response - since we don't understand
+ // it, we can't tell if it has sensitive data.
+ console.error('Invalid oauth2 response.');
+ }
+ }
+ chrome.extension.onMessage.removeListener(oauth2MessageListener);
+ }
+ chrome.extension.onMessage.addListener(oauth2MessageListener);
+ window.open(GET_CODE_URL, '_blank', 'location=yes,toolbar=no,menubar=no');
};
/**
« no previous file with comments | « remoting/webapp/jscompiler_hacks.js ('k') | remoting/webapp/oauth2_callback.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698