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 | 8 |
9 import 'package:http/http.dart' as http; | 9 import 'package:http/http.dart' as http; |
| 10 import 'package:pub/src/utils.dart'; |
10 import 'package:scheduled_test/scheduled_process.dart'; | 11 import 'package:scheduled_test/scheduled_process.dart'; |
11 import 'package:scheduled_test/scheduled_test.dart'; | 12 import 'package:scheduled_test/scheduled_test.dart'; |
12 import 'package:scheduled_test/scheduled_server.dart'; | 13 import 'package:scheduled_test/scheduled_server.dart'; |
13 import 'package:shelf/shelf.dart' as shelf; | 14 import 'package:shelf/shelf.dart' as shelf; |
14 | 15 |
15 import '../../lib/src/utils.dart'; | |
16 | 16 |
17 void authorizePub(ScheduledProcess pub, ScheduledServer server, | 17 void authorizePub(ScheduledProcess pub, ScheduledServer server, |
18 [String accessToken="access token"]) { | 18 [String accessToken="access token"]) { |
19 pub.stdout.expect('Pub needs your authorization to upload packages on your ' | 19 pub.stdout.expect('Pub needs your authorization to upload packages on your ' |
20 'behalf.'); | 20 'behalf.'); |
21 | 21 |
22 schedule(() { | 22 schedule(() { |
23 return pub.stdout.next().then((line) { | 23 return pub.stdout.next().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); |
(...skipping 18 matching lines...) Loading... |
44 expect(body, matches(new RegExp(r'(^|&)code=access\+code(&|$)'))); | 44 expect(body, matches(new RegExp(r'(^|&)code=access\+code(&|$)'))); |
45 | 45 |
46 return new shelf.Response.ok(JSON.encode({ | 46 return new shelf.Response.ok(JSON.encode({ |
47 "access_token": accessToken, | 47 "access_token": accessToken, |
48 "token_type": "bearer" | 48 "token_type": "bearer" |
49 }), headers: {'content-type': 'application/json'}); | 49 }), headers: {'content-type': 'application/json'}); |
50 }); | 50 }); |
51 }); | 51 }); |
52 } | 52 } |
53 | 53 |
OLD | NEW |