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

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

Issue 11416352: Handle OAuth2 AuthorizationExceptions in pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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
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: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 29 matching lines...) Expand all
40 'https://accounts.google.com/o/oauth2/token'); 40 'https://accounts.google.com/o/oauth2/token');
41 41
42 /// The OAuth2 scopes that the pub client needs. Currently the client only needs 42 /// The OAuth2 scopes that the pub client needs. Currently the client only needs
43 /// the user's email so that the server can verify their identity. 43 /// the user's email so that the server can verify their identity.
44 final _scopes = ['https://www.googleapis.com/auth/userinfo.email']; 44 final _scopes = ['https://www.googleapis.com/auth/userinfo.email'];
45 45
46 /// An in-memory cache of the user's OAuth2 credentials. This should always be 46 /// An in-memory cache of the user's OAuth2 credentials. This should always be
47 /// the same as the credentials file stored in the system cache. 47 /// the same as the credentials file stored in the system cache.
48 Credentials _credentials; 48 Credentials _credentials;
49 49
50 /// Delete the cached credentials, if they exist.
51 Future clearCredentials(SystemCache cache) {
52 _credentials = null;
53 var credentialsFile = _credentialsFile(cache);
54 return fileExists(credentialsFile).chain((exists) {
55 if (exists) return deleteFile(credentialsFile);
56 return new Future.immediate(null);
57 });
58 }
59
50 /// Asynchronously passes an OAuth2 [Client] to [fn], and closes the client when 60 /// Asynchronously passes an OAuth2 [Client] to [fn], and closes the client when
51 /// the [Future] returned by [fn] completes. 61 /// the [Future] returned by [fn] completes.
52 /// 62 ///
53 /// This takes care of loading and saving the client's credentials, as well as 63 /// This takes care of loading and saving the client's credentials, as well as
54 /// prompting the user for their authorization. 64 /// prompting the user for their authorization.
55 Future withClient(SystemCache cache, Future fn(Client client)) { 65 Future withClient(SystemCache cache, Future fn(Client client)) {
56 return _getClient(cache).chain((client) { 66 return _getClient(cache).chain((client) {
57 var completer = new Completer(); 67 var completer = new Completer();
58 var future = fn(client); 68 var future = fn(client);
59 future.onComplete((_) { 69 future.onComplete((_) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 print('Pub needs your authorization to upload packages on your behalf.\n' 183 print('Pub needs your authorization to upload packages on your behalf.\n'
174 'In a web browser, go to $authUrl\n' 184 'In a web browser, go to $authUrl\n'
175 'Then click "Allow access".\n\n' 185 'Then click "Allow access".\n\n'
176 'Waiting for your authorization...'); 186 'Waiting for your authorization...');
177 187
178 return completer.future.transform((client) { 188 return completer.future.transform((client) {
179 print('Successfully authorized.\n'); 189 print('Successfully authorized.\n');
180 return client; 190 return client;
181 }); 191 });
182 } 192 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698