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