| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 /// Loads the user's OAuth2 credentials from the in-memory cache or the | 111 /// Loads the user's OAuth2 credentials from the in-memory cache or the |
| 112 /// filesystem if possible. If the credentials can't be loaded for any reason, | 112 /// filesystem if possible. If the credentials can't be loaded for any reason, |
| 113 /// the returned [Future] will complete to null. | 113 /// the returned [Future] will complete to null. |
| 114 Credentials _loadCredentials(SystemCache cache) { | 114 Credentials _loadCredentials(SystemCache cache) { |
| 115 log.fine('Loading OAuth2 credentials.'); | 115 log.fine('Loading OAuth2 credentials.'); |
| 116 | 116 |
| 117 try { | 117 try { |
| 118 if (_credentials != null) return _credentials; | 118 if (_credentials != null) return _credentials; |
| 119 | 119 |
| 120 var path = _credentialsFile(cache); | 120 var path = _credentialsFile(cache); |
| 121 if (!fileExists(path)) return; | 121 if (!fileExists(path)) return null; |
| 122 | 122 |
| 123 var credentials = new Credentials.fromJson(readTextFile(path)); | 123 var credentials = new Credentials.fromJson(readTextFile(path)); |
| 124 if (credentials.isExpired && !credentials.canRefresh) { | 124 if (credentials.isExpired && !credentials.canRefresh) { |
| 125 log.error("Pub's authorization to upload packages has expired and " | 125 log.error("Pub's authorization to upload packages has expired and " |
| 126 "can't be automatically refreshed."); | 126 "can't be automatically refreshed."); |
| 127 return null; // null means re-authorize. | 127 return null; // null means re-authorize. |
| 128 } | 128 } |
| 129 | 129 |
| 130 return credentials; | 130 return credentials; |
| 131 } catch (e) { | 131 } catch (e) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 'Pub needs your authorization to upload packages on your behalf.\n' | 196 'Pub needs your authorization to upload packages on your behalf.\n' |
| 197 'In a web browser, go to $authUrl\n' | 197 'In a web browser, go to $authUrl\n' |
| 198 'Then click "Allow access".\n\n' | 198 'Then click "Allow access".\n\n' |
| 199 'Waiting for your authorization...'); | 199 'Waiting for your authorization...'); |
| 200 | 200 |
| 201 return completer.future.then((client) { | 201 return completer.future.then((client) { |
| 202 log.message('Successfully authorized.\n'); | 202 log.message('Successfully authorized.\n'); |
| 203 return client; | 203 return client; |
| 204 }); | 204 }); |
| 205 } | 205 } |
| OLD | NEW |