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:io'; | 7 import 'dart:io'; |
8 import 'dart:uri'; | 8 import 'dart:uri'; |
9 | 9 |
10 // TODO(nweiz): Make this a "package:" URL, or something nicer than this. | 10 // TODO(nweiz): Make this a "package:" URL, or something nicer than this. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 }); | 132 }); |
133 } | 133 } |
134 | 134 |
135 /// Save the user's OAuth2 credentials to the in-memory cache and the | 135 /// Save the user's OAuth2 credentials to the in-memory cache and the |
136 /// filesystem. | 136 /// filesystem. |
137 Future _saveCredentials(SystemCache cache, Credentials credentials) { | 137 Future _saveCredentials(SystemCache cache, Credentials credentials) { |
138 log.fine('Saving OAuth2 credentials.'); | 138 log.fine('Saving OAuth2 credentials.'); |
139 _credentials = credentials; | 139 _credentials = credentials; |
140 var path = _credentialsFile(cache); | 140 var path = _credentialsFile(cache); |
141 return ensureDir(dirname(path)).chain((_) => | 141 return ensureDir(dirname(path)).chain((_) => |
142 writeTextFile(path, credentials.toJson())); | 142 writeTextFile(path, credentials.toJson(), dontLogContents: true)); |
143 } | 143 } |
144 | 144 |
145 /// The path to the file in which the user's OAuth2 credentials are stored. | 145 /// The path to the file in which the user's OAuth2 credentials are stored. |
146 String _credentialsFile(SystemCache cache) => | 146 String _credentialsFile(SystemCache cache) => |
147 join(cache.rootDir, 'credentials.json'); | 147 join(cache.rootDir, 'credentials.json'); |
148 | 148 |
149 /// Gets the user to authorize pub as a client of pub.dartlang.org via oauth2. | 149 /// Gets the user to authorize pub as a client of pub.dartlang.org via oauth2. |
150 /// Returns a Future that will complete to a fully-authorized [Client]. | 150 /// Returns a Future that will complete to a fully-authorized [Client]. |
151 Future<Client> _authorize() { | 151 Future<Client> _authorize() { |
152 // Allow the tests to inject their own token endpoint URL. | 152 // Allow the tests to inject their own token endpoint URL. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 'Pub needs your authorization to upload packages on your behalf.\n' | 193 'Pub needs your authorization to upload packages on your behalf.\n' |
194 'In a web browser, go to $authUrl\n' | 194 'In a web browser, go to $authUrl\n' |
195 'Then click "Allow access".\n\n' | 195 'Then click "Allow access".\n\n' |
196 'Waiting for your authorization...'); | 196 'Waiting for your authorization...'); |
197 | 197 |
198 return completer.future.transform((client) { | 198 return completer.future.transform((client) { |
199 log.message('Successfully authorized.\n'); | 199 log.message('Successfully authorized.\n'); |
200 return client; | 200 return client; |
201 }); | 201 }); |
202 } | 202 } |
OLD | NEW |