| 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;
|
| });
|
|
|