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 pub.oauth2; | 5 library pub.oauth2; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:oauth2/oauth2.dart'; | 10 import 'package:oauth2/oauth2.dart'; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 authorizationEndpoint, | 176 authorizationEndpoint, |
177 tokenEndpoint, | 177 tokenEndpoint, |
178 httpClient: httpClient); | 178 httpClient: httpClient); |
179 | 179 |
180 // Spin up a one-shot HTTP server to receive the authorization code from the | 180 // Spin up a one-shot HTTP server to receive the authorization code from the |
181 // Google OAuth2 server via redirect. This server will close itself as soon as | 181 // Google OAuth2 server via redirect. This server will close itself as soon as |
182 // the code is received. | 182 // the code is received. |
183 var completer = new Completer(); | 183 var completer = new Completer(); |
184 bindServer('localhost', 0).then((server) { | 184 bindServer('localhost', 0).then((server) { |
185 shelf_io.serveRequests(server, (request) { | 185 shelf_io.serveRequests(server, (request) { |
186 if (request.url.path != "/") { | 186 if (request.url.path.isNotEmpty) { |
187 return new shelf.Response.notFound('Invalid URI.'); | 187 return new shelf.Response.notFound('Invalid URI.'); |
188 } | 188 } |
189 | 189 |
190 log.message('Authorization received, processing...'); | 190 log.message('Authorization received, processing...'); |
191 var queryString = request.url.query; | 191 var queryString = request.url.query; |
192 if (queryString == null) queryString = ''; | 192 if (queryString == null) queryString = ''; |
193 | 193 |
194 // Closing the server here is safe, since it will wait until the response | 194 // Closing the server here is safe, since it will wait until the response |
195 // is sent to actually shut down. | 195 // is sent to actually shut down. |
196 server.close(); | 196 server.close(); |
(...skipping 11 matching lines...) Expand all Loading... |
208 'In a web browser, go to $authUrl\n' | 208 'In a web browser, go to $authUrl\n' |
209 'Then click "Allow access".\n\n' | 209 'Then click "Allow access".\n\n' |
210 'Waiting for your authorization...'); | 210 'Waiting for your authorization...'); |
211 }); | 211 }); |
212 | 212 |
213 return completer.future.then((client) { | 213 return completer.future.then((client) { |
214 log.message('Successfully authorized.\n'); | 214 log.message('Successfully authorized.\n'); |
215 return client; | 215 return client; |
216 }); | 216 }); |
217 } | 217 } |
OLD | NEW |