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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 var completer = new Completer(); | 150 var completer = new Completer(); |
151 var server = new HttpServer(); | 151 var server = new HttpServer(); |
152 server.addRequestHandler((request) => request.path == "/", | 152 server.addRequestHandler((request) => request.path == "/", |
153 (request, response) { | 153 (request, response) { |
154 chainToCompleter(new Future.immediate(null).chain((_) { | 154 chainToCompleter(new Future.immediate(null).chain((_) { |
155 print('Authorization received, processing...'); | 155 print('Authorization received, processing...'); |
156 var queryString = request.queryString; | 156 var queryString = request.queryString; |
157 if (queryString == null) queryString = ''; | 157 if (queryString == null) queryString = ''; |
158 response.statusCode = 302; | 158 response.statusCode = 302; |
159 response.headers.set('location', 'http://pub.dartlang.org/authorized'); | 159 response.headers.set('location', 'http://pub.dartlang.org/authorized'); |
160 response.outputStream.close(); | 160 return Futures.wait([ |
| 161 closeHttpResponse(request, response), |
| 162 grant.handleAuthorizationResponse(queryToMap(queryString)) |
| 163 ]); |
| 164 }).transform((results) { |
161 server.close(); | 165 server.close(); |
162 return grant.handleAuthorizationResponse(queryToMap(queryString)); | 166 return results[1]; |
163 }), completer); | 167 }), completer); |
164 }); | 168 }); |
165 server.listen('127.0.0.1', 0); | 169 server.listen('127.0.0.1', 0); |
166 | 170 |
167 var authUrl = grant.getAuthorizationUrl( | 171 var authUrl = grant.getAuthorizationUrl( |
168 new Uri.fromString('http://localhost:${server.port}'), scopes: _scopes); | 172 new Uri.fromString('http://localhost:${server.port}'), scopes: _scopes); |
169 | 173 |
170 print('Pub needs your authorization to upload packages on your behalf.\n' | 174 print('Pub needs your authorization to upload packages on your behalf.\n' |
171 'In a web browser, go to $authUrl\n' | 175 'In a web browser, go to $authUrl\n' |
172 'Then click "Allow access".\n\n' | 176 'Then click "Allow access".\n\n' |
173 'Waiting for your authorization...'); | 177 'Waiting for your authorization...'); |
174 | 178 |
175 return completer.future.transform((client) { | 179 return completer.future.transform((client) { |
176 print('Successfully authorized.\n'); | 180 print('Successfully authorized.\n'); |
177 return client; | 181 return client; |
178 }); | 182 }); |
179 } | 183 } |
OLD | NEW |