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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 void _saveCredentials(SystemCache cache, Credentials credentials) { | 140 void _saveCredentials(SystemCache cache, Credentials credentials) { |
141 log.fine('Saving OAuth2 credentials.'); | 141 log.fine('Saving OAuth2 credentials.'); |
142 _credentials = credentials; | 142 _credentials = credentials; |
143 var credentialsPath = _credentialsFile(cache); | 143 var credentialsPath = _credentialsFile(cache); |
144 ensureDir(path.dirname(credentialsPath)); | 144 ensureDir(path.dirname(credentialsPath)); |
145 writeTextFile(credentialsPath, credentials.toJson(), dontLogContents: true); | 145 writeTextFile(credentialsPath, credentials.toJson(), dontLogContents: true); |
146 } | 146 } |
147 | 147 |
148 /// 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. |
149 String _credentialsFile(SystemCache cache) => | 149 String _credentialsFile(SystemCache cache) => |
150 join(cache.rootDir, 'credentials.json'); | 150 path.join(cache.rootDir, 'credentials.json'); |
151 | 151 |
152 /// 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. |
153 /// Returns a Future that will complete to a fully-authorized [Client]. | 153 /// Returns a Future that will complete to a fully-authorized [Client]. |
154 Future<Client> _authorize() { | 154 Future<Client> _authorize() { |
155 // Allow the tests to inject their own token endpoint URL. | 155 // Allow the tests to inject their own token endpoint URL. |
156 var tokenEndpoint = Platform.environment['_PUB_TEST_TOKEN_ENDPOINT']; | 156 var tokenEndpoint = Platform.environment['_PUB_TEST_TOKEN_ENDPOINT']; |
157 if (tokenEndpoint != null) { | 157 if (tokenEndpoint != null) { |
158 tokenEndpoint = Uri.parse(tokenEndpoint); | 158 tokenEndpoint = Uri.parse(tokenEndpoint); |
159 } else { | 159 } else { |
160 tokenEndpoint = _tokenEndpoint; | 160 tokenEndpoint = _tokenEndpoint; |
(...skipping 35 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 |