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

Unified Diff: utils/pub/oauth2.dart

Issue 12316036: Merge IO v2 branch to bleeding edge (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased to r18818 Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/pub/io.dart ('k') | utils/testrunner/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/oauth2.dart
diff --git a/utils/pub/oauth2.dart b/utils/pub/oauth2.dart
index 276fb25b62b989b26ab0e8b6a64c3f46da8fc22f..f2ec1b537ab10bdbb99d378455650d15c40ba901 100644
--- a/utils/pub/oauth2.dart
+++ b/utils/pub/oauth2.dart
@@ -170,35 +170,37 @@ Future<Client> _authorize() {
// Spin up a one-shot HTTP server to receive the authorization code from the
// Google OAuth2 server via redirect. This server will close itself as soon as
// the code is received.
- var completer = new Completer();
- var server = new HttpServer();
- server.addRequestHandler((request) => request.path == "/",
- (request, response) {
- chainToCompleter(defer(() {
- log.message('Authorization received, processing...');
- var queryString = request.queryString;
- if (queryString == null) queryString = '';
- response.statusCode = 302;
- response.headers.set('location', 'http://pub.dartlang.org/authorized');
- response.outputStream.close();
- return grant.handleAuthorizationResponse(queryToMap(queryString));
- }).then((client) {
- server.close();
- return client;
- }), completer);
- });
- server.listen('127.0.0.1', 0);
-
- var authUrl = grant.getAuthorizationUrl(
- Uri.parse('http://localhost:${server.port}'), scopes: _scopes);
-
- log.message(
- 'Pub needs your authorization to upload packages on your behalf.\n'
- 'In a web browser, go to $authUrl\n'
- 'Then click "Allow access".\n\n'
- 'Waiting for your authorization...');
-
- return completer.future.then((client) {
+ return HttpServer.bind('127.0.0.1', 0).then((server) {
+ var authUrl = grant.getAuthorizationUrl(
+ Uri.parse('http://localhost:${server.port}'), scopes: _scopes);
+
+ log.message(
+ 'Pub needs your authorization to upload packages on your behalf.\n'
+ 'In a web browser, go to $authUrl\n'
+ 'Then click "Allow access".\n\n'
+ 'Waiting for your authorization...');
+ return server.first.then((request) {
+ var response = request.response;
+ if (request.uri.path == "/") {
+ log.message('Authorization received, processing...');
+ var queryString = request.uri.query;
+ if (queryString == null) queryString = '';
+ response.statusCode = 302;
+ response.headers.set('location',
+ 'http://pub.dartlang.org/authorized');
+ response.close();
+ return grant.handleAuthorizationResponse(queryToMap(queryString))
+ .then((client) {
+ server.close();
+ return client;
+ });
+ } else {
+ response.statusCode = 404;
+ response.close();
+ }
+ });
+ })
+ .then((client) {
log.message('Successfully authorized.\n');
return client;
});
« no previous file with comments | « utils/pub/io.dart ('k') | utils/testrunner/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698