diff options
-rw-r--r-- | codereview/__init__.py | 2 | ||||
-rwxr-xr-x | codereview/proto_client.py | 21 |
2 files changed, 17 insertions, 6 deletions
diff --git a/codereview/__init__.py b/codereview/__init__.py index e47bc94e..4ac92e8a 100644 --- a/codereview/__init__.py +++ b/codereview/__init__.py | |||
@@ -1 +1 @@ | |||
__version__ = 'v1.0' | __version__ = 'v1.0-14-gc4f226bc' | ||
diff --git a/codereview/proto_client.py b/codereview/proto_client.py index e11beff0..a51fcd06 100755 --- a/codereview/proto_client.py +++ b/codereview/proto_client.py | |||
@@ -167,6 +167,10 @@ class HttpRpc(RpcChannel): | |||
167 | Returns: | 167 | Returns: |
168 | The authentication token returned by ClientLogin. | 168 | The authentication token returned by ClientLogin. |
169 | """ | 169 | """ |
170 | account_type = 'GOOGLE' | ||
171 | if self.host.endswith('.google.com'): | ||
172 | account_type = 'HOSTED' | ||
173 | |||
170 | req = self._CreateRequest( | 174 | req = self._CreateRequest( |
171 | url="https://www.google.com/accounts/ClientLogin", | 175 | url="https://www.google.com/accounts/ClientLogin", |
172 | data=urllib.urlencode({ | 176 | data=urllib.urlencode({ |
@@ -174,7 +178,7 @@ class HttpRpc(RpcChannel): | |||
174 | "Passwd": password, | 178 | "Passwd": password, |
175 | "service": "ah", | 179 | "service": "ah", |
176 | "source": "gerrit-codereview-client", | 180 | "source": "gerrit-codereview-client", |
177 | "accountType": "HOSTED_OR_GOOGLE", | 181 | "accountType": account_type, |
178 | }) | 182 | }) |
179 | ) | 183 | ) |
180 | try: | 184 | try: |
@@ -214,7 +218,6 @@ class HttpRpc(RpcChannel): | |||
214 | response.info()["location"] != continue_location): | 218 | response.info()["location"] != continue_location): |
215 | raise urllib2.HTTPError(req.get_full_url(), response.code, response.msg, | 219 | raise urllib2.HTTPError(req.get_full_url(), response.code, response.msg, |
216 | response.headers, response.fp) | 220 | response.headers, response.fp) |
217 | self.authenticated = True | ||
218 | 221 | ||
219 | def _GetXsrfToken(self): | 222 | def _GetXsrfToken(self): |
220 | """Fetches /proto/_token for use in X-XSRF-Token HTTP header. | 223 | """Fetches /proto/_token for use in X-XSRF-Token HTTP header. |
@@ -253,10 +256,18 @@ class HttpRpc(RpcChannel): | |||
253 | authentication cookie, it returns a 401 response and directs us to | 256 | authentication cookie, it returns a 401 response and directs us to |
254 | authenticate ourselves with ClientLogin. | 257 | authenticate ourselves with ClientLogin. |
255 | """ | 258 | """ |
256 | for i in range(3): | 259 | attempts = 0 |
257 | credentials = self.auth_function() | 260 | while True: |
258 | auth_token = self._GetAuthToken(credentials[0], credentials[1]) | 261 | attempts += 1 |
262 | try: | ||
263 | cred = self.auth_function() | ||
264 | auth_token = self._GetAuthToken(cred[0], cred[1]) | ||
265 | except ClientLoginError: | ||
266 | if attempts < 3: | ||
267 | continue | ||
268 | raise | ||
259 | self._GetAuthCookie(auth_token) | 269 | self._GetAuthCookie(auth_token) |
270 | self.authenticated = True | ||
260 | if self.cookie_file is not None: | 271 | if self.cookie_file is not None: |
261 | self.cookie_jar.save() | 272 | self.cookie_jar.save() |
262 | return | 273 | return |