| 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 * OAuth2 API flow implementations. | 7 * OAuth2 API flow implementations. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 'use strict'; | 10 'use strict'; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 * @param {string} clientSecret OAuth2 client secret. | 67 * @param {string} clientSecret OAuth2 client secret. |
| 68 * @param {string} refreshToken OAuth2 refresh token to be redeemed. | 68 * @param {string} refreshToken OAuth2 refresh token to be redeemed. |
| 69 * @return {void} Nothing. | 69 * @return {void} Nothing. |
| 70 */ | 70 */ |
| 71 remoting.OAuth2Api.refreshAccessToken = function( | 71 remoting.OAuth2Api.refreshAccessToken = function( |
| 72 onDone, onError, clientId, clientSecret, refreshToken) { | 72 onDone, onError, clientId, clientSecret, refreshToken) { |
| 73 /** @param {XMLHttpRequest} xhr */ | 73 /** @param {XMLHttpRequest} xhr */ |
| 74 var onResponse = function(xhr) { | 74 var onResponse = function(xhr) { |
| 75 if (xhr.status == 200) { | 75 if (xhr.status == 200) { |
| 76 try { | 76 try { |
| 77 // Don't use jsonParseSafe here unless you move the definition out of | 77 // Don't use base.jsonParseSafe here unless you also include base.js, |
| 78 // remoting.js, otherwise this won't work from the OAuth trampoline. | 78 // otherwise this won't work from the OAuth trampoline. |
| 79 // TODO(jamiewalch): Fix this once we're no longer using the trampoline. | 79 // TODO(jamiewalch): Fix this once we're no longer using the trampoline. |
| 80 var tokens = JSON.parse(xhr.responseText); | 80 var tokens = JSON.parse(xhr.responseText); |
| 81 onDone(tokens['access_token'], tokens['expires_in']); | 81 onDone(tokens['access_token'], tokens['expires_in']); |
| 82 } catch (err) { | 82 } catch (err) { |
| 83 console.error('Invalid "token" response from server:', | 83 console.error('Invalid "token" response from server:', |
| 84 /** @type {*} */ (err)); | 84 /** @type {*} */ (err)); |
| 85 onError(remoting.Error.UNEXPECTED); | 85 onError(remoting.Error.UNEXPECTED); |
| 86 } | 86 } |
| 87 } else { | 87 } else { |
| 88 console.error('Failed to refresh token. Status: ' + xhr.status + | 88 console.error('Failed to refresh token. Status: ' + xhr.status + |
| (...skipping 26 matching lines...) Expand all Loading... |
| 115 * @param {string} code OAuth2 authorization code. | 115 * @param {string} code OAuth2 authorization code. |
| 116 * @param {string} redirectUri Redirect URI used to obtain this code. | 116 * @param {string} redirectUri Redirect URI used to obtain this code. |
| 117 * @return {void} Nothing. | 117 * @return {void} Nothing. |
| 118 */ | 118 */ |
| 119 remoting.OAuth2Api.exchangeCodeForTokens = function( | 119 remoting.OAuth2Api.exchangeCodeForTokens = function( |
| 120 onDone, onError, clientId, clientSecret, code, redirectUri) { | 120 onDone, onError, clientId, clientSecret, code, redirectUri) { |
| 121 /** @param {XMLHttpRequest} xhr */ | 121 /** @param {XMLHttpRequest} xhr */ |
| 122 var onResponse = function(xhr) { | 122 var onResponse = function(xhr) { |
| 123 if (xhr.status == 200) { | 123 if (xhr.status == 200) { |
| 124 try { | 124 try { |
| 125 // Don't use jsonParseSafe here unless you move the definition out of | 125 // Don't use base.jsonParseSafe here unless you also include base.js, |
| 126 // remoting.js, otherwise this won't work from the OAuth trampoline. | 126 // otherwise this won't work from the OAuth trampoline. |
| 127 // TODO(jamiewalch): Fix this once we're no longer using the trampoline. | 127 // TODO(jamiewalch): Fix this once we're no longer using the trampoline. |
| 128 var tokens = JSON.parse(xhr.responseText); | 128 var tokens = JSON.parse(xhr.responseText); |
| 129 onDone(tokens['refresh_token'], | 129 onDone(tokens['refresh_token'], |
| 130 tokens['access_token'], tokens['expires_in']); | 130 tokens['access_token'], tokens['expires_in']); |
| 131 } catch (err) { | 131 } catch (err) { |
| 132 console.error('Invalid "token" response from server:', | 132 console.error('Invalid "token" response from server:', |
| 133 /** @type {*} */ (err)); | 133 /** @type {*} */ (err)); |
| 134 onError(remoting.Error.UNEXPECTED); | 134 onError(remoting.Error.UNEXPECTED); |
| 135 } | 135 } |
| 136 } else { | 136 } else { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 } else { | 176 } else { |
| 177 console.error('Failed to get email. Status: ' + xhr.status + | 177 console.error('Failed to get email. Status: ' + xhr.status + |
| 178 ' response: ' + xhr.responseText); | 178 ' response: ' + xhr.responseText); |
| 179 onError(remoting.OAuth2Api.interpretXhrStatus_(xhr.status)); | 179 onError(remoting.OAuth2Api.interpretXhrStatus_(xhr.status)); |
| 180 } | 180 } |
| 181 }; | 181 }; |
| 182 var headers = { 'Authorization': 'OAuth ' + token }; | 182 var headers = { 'Authorization': 'OAuth ' + token }; |
| 183 remoting.xhr.get(remoting.OAuth2Api.getOAuth2ApiUserInfoEndpoint_(), | 183 remoting.xhr.get(remoting.OAuth2Api.getOAuth2ApiUserInfoEndpoint_(), |
| 184 onResponse, '', headers); | 184 onResponse, '', headers); |
| 185 }; | 185 }; |
| OLD | NEW |