| 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 oauth2; | 5 library oauth2; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:uri'; | 9 import 'dart:uri'; |
| 10 | 10 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 return withClient(cache, fn); | 97 return withClient(cache, fn); |
| 98 } else { | 98 } else { |
| 99 throw error; | 99 throw error; |
| 100 } | 100 } |
| 101 }); | 101 }); |
| 102 } | 102 } |
| 103 | 103 |
| 104 /// Gets a new OAuth2 client. If saved credentials are available, those are | 104 /// Gets a new OAuth2 client. If saved credentials are available, those are |
| 105 /// used; otherwise, the user is prompted to authorize the pub client. | 105 /// used; otherwise, the user is prompted to authorize the pub client. |
| 106 Future<Client> _getClient(SystemCache cache) { | 106 Future<Client> _getClient(SystemCache cache) { |
| 107 return new Future.of(() { | 107 return new Future.sync(() { |
| 108 var credentials = _loadCredentials(cache); | 108 var credentials = _loadCredentials(cache); |
| 109 if (credentials == null) return _authorize(); | 109 if (credentials == null) return _authorize(); |
| 110 | 110 |
| 111 var client = new Client(_identifier, _secret, credentials, | 111 var client = new Client(_identifier, _secret, credentials, |
| 112 httpClient: httpClient); | 112 httpClient: httpClient); |
| 113 _saveCredentials(cache, client.credentials); | 113 _saveCredentials(cache, client.credentials); |
| 114 return client; | 114 return client; |
| 115 }); | 115 }); |
| 116 } | 116 } |
| 117 | 117 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 response.statusCode = 404; | 197 response.statusCode = 404; |
| 198 response.close(); | 198 response.close(); |
| 199 } | 199 } |
| 200 }); | 200 }); |
| 201 }) | 201 }) |
| 202 .then((client) { | 202 .then((client) { |
| 203 log.message('Successfully authorized.\n'); | 203 log.message('Successfully authorized.\n'); |
| 204 return client; | 204 return client; |
| 205 }); | 205 }); |
| 206 } | 206 } |
| OLD | NEW |