Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: utils/pub/oauth2.dart

Issue 11778108: Stop working around issue 7790 in pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/pub/io.dart ('k') | utils/pub/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 /// Asynchronously passes an OAuth2 [Client] to [fn], and closes the client when 63 /// Asynchronously passes an OAuth2 [Client] to [fn], and closes the client when
64 /// the [Future] returned by [fn] completes. 64 /// the [Future] returned by [fn] completes.
65 /// 65 ///
66 /// This takes care of loading and saving the client's credentials, as well as 66 /// This takes care of loading and saving the client's credentials, as well as
67 /// prompting the user for their authorization. It will also re-authorize and 67 /// prompting the user for their authorization. It will also re-authorize and
68 /// re-run [fn] if a recoverable authorization error is detected. 68 /// re-run [fn] if a recoverable authorization error is detected.
69 Future withClient(SystemCache cache, Future fn(Client client)) { 69 Future withClient(SystemCache cache, Future fn(Client client)) {
70 return _getClient(cache).then((client) { 70 return _getClient(cache).then((client) {
71 var completer = new Completer(); 71 var completer = new Completer();
72 return asyncWhenComplete(fn(client), () { 72 return fn(client).whenComplete(() {
73 client.close(); 73 client.close();
74 // Be sure to save the credentials even when an error happens. 74 // Be sure to save the credentials even when an error happens.
75 return _saveCredentials(cache, client.credentials); 75 return _saveCredentials(cache, client.credentials);
76 }); 76 });
77 }).catchError((asyncError) { 77 }).catchError((asyncError) {
78 var e = getRealError(asyncError); 78 var e = getRealError(asyncError);
79 if (e is ExpirationException) { 79 if (e is ExpirationException) {
80 log.error("Pub's authorization to upload packages has expired and " 80 log.error("Pub's authorization to upload packages has expired and "
81 "can't be automatically refreshed."); 81 "can't be automatically refreshed.");
82 return withClient(cache, fn); 82 return withClient(cache, fn);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 'Pub needs your authorization to upload packages on your behalf.\n' 199 'Pub needs your authorization to upload packages on your behalf.\n'
200 'In a web browser, go to $authUrl\n' 200 'In a web browser, go to $authUrl\n'
201 'Then click "Allow access".\n\n' 201 'Then click "Allow access".\n\n'
202 'Waiting for your authorization...'); 202 'Waiting for your authorization...');
203 203
204 return completer.future.then((client) { 204 return completer.future.then((client) {
205 log.message('Successfully authorized.\n'); 205 log.message('Successfully authorized.\n');
206 return client; 206 return client;
207 }); 207 });
208 } 208 }
OLDNEW
« no previous file with comments | « utils/pub/io.dart ('k') | utils/pub/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698