| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 final _scopes = ['https://www.googleapis.com/auth/userinfo.email']; | 59 final _scopes = ['https://www.googleapis.com/auth/userinfo.email']; |
| 60 | 60 |
| 61 /// An in-memory cache of the user's OAuth2 credentials. This should always be | 61 /// An in-memory cache of the user's OAuth2 credentials. This should always be |
| 62 /// the same as the credentials file stored in the system cache. | 62 /// the same as the credentials file stored in the system cache. |
| 63 Credentials _credentials; | 63 Credentials _credentials; |
| 64 | 64 |
| 65 /// Delete the cached credentials, if they exist. | 65 /// Delete the cached credentials, if they exist. |
| 66 void clearCredentials(SystemCache cache) { | 66 void clearCredentials(SystemCache cache) { |
| 67 _credentials = null; | 67 _credentials = null; |
| 68 var credentialsFile = _credentialsFile(cache); | 68 var credentialsFile = _credentialsFile(cache); |
| 69 if (!fileExists(credentialsFile)) return; | 69 if (entryExists(credentialsFile)) deleteEntry(credentialsFile); |
| 70 | |
| 71 deleteFile(credentialsFile); | |
| 72 } | 70 } |
| 73 | 71 |
| 74 /// Asynchronously passes an OAuth2 [Client] to [fn], and closes the client when | 72 /// Asynchronously passes an OAuth2 [Client] to [fn], and closes the client when |
| 75 /// the [Future] returned by [fn] completes. | 73 /// the [Future] returned by [fn] completes. |
| 76 /// | 74 /// |
| 77 /// This takes care of loading and saving the client's credentials, as well as | 75 /// This takes care of loading and saving the client's credentials, as well as |
| 78 /// prompting the user for their authorization. It will also re-authorize and | 76 /// prompting the user for their authorization. It will also re-authorize and |
| 79 /// re-run [fn] if a recoverable authorization error is detected. | 77 /// re-run [fn] if a recoverable authorization error is detected. |
| 80 Future withClient(SystemCache cache, Future fn(Client client)) { | 78 Future withClient(SystemCache cache, Future fn(Client client)) { |
| 81 return _getClient(cache).then((client) { | 79 return _getClient(cache).then((client) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 response.statusCode = 404; | 198 response.statusCode = 404; |
| 201 response.close(); | 199 response.close(); |
| 202 } | 200 } |
| 203 }); | 201 }); |
| 204 }) | 202 }) |
| 205 .then((client) { | 203 .then((client) { |
| 206 log.message('Successfully authorized.\n'); | 204 log.message('Successfully authorized.\n'); |
| 207 return client; | 205 return client; |
| 208 }); | 206 }); |
| 209 } | 207 } |
| OLD | NEW |