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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 var completer = new Completer(); | 170 var completer = new Completer(); |
171 var server = new HttpServer(); | 171 var server = new HttpServer(); |
172 server.addRequestHandler((request) => request.path == "/", | 172 server.addRequestHandler((request) => request.path == "/", |
173 (request, response) { | 173 (request, response) { |
174 chainToCompleter(new Future.immediate(null).chain((_) { | 174 chainToCompleter(new Future.immediate(null).chain((_) { |
175 log.message('Authorization received, processing...'); | 175 log.message('Authorization received, processing...'); |
176 var queryString = request.queryString; | 176 var queryString = request.queryString; |
177 if (queryString == null) queryString = ''; | 177 if (queryString == null) queryString = ''; |
178 response.statusCode = 302; | 178 response.statusCode = 302; |
179 response.headers.set('location', 'http://pub.dartlang.org/authorized'); | 179 response.headers.set('location', 'http://pub.dartlang.org/authorized'); |
180 return Futures.wait([ | 180 response.outputStream.close(); |
181 closeHttpResponse(request, response), | 181 return grant.handleAuthorizationResponse(queryToMap(queryString)); |
182 grant.handleAuthorizationResponse(queryToMap(queryString)) | 182 }).transform((client) { |
183 ]); | |
184 }).transform((results) { | |
185 server.close(); | 183 server.close(); |
186 return results[1]; | 184 return client; |
187 }), completer); | 185 }), completer); |
188 }); | 186 }); |
189 server.listen('127.0.0.1', 0); | 187 server.listen('127.0.0.1', 0); |
190 | 188 |
191 var authUrl = grant.getAuthorizationUrl( | 189 var authUrl = grant.getAuthorizationUrl( |
192 new Uri.fromString('http://localhost:${server.port}'), scopes: _scopes); | 190 new Uri.fromString('http://localhost:${server.port}'), scopes: _scopes); |
193 | 191 |
194 log.message( | 192 log.message( |
195 'Pub needs your authorization to upload packages on your behalf.\n' | 193 'Pub needs your authorization to upload packages on your behalf.\n' |
196 'In a web browser, go to $authUrl\n' | 194 'In a web browser, go to $authUrl\n' |
197 'Then click "Allow access".\n\n' | 195 'Then click "Allow access".\n\n' |
198 'Waiting for your authorization...'); | 196 'Waiting for your authorization...'); |
199 | 197 |
200 return completer.future.transform((client) { | 198 return completer.future.transform((client) { |
201 log.message('Successfully authorized.\n'); | 199 log.message('Successfully authorized.\n'); |
202 return client; | 200 return client; |
203 }); | 201 }); |
204 } | 202 } |
OLD | NEW |