| 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:io'; | 7 import 'dart:io'; |
| 8 import 'dart:json' as json; | 8 import 'dart:json' as json; |
| 9 import 'dart:uri'; | 9 import 'dart:uri'; |
| 10 | 10 |
| 11 import 'package:http/http.dart' as http; | 11 import 'package:http/http.dart' as http; |
| 12 import 'package:scheduled_test/scheduled_process.dart'; | 12 import 'package:scheduled_test/scheduled_process.dart'; |
| 13 import 'package:scheduled_test/scheduled_test.dart'; | 13 import 'package:scheduled_test/scheduled_test.dart'; |
| 14 import 'package:scheduled_test/scheduled_server.dart'; | 14 import 'package:scheduled_test/scheduled_server.dart'; |
| 15 | 15 |
| 16 import '../../lib/src/io.dart'; | 16 import '../../lib/src/io.dart'; |
| 17 import '../../lib/src/utils.dart'; | 17 import '../../lib/src/utils.dart'; |
| 18 import '../test_pub.dart'; | 18 import '../test_pub.dart'; |
| 19 | 19 |
| 20 void authorizePub(ScheduledProcess pub, ScheduledServer server, | 20 void authorizePub(ScheduledProcess pub, ScheduledServer server, |
| 21 [String accessToken="access token"]) { | 21 [String accessToken="access token"]) { |
| 22 // TODO(rnystrom): The confirm line is run together with this one because | 22 expect(pub.nextLine(), completion(equals('Pub needs your authorization to ' |
| 23 // in normal usage, the user will have entered a newline on stdin which | 23 'upload packages on your behalf.'))); |
| 24 // gets echoed to the terminal. Do something better here? | |
| 25 expect(pub.nextLine(), completion(equals( | |
| 26 'Looks great! Are you ready to upload your package (y/n)? ' | |
| 27 'Pub needs your authorization to upload packages on your behalf.'))); | |
| 28 | 24 |
| 29 expect(pub.nextLine().then((line) { | 25 expect(pub.nextLine().then((line) { |
| 30 var match = new RegExp(r'[?&]redirect_uri=([0-9a-zA-Z%+-]+)[$&]') | 26 var match = new RegExp(r'[?&]redirect_uri=([0-9a-zA-Z%+-]+)[$&]') |
| 31 .firstMatch(line); | 27 .firstMatch(line); |
| 32 expect(match, isNotNull); | 28 expect(match, isNotNull); |
| 33 | 29 |
| 34 var redirectUrl = Uri.parse(decodeUriComponent(match.group(1))); | 30 var redirectUrl = Uri.parse(decodeUriComponent(match.group(1))); |
| 35 redirectUrl = addQueryParameters(redirectUrl, {'code': 'access code'}); | 31 redirectUrl = addQueryParameters(redirectUrl, {'code': 'access code'}); |
| 36 return (new http.Request('GET', redirectUrl)..followRedirects = false) | 32 return (new http.Request('GET', redirectUrl)..followRedirects = false) |
| 37 .send(); | 33 .send(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 53 new ContentType("application", "json"); | 49 new ContentType("application", "json"); |
| 54 request.response.write(json.stringify({ | 50 request.response.write(json.stringify({ |
| 55 "access_token": accessToken, | 51 "access_token": accessToken, |
| 56 "token_type": "bearer" | 52 "token_type": "bearer" |
| 57 })); | 53 })); |
| 58 request.response.close(); | 54 request.response.close(); |
| 59 }); | 55 }); |
| 60 }); | 56 }); |
| 61 } | 57 } |
| 62 | 58 |
| OLD | NEW |