Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(813)

Unified Diff: utils/pub/oauth2.dart

Issue 12428012: Properly handle errors from the OAuth2 token endpoint in pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor changes Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/pub/http.dart ('k') | utils/tests/pub/oauth2_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/oauth2.dart
diff --git a/utils/pub/oauth2.dart b/utils/pub/oauth2.dart
index cc80d862be004344d49b04556c200de984ad00df..6543ecd06528cbf626ccba93d131b090d1e78bc9 100644
--- a/utils/pub/oauth2.dart
+++ b/utils/pub/oauth2.dart
@@ -35,14 +35,23 @@ final _secret = 'SWeqj8seoJW0w7_CpEPFLX0K';
/// a refresh token from the server. See the [Google OAuth2 documentation][].
///
/// [Google OAuth2 documentation]: https://developers.google.com/accounts/docs/OAuth2WebServer#offline
-final _authorizationEndpoint = Uri.parse(
+final authorizationEndpoint = Uri.parse(
'https://accounts.google.com/o/oauth2/auth?access_type=offline'
'&approval_prompt=force');
/// The URL from which the pub client will request an access token once it's
-/// been authorized by the user.
-final _tokenEndpoint = Uri.parse(
- 'https://accounts.google.com/o/oauth2/token');
+/// been authorized by the user. This can be controlled externally by setting
+/// the _PUB_TEST_TOKEN_ENDPOINT environment variable.
+Uri get tokenEndpoint {
+ var tokenEndpoint = Platform.environment['_PUB_TEST_TOKEN_ENDPOINT'];
+ if (tokenEndpoint != null) {
+ return Uri.parse(tokenEndpoint);
+ } else {
+ return _tokenEndpoint;
+ }
+}
+
+final _tokenEndpoint = Uri.parse('https://accounts.google.com/o/oauth2/token');
/// The OAuth2 scopes that the pub client needs. Currently the client only needs
/// the user's email so that the server can verify their identity.
@@ -152,18 +161,10 @@ String _credentialsFile(SystemCache cache) =>
/// Gets the user to authorize pub as a client of pub.dartlang.org via oauth2.
/// Returns a Future that will complete to a fully-authorized [Client].
Future<Client> _authorize() {
- // Allow the tests to inject their own token endpoint URL.
- var tokenEndpoint = Platform.environment['_PUB_TEST_TOKEN_ENDPOINT'];
- if (tokenEndpoint != null) {
- tokenEndpoint = Uri.parse(tokenEndpoint);
- } else {
- tokenEndpoint = _tokenEndpoint;
- }
-
var grant = new AuthorizationCodeGrant(
_identifier,
_secret,
- _authorizationEndpoint,
+ authorizationEndpoint,
tokenEndpoint,
httpClient: httpClient);
« no previous file with comments | « utils/pub/http.dart ('k') | utils/tests/pub/oauth2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698