| 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:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:uri'; | 9 import 'dart:uri'; |
| 10 | 10 |
| 11 // TODO(nweiz): Make this a "package:" URL, or something nicer than this. | 11 // TODO(nweiz): Make this a "package:" URL, or something nicer than this. |
| 12 import '../../pkg/oauth2/lib/oauth2.dart'; | 12 import '../../pkg/oauth2/lib/oauth2.dart'; |
| 13 import '../../pkg/pathos/lib/path.dart' as path; | 13 import '../../pkg/pathos/lib/path.dart' as path; |
| 14 | 14 |
| 15 import 'http.dart'; | 15 import 'http.dart'; |
| 16 import 'io.dart'; | 16 import 'io.dart'; |
| 17 import 'log.dart' as log; | 17 import 'log.dart' as log; |
| 18 import 'safe_http_server.dart'; |
| 18 import 'system_cache.dart'; | 19 import 'system_cache.dart'; |
| 19 import 'utils.dart'; | 20 import 'utils.dart'; |
| 20 | 21 |
| 21 export '../../pkg/oauth2/lib/oauth2.dart'; | 22 export '../../pkg/oauth2/lib/oauth2.dart'; |
| 22 | 23 |
| 23 /// The pub client's OAuth2 identifier. | 24 /// The pub client's OAuth2 identifier. |
| 24 final _identifier = '818368855108-8grd2eg9tj9f38os6f1urbcvsq399u8n.apps.' | 25 final _identifier = '818368855108-8grd2eg9tj9f38os6f1urbcvsq399u8n.apps.' |
| 25 'googleusercontent.com'; | 26 'googleusercontent.com'; |
| 26 | 27 |
| 27 /// The pub client's OAuth2 secret. This isn't actually meant to be kept a | 28 /// The pub client's OAuth2 secret. This isn't actually meant to be kept a |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 var grant = new AuthorizationCodeGrant( | 165 var grant = new AuthorizationCodeGrant( |
| 165 _identifier, | 166 _identifier, |
| 166 _secret, | 167 _secret, |
| 167 authorizationEndpoint, | 168 authorizationEndpoint, |
| 168 tokenEndpoint, | 169 tokenEndpoint, |
| 169 httpClient: httpClient); | 170 httpClient: httpClient); |
| 170 | 171 |
| 171 // Spin up a one-shot HTTP server to receive the authorization code from the | 172 // Spin up a one-shot HTTP server to receive the authorization code from the |
| 172 // Google OAuth2 server via redirect. This server will close itself as soon as | 173 // Google OAuth2 server via redirect. This server will close itself as soon as |
| 173 // the code is received. | 174 // the code is received. |
| 174 return HttpServer.bind('127.0.0.1', 0).then((server) { | 175 return SafeHttpServer.bind('127.0.0.1', 0).then((server) { |
| 175 var authUrl = grant.getAuthorizationUrl( | 176 var authUrl = grant.getAuthorizationUrl( |
| 176 Uri.parse('http://localhost:${server.port}'), scopes: _scopes); | 177 Uri.parse('http://localhost:${server.port}'), scopes: _scopes); |
| 177 | 178 |
| 178 log.message( | 179 log.message( |
| 179 'Pub needs your authorization to upload packages on your behalf.\n' | 180 'Pub needs your authorization to upload packages on your behalf.\n' |
| 180 'In a web browser, go to $authUrl\n' | 181 'In a web browser, go to $authUrl\n' |
| 181 'Then click "Allow access".\n\n' | 182 'Then click "Allow access".\n\n' |
| 182 'Waiting for your authorization...'); | 183 'Waiting for your authorization...'); |
| 183 return server.first.then((request) { | 184 return server.first.then((request) { |
| 184 var response = request.response; | 185 var response = request.response; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 199 response.statusCode = 404; | 200 response.statusCode = 404; |
| 200 response.close(); | 201 response.close(); |
| 201 } | 202 } |
| 202 }); | 203 }); |
| 203 }) | 204 }) |
| 204 .then((client) { | 205 .then((client) { |
| 205 log.message('Successfully authorized.\n'); | 206 log.message('Successfully authorized.\n'); |
| 206 return client; | 207 return client; |
| 207 }); | 208 }); |
| 208 } | 209 } |
| OLD | NEW |