| 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 credentials; | 5 library credentials; |
| 6 | 6 |
| 7 import 'dart:json'; | 7 import 'dart:json'; |
| 8 import 'dart:uri'; | 8 import 'dart:uri'; |
| 9 | 9 |
| 10 import '../../../http/lib/http.dart' as http; | 10 import '../../../http/lib/http.dart' as http; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 void validate(bool condition, String message) { | 73 void validate(bool condition, String message) { |
| 74 if (condition) return; | 74 if (condition) return; |
| 75 throw new FormatException( | 75 throw new FormatException( |
| 76 "Failed to load credentials: $message.\n\n$json"); | 76 "Failed to load credentials: $message.\n\n$json"); |
| 77 } | 77 } |
| 78 | 78 |
| 79 var parsed; | 79 var parsed; |
| 80 try { | 80 try { |
| 81 parsed = JSON.parse(json); | 81 parsed = JSON.parse(json); |
| 82 } catch (e) { | 82 } catch (e) { |
| 83 // TODO(nweiz): narrow this catch clause once issue 6775 is fixed. |
| 83 validate(false, 'invalid JSON'); | 84 validate(false, 'invalid JSON'); |
| 84 } | 85 } |
| 85 | 86 |
| 86 validate(parsed is Map, 'was not a JSON map'); | 87 validate(parsed is Map, 'was not a JSON map'); |
| 87 validate(parsed.containsKey('accessToken'), | 88 validate(parsed.containsKey('accessToken'), |
| 88 'did not contain required field "accessToken"'); | 89 'did not contain required field "accessToken"'); |
| 89 validate(parsed['accessToken'] is String, | 90 validate(parsed['accessToken'] is String, |
| 90 'required field "accessToken" was not a string, was ' | 91 'required field "accessToken" was not a string, was ' |
| 91 '${parsed["accessToken"]}'); | 92 '${parsed["accessToken"]}'); |
| 92 | 93 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 if (credentials.refreshToken != null) return credentials; | 182 if (credentials.refreshToken != null) return credentials; |
| 182 return new Credentials( | 183 return new Credentials( |
| 183 credentials.accessToken, | 184 credentials.accessToken, |
| 184 this.refreshToken, | 185 this.refreshToken, |
| 185 credentials.tokenEndpoint, | 186 credentials.tokenEndpoint, |
| 186 credentials.scopes, | 187 credentials.scopes, |
| 187 credentials.expiration); | 188 credentials.expiration); |
| 188 }); | 189 }); |
| 189 } | 190 } |
| 190 } | 191 } |
| OLD | NEW |