| 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.utils; | 5 library oauth2.utils; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:http/http.dart' as http; | 10 import 'package:http/http.dart' as http; |
| 11 import 'package:scheduled_test/scheduled_process.dart'; | 11 import 'package:scheduled_test/scheduled_process.dart'; |
| 12 import 'package:scheduled_test/scheduled_test.dart'; | 12 import 'package:scheduled_test/scheduled_test.dart'; |
| 13 import 'package:scheduled_test/scheduled_server.dart'; | 13 import 'package:scheduled_test/scheduled_server.dart'; |
| 14 | 14 |
| 15 import '../../lib/src/io.dart'; | 15 import '../../lib/src/io.dart'; |
| 16 import '../../lib/src/utils.dart'; | 16 import '../../lib/src/utils.dart'; |
| 17 | 17 |
| 18 void authorizePub(ScheduledProcess pub, ScheduledServer server, | 18 void authorizePub(ScheduledProcess pub, ScheduledServer server, |
| 19 [String accessToken="access token"]) { | 19 [String accessToken="access token"]) { |
| 20 expect(pub.nextLine(), completion(equals('Pub needs your authorization to ' | 20 expect(pub.nextLine(), completion(equals('Pub needs your authorization to ' |
| 21 'upload packages on your behalf.'))); | 21 'upload packages on your behalf.'))); |
| 22 | 22 |
| 23 expect(pub.nextLine().then((line) { | 23 expect(pub.nextLine().then((line) { |
| 24 var match = new RegExp(r'[?&]redirect_uri=([0-9a-zA-Z%+-]+)[$&]') | 24 var match = new RegExp(r'[?&]redirect_uri=([0-9a-zA-Z.%+-]+)[$&]') |
| 25 .firstMatch(line); | 25 .firstMatch(line); |
| 26 expect(match, isNotNull); | 26 expect(match, isNotNull); |
| 27 | 27 |
| 28 var redirectUrl = Uri.parse(Uri.decodeComponent(match.group(1))); | 28 var redirectUrl = Uri.parse(Uri.decodeComponent(match.group(1))); |
| 29 redirectUrl = addQueryParameters(redirectUrl, {'code': 'access code'}); | 29 redirectUrl = addQueryParameters(redirectUrl, {'code': 'access code'}); |
| 30 return (new http.Request('GET', redirectUrl)..followRedirects = false) | 30 return (new http.Request('GET', redirectUrl)..followRedirects = false) |
| 31 .send(); | 31 .send(); |
| 32 }).then((response) { | 32 }).then((response) { |
| 33 expect(response.headers['location'], | 33 expect(response.headers['location'], |
| 34 equals('http://pub.dartlang.org/authorized')); | 34 equals('http://pub.dartlang.org/authorized')); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 47 new ContentType("application", "json"); | 47 new ContentType("application", "json"); |
| 48 request.response.write(JSON.encode({ | 48 request.response.write(JSON.encode({ |
| 49 "access_token": accessToken, | 49 "access_token": accessToken, |
| 50 "token_type": "bearer" | 50 "token_type": "bearer" |
| 51 })); | 51 })); |
| 52 request.response.close(); | 52 request.response.close(); |
| 53 }); | 53 }); |
| 54 }); | 54 }); |
| 55 } | 55 } |
| 56 | 56 |
| OLD | NEW |