| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // TODO(jamiewalch): Fix this once we're no longer using the trampoline. | 82 // TODO(jamiewalch): Fix this once we're no longer using the trampoline. |
| 83 var tokens = JSON.parse(xhr.responseText); | 83 var tokens = JSON.parse(xhr.responseText); |
| 84 onDone(tokens['access_token'], tokens['expires_in']); | 84 onDone(tokens['access_token'], tokens['expires_in']); |
| 85 } catch (/** @type {Error} */ err) { | 85 } catch (/** @type {Error} */ err) { |
| 86 console.error('Invalid "token" response from server:', err); | 86 console.error('Invalid "token" response from server:', err); |
| 87 onError(remoting.Error.UNEXPECTED); | 87 onError(remoting.Error.UNEXPECTED); |
| 88 } | 88 } |
| 89 } else { | 89 } else { |
| 90 console.error('Failed to refresh token. Status: ' + xhr.status + | 90 console.error('Failed to refresh token. Status: ' + xhr.status + |
| 91 ' response: ' + xhr.responseText); | 91 ' response: ' + xhr.responseText); |
| 92 onError(remoting.Error.fromHttpError(xhr.status)); | 92 onError(remoting.Error.fromHttpStatus(xhr.status)); |
| 93 } | 93 } |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 var parameters = { | 96 var parameters = { |
| 97 'client_id': clientId, | 97 'client_id': clientId, |
| 98 'client_secret': clientSecret, | 98 'client_secret': clientSecret, |
| 99 'refresh_token': refreshToken, | 99 'refresh_token': refreshToken, |
| 100 'grant_type': 'refresh_token' | 100 'grant_type': 'refresh_token' |
| 101 }; | 101 }; |
| 102 | 102 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 129 var tokens = JSON.parse(xhr.responseText); | 129 var tokens = JSON.parse(xhr.responseText); |
| 130 onDone(tokens['refresh_token'], | 130 onDone(tokens['refresh_token'], |
| 131 tokens['access_token'], tokens['expires_in']); | 131 tokens['access_token'], tokens['expires_in']); |
| 132 } catch (/** @type {Error} */ err) { | 132 } catch (/** @type {Error} */ err) { |
| 133 console.error('Invalid "token" response from server:', err); | 133 console.error('Invalid "token" response from server:', err); |
| 134 onError(remoting.Error.UNEXPECTED); | 134 onError(remoting.Error.UNEXPECTED); |
| 135 } | 135 } |
| 136 } else { | 136 } else { |
| 137 console.error('Failed to exchange code for token. Status: ' + xhr.status + | 137 console.error('Failed to exchange code for token. Status: ' + xhr.status + |
| 138 ' response: ' + xhr.responseText); | 138 ' response: ' + xhr.responseText); |
| 139 onError(remoting.Error.fromHttpError(xhr.status)); | 139 onError(remoting.Error.fromHttpStatus(xhr.status)); |
| 140 } | 140 } |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 var parameters = { | 143 var parameters = { |
| 144 'client_id': clientId, | 144 'client_id': clientId, |
| 145 'client_secret': clientSecret, | 145 'client_secret': clientSecret, |
| 146 'redirect_uri': redirectUri, | 146 'redirect_uri': redirectUri, |
| 147 'code': code, | 147 'code': code, |
| 148 'grant_type': 'authorization_code' | 148 'grant_type': 'authorization_code' |
| 149 }; | 149 }; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 167 try { | 167 try { |
| 168 var result = JSON.parse(xhr.responseText); | 168 var result = JSON.parse(xhr.responseText); |
| 169 onDone(result['email']); | 169 onDone(result['email']); |
| 170 } catch (/** @type {Error} */ err) { | 170 } catch (/** @type {Error} */ err) { |
| 171 console.error('Invalid "userinfo" response from server:', err); | 171 console.error('Invalid "userinfo" response from server:', err); |
| 172 onError(remoting.Error.UNEXPECTED); | 172 onError(remoting.Error.UNEXPECTED); |
| 173 } | 173 } |
| 174 } else { | 174 } else { |
| 175 console.error('Failed to get email. Status: ' + xhr.status + | 175 console.error('Failed to get email. Status: ' + xhr.status + |
| 176 ' response: ' + xhr.responseText); | 176 ' response: ' + xhr.responseText); |
| 177 onError(remoting.Error.fromHttpError(xhr.status)); | 177 onError(remoting.Error.fromHttpStatus(xhr.status)); |
| 178 } | 178 } |
| 179 }; | 179 }; |
| 180 var headers = { 'Authorization': 'OAuth ' + token }; | 180 var headers = { 'Authorization': 'OAuth ' + token }; |
| 181 remoting.xhr.get(this.getOAuth2ApiUserInfoEndpoint_(), | 181 remoting.xhr.get(this.getOAuth2ApiUserInfoEndpoint_(), |
| 182 onResponse, '', headers); | 182 onResponse, '', headers); |
| 183 }; | 183 }; |
| 184 | 184 |
| 185 /** | 185 /** |
| 186 * Get the user's email address and full name. | 186 * Get the user's email address and full name. |
| 187 * | 187 * |
| (...skipping 12 matching lines...) Expand all Loading... |
| 200 try { | 200 try { |
| 201 var result = JSON.parse(xhr.responseText); | 201 var result = JSON.parse(xhr.responseText); |
| 202 onDone(result['email'], result['name']); | 202 onDone(result['email'], result['name']); |
| 203 } catch (/** @type {Error} */ err) { | 203 } catch (/** @type {Error} */ err) { |
| 204 console.error('Invalid "userinfo" response from server:', err); | 204 console.error('Invalid "userinfo" response from server:', err); |
| 205 onError(remoting.Error.UNEXPECTED); | 205 onError(remoting.Error.UNEXPECTED); |
| 206 } | 206 } |
| 207 } else { | 207 } else { |
| 208 console.error('Failed to get user info. Status: ' + xhr.status + | 208 console.error('Failed to get user info. Status: ' + xhr.status + |
| 209 ' response: ' + xhr.responseText); | 209 ' response: ' + xhr.responseText); |
| 210 onError(remoting.Error.fromHttpError(xhr.status)); | 210 onError(remoting.Error.fromHttpStatus(xhr.status)); |
| 211 } | 211 } |
| 212 }; | 212 }; |
| 213 var headers = { 'Authorization': 'OAuth ' + token }; | 213 var headers = { 'Authorization': 'OAuth ' + token }; |
| 214 remoting.xhr.get(this.getOAuth2ApiUserInfoEndpoint_(), | 214 remoting.xhr.get(this.getOAuth2ApiUserInfoEndpoint_(), |
| 215 onResponse, '', headers); | 215 onResponse, '', headers); |
| 216 }; | 216 }; |
| 217 | 217 |
| 218 /** @type {remoting.OAuth2Api} */ | 218 /** @type {remoting.OAuth2Api} */ |
| 219 remoting.oauth2Api = new remoting.OAuth2ApiImpl(); | 219 remoting.oauth2Api = new remoting.OAuth2ApiImpl(); |
| OLD | NEW |