| 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 |
| 11 // TODO(nweiz): Make this a "package:" URL, or something nicer than this. | 11 // TODO(nweiz): Make this a "package:" URL, or something nicer than this. |
| 12 import '../../pkg/oauth2/lib/oauth2.dart'; | 12 import '../../pkg/oauth2/lib/oauth2.dart'; |
| 13 import '../../pkg/path/lib/path.dart' as path; |
| 14 |
| 13 import 'http.dart'; | 15 import 'http.dart'; |
| 14 import 'io.dart'; | 16 import 'io.dart'; |
| 15 import 'log.dart' as log; | 17 import 'log.dart' as log; |
| 16 import 'system_cache.dart'; | 18 import 'system_cache.dart'; |
| 17 import 'utils.dart'; | 19 import 'utils.dart'; |
| 18 | 20 |
| 19 export '../../pkg/oauth2/lib/oauth2.dart'; | 21 export '../../pkg/oauth2/lib/oauth2.dart'; |
| 20 | 22 |
| 21 /// The pub client's OAuth2 identifier. | 23 /// The pub client's OAuth2 identifier. |
| 22 final _identifier = '818368855108-8grd2eg9tj9f38os6f1urbcvsq399u8n.apps.' | 24 final _identifier = '818368855108-8grd2eg9tj9f38os6f1urbcvsq399u8n.apps.' |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 'Obtaining new credentials...'); | 133 'Obtaining new credentials...'); |
| 132 return null; // null means re-authorize. | 134 return null; // null means re-authorize. |
| 133 } | 135 } |
| 134 } | 136 } |
| 135 | 137 |
| 136 /// Save the user's OAuth2 credentials to the in-memory cache and the | 138 /// Save the user's OAuth2 credentials to the in-memory cache and the |
| 137 /// filesystem. | 139 /// filesystem. |
| 138 void _saveCredentials(SystemCache cache, Credentials credentials) { | 140 void _saveCredentials(SystemCache cache, Credentials credentials) { |
| 139 log.fine('Saving OAuth2 credentials.'); | 141 log.fine('Saving OAuth2 credentials.'); |
| 140 _credentials = credentials; | 142 _credentials = credentials; |
| 141 var path = _credentialsFile(cache); | 143 var credentialsPath = _credentialsFile(cache); |
| 142 ensureDir(dirname(path)); | 144 ensureDir(path.dirname(credentialsPath)); |
| 143 writeTextFile(path, credentials.toJson(), dontLogContents: true); | 145 writeTextFile(credentialsPath, credentials.toJson(), dontLogContents: true); |
| 144 } | 146 } |
| 145 | 147 |
| 146 /// The path to the file in which the user's OAuth2 credentials are stored. | 148 /// The path to the file in which the user's OAuth2 credentials are stored. |
| 147 String _credentialsFile(SystemCache cache) => | 149 String _credentialsFile(SystemCache cache) => |
| 148 join(cache.rootDir, 'credentials.json'); | 150 join(cache.rootDir, 'credentials.json'); |
| 149 | 151 |
| 150 /// Gets the user to authorize pub as a client of pub.dartlang.org via oauth2. | 152 /// Gets the user to authorize pub as a client of pub.dartlang.org via oauth2. |
| 151 /// Returns a Future that will complete to a fully-authorized [Client]. | 153 /// Returns a Future that will complete to a fully-authorized [Client]. |
| 152 Future<Client> _authorize() { | 154 Future<Client> _authorize() { |
| 153 // Allow the tests to inject their own token endpoint URL. | 155 // Allow the tests to inject their own token endpoint URL. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 'Pub needs your authorization to upload packages on your behalf.\n' | 196 'Pub needs your authorization to upload packages on your behalf.\n' |
| 195 'In a web browser, go to $authUrl\n' | 197 'In a web browser, go to $authUrl\n' |
| 196 'Then click "Allow access".\n\n' | 198 'Then click "Allow access".\n\n' |
| 197 'Waiting for your authorization...'); | 199 'Waiting for your authorization...'); |
| 198 | 200 |
| 199 return completer.future.then((client) { | 201 return completer.future.then((client) { |
| 200 log.message('Successfully authorized.\n'); | 202 log.message('Successfully authorized.\n'); |
| 201 return client; | 203 return client; |
| 202 }); | 204 }); |
| 203 } | 205 } |
| OLD | NEW |