Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * Third party authentication support for the remoting web-app. | 7 * Third party authentication support for the remoting web-app. |
| 8 * | 8 * |
| 9 * When third party authentication is being used, the client must request both a | 9 * When third party authentication is being used, the client must request both a |
| 10 * token and a shared secret from a third-party server. The server can then | 10 * token and a shared secret from a third-party server. The server can then |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 /** | 81 /** |
| 82 * Parse the access token from the URL to which we were redirected. | 82 * Parse the access token from the URL to which we were redirected. |
| 83 * | 83 * |
| 84 * @param {string} responseUrl The URL to which we were redirected. | 84 * @param {string} responseUrl The URL to which we were redirected. |
| 85 * @private | 85 * @private |
| 86 */ | 86 */ |
| 87 remoting.ThirdPartyTokenFetcher.prototype.parseRedirectUrl_ = | 87 remoting.ThirdPartyTokenFetcher.prototype.parseRedirectUrl_ = |
| 88 function(responseUrl) { | 88 function(responseUrl) { |
| 89 var token = ''; | 89 var token = ''; |
| 90 var sharedSecret = ''; | 90 var sharedSecret = ''; |
| 91 if (responseUrl && | 91 var query = responseUrl.substring(responseUrl.search('#') + 1); |
|
Wez
2013/08/09 00:35:28
Old code coped with an empty responseUrl - don't w
rmsousa
2013/08/09 01:44:00
being pedantic: the new code was also (accidentall
| |
| 92 responseUrl.search(this.redirectUri_ + '#') == 0) { | 92 var parts = query.split('&'); |
| 93 var query = responseUrl.substring(this.redirectUri_.length + 1); | 93 /** @type {Object.<string>} */ |
| 94 var parts = query.split('&'); | 94 var queryArgs = {}; |
| 95 /** @type {Object.<string>} */ | 95 for (var i = 0; i < parts.length; i++) { |
| 96 var queryArgs = {}; | 96 var pair = parts[i].split('='); |
| 97 for (var i = 0; i < parts.length; i++) { | 97 queryArgs[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]); |
| 98 var pair = parts[i].split('='); | 98 } |
| 99 queryArgs[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]); | |
| 100 } | |
| 101 | 99 |
| 102 // Check that 'state' contains the same XSRF token we sent in the request. | 100 // Check that 'state' contains the same XSRF token we sent in the request. |
| 103 var xsrfToken = queryArgs['state']; | 101 var xsrfToken = queryArgs['state']; |
| 104 if (xsrfToken == this.xsrfToken_ && | 102 if (xsrfToken == this.xsrfToken_ && |
| 105 'code' in queryArgs && 'access_token' in queryArgs) { | 103 'code' in queryArgs && 'access_token' in queryArgs) { |
| 106 // Terminology note: | 104 // Terminology note: |
| 107 // In the OAuth code/token exchange semantics, 'code' refers to the value | 105 // In the OAuth code/token exchange semantics, 'code' refers to the value |
| 108 // obtained when the *user* authenticates itself, while 'access_token' is | 106 // obtained when the *user* authenticates itself, while 'access_token' is |
| 109 // the value obtained when the *application* authenticates itself to the | 107 // the value obtained when the *application* authenticates itself to the |
| 110 // server ("implicitly", by receiving it directly in the URL fragment, or | 108 // server ("implicitly", by receiving it directly in the URL fragment, or |
| 111 // explicitly, by sending the 'code' and a 'client_secret' to the server). | 109 // explicitly, by sending the 'code' and a 'client_secret' to the server). |
| 112 // Internally, the piece of data obtained when the user authenticates | 110 // Internally, the piece of data obtained when the user authenticates |
| 113 // itself is called the 'token', and the one obtained when the host | 111 // itself is called the 'token', and the one obtained when the host |
| 114 // authenticates itself (using the 'token' received from the client and | 112 // authenticates itself (using the 'token' received from the client and |
| 115 // its private key) is called the 'shared secret'. | 113 // its private key) is called the 'shared secret'. |
| 116 // The client implicitly authenticates itself, and directly obtains the | 114 // The client implicitly authenticates itself, and directly obtains the |
| 117 // 'shared secret', along with the 'token' from the redirect URL fragment. | 115 // 'shared secret', along with the 'token' from the redirect URL fragment. |
| 118 token = queryArgs['code']; | 116 token = queryArgs['code']; |
| 119 sharedSecret = queryArgs['access_token']; | 117 sharedSecret = queryArgs['access_token']; |
| 120 } | |
| 121 } | 118 } |
| 122 this.onThirdPartyTokenFetched_(token, sharedSecret); | 119 this.onThirdPartyTokenFetched_(token, sharedSecret); |
| 123 }; | 120 }; |
| 124 | 121 |
| 125 /** | 122 /** |
| 126 * Build a full token request URL from the parameters in this object. | 123 * Build a full token request URL from the parameters in this object. |
| 127 * | 124 * |
| 128 * @return {string} Full URL to request a token. | 125 * @return {string} Full URL to request a token. |
| 129 * @private | 126 * @private |
| 130 */ | 127 */ |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 * Fetch a token from a token server using the identity.launchWebAuthFlow API. | 159 * Fetch a token from a token server using the identity.launchWebAuthFlow API. |
| 163 * @private | 160 * @private |
| 164 */ | 161 */ |
| 165 remoting.ThirdPartyTokenFetcher.prototype.fetchTokenIdentityApi_ = function() { | 162 remoting.ThirdPartyTokenFetcher.prototype.fetchTokenIdentityApi_ = function() { |
| 166 var fullTokenUrl = this.getFullTokenUrl_(); | 163 var fullTokenUrl = this.getFullTokenUrl_(); |
| 167 // TODO(rmsousa): chrome.identity.launchWebAuthFlow is experimental. | 164 // TODO(rmsousa): chrome.identity.launchWebAuthFlow is experimental. |
| 168 chrome.experimental.identity.launchWebAuthFlow( | 165 chrome.experimental.identity.launchWebAuthFlow( |
| 169 {'url': fullTokenUrl, 'interactive': true}, | 166 {'url': fullTokenUrl, 'interactive': true}, |
| 170 this.parseRedirectUrl_.bind(this)); | 167 this.parseRedirectUrl_.bind(this)); |
| 171 }; | 168 }; |
| OLD | NEW |