| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library handle_access_token_response; | 5 library handle_access_token_response; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart:json' as JSON; | 8 import 'dart:json' as JSON; |
| 9 import 'dart:uri'; | 9 import 'dart:uri'; |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 Uri tokenEndpoint, | 26 Uri tokenEndpoint, |
| 27 DateTime startTime, | 27 DateTime startTime, |
| 28 List<String> scopes) { | 28 List<String> scopes) { |
| 29 if (response.statusCode != 200) _handleErrorResponse(response, tokenEndpoint); | 29 if (response.statusCode != 200) _handleErrorResponse(response, tokenEndpoint); |
| 30 | 30 |
| 31 void validate(bool condition, String message) => | 31 void validate(bool condition, String message) => |
| 32 _validate(response, tokenEndpoint, condition, message); | 32 _validate(response, tokenEndpoint, condition, message); |
| 33 | 33 |
| 34 var contentType = response.headers['content-type']; | 34 var contentType = response.headers['content-type']; |
| 35 if (contentType != null) { | 35 if (contentType != null) { |
| 36 contentType = new ContentType.fromString(contentType); | 36 contentType = ContentType.parse(contentType); |
| 37 } | 37 } |
| 38 validate(contentType != null && contentType.value == "application/json", | 38 validate(contentType != null && contentType.value == "application/json", |
| 39 'content-type was "$contentType", expected "application/json"'); | 39 'content-type was "$contentType", expected "application/json"'); |
| 40 | 40 |
| 41 var parameters; | 41 var parameters; |
| 42 try { | 42 try { |
| 43 parameters = JSON.parse(response.body); | 43 parameters = JSON.parse(response.body); |
| 44 } catch (e) { | 44 } catch (e) { |
| 45 // TODO(nweiz): narrow this catch clause once issue 6775 is fixed. | 45 // TODO(nweiz): narrow this catch clause once issue 6775 is fixed. |
| 46 validate(false, 'invalid JSON'); | 46 validate(false, 'invalid JSON'); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 var reason = ''; | 96 var reason = ''; |
| 97 if (response.reasonPhrase != null && !response.reasonPhrase.isEmpty) { | 97 if (response.reasonPhrase != null && !response.reasonPhrase.isEmpty) { |
| 98 ' ${response.reasonPhrase}'; | 98 ' ${response.reasonPhrase}'; |
| 99 } | 99 } |
| 100 throw new FormatException('OAuth request for "$tokenEndpoint" failed ' | 100 throw new FormatException('OAuth request for "$tokenEndpoint" failed ' |
| 101 'with status ${response.statusCode}$reason.\n\n${response.body}'); | 101 'with status ${response.statusCode}$reason.\n\n${response.body}'); |
| 102 } | 102 } |
| 103 | 103 |
| 104 var contentType = response.headers['content-type']; | 104 var contentType = response.headers['content-type']; |
| 105 if (contentType != null) { | 105 if (contentType != null) { |
| 106 contentType = new ContentType.fromString(contentType); | 106 contentType = ContentType.parse(contentType); |
| 107 } | 107 } |
| 108 validate(contentType != null && contentType.value == "application/json", | 108 validate(contentType != null && contentType.value == "application/json", |
| 109 'content-type was "$contentType", expected "application/json"'); | 109 'content-type was "$contentType", expected "application/json"'); |
| 110 | 110 |
| 111 var parameters; | 111 var parameters; |
| 112 try { | 112 try { |
| 113 parameters = JSON.parse(response.body); | 113 parameters = JSON.parse(response.body); |
| 114 } catch (e) { | 114 } catch (e) { |
| 115 // TODO(nweiz): narrow this catch clause once issue 6775 is fixed. | 115 // TODO(nweiz): narrow this catch clause once issue 6775 is fixed. |
| 116 validate(false, 'invalid JSON'); | 116 validate(false, 'invalid JSON'); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 136 | 136 |
| 137 void _validate( | 137 void _validate( |
| 138 http.Response response, | 138 http.Response response, |
| 139 Uri tokenEndpoint, | 139 Uri tokenEndpoint, |
| 140 bool condition, | 140 bool condition, |
| 141 String message) { | 141 String message) { |
| 142 if (condition) return; | 142 if (condition) return; |
| 143 throw new FormatException('Invalid OAuth response for "$tokenEndpoint": ' | 143 throw new FormatException('Invalid OAuth response for "$tokenEndpoint": ' |
| 144 '$message.\n\n${response.body}'); | 144 '$message.\n\n${response.body}'); |
| 145 } | 145 } |
| OLD | NEW |