OLD | NEW |
1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import getpass | 5 import getpass |
6 import os | 6 import os |
7 import urllib | 7 import urllib |
8 | 8 |
9 default_gaia_url = "https://www.google.com:443/accounts/ClientLogin" | 9 DEFAULT_GAIA_URL = "https://www.google.com:443/accounts/ClientLogin" |
10 | 10 |
11 class GaiaAuthenticator: | 11 class GaiaAuthenticator: |
12 def __init__(self, service, url = default_gaia_url): | 12 def __init__(self, service, url = DEFAULT_GAIA_URL): |
13 self._service = service | 13 self._service = service |
14 self._url = url | 14 self._url = url |
15 | 15 |
16 ## Logins to gaia and returns auth token. | 16 ## Logins to gaia and returns auth token. |
17 def authenticate(self, email, passwd): | 17 def authenticate(self, email, passwd): |
18 params = urllib.urlencode({'Email': email, 'Passwd': passwd, | 18 params = urllib.urlencode({'Email': email, 'Passwd': passwd, |
19 'source': 'chromoting', | 19 'source': 'chromoting', |
20 'service': self._service, | 20 'service': self._service, |
21 'PersistentCookie': 'true', | 21 'PersistentCookie': 'true', |
22 'accountType': 'GOOGLE'}) | 22 'accountType': 'GOOGLE'}) |
23 f = urllib.urlopen(self._url, params); | 23 f = urllib.urlopen(self._url, params); |
24 result = f.read() | 24 result = f.read() |
25 for line in result.splitlines(): | 25 for line in result.splitlines(): |
26 if line.startswith('Auth='): | 26 if line.startswith('Auth='): |
27 auth_string = line[5:] | 27 auth_string = line[5:] |
28 return auth_string | 28 return auth_string |
29 raise Exception("Gaia didn't return auth token: " + result) | 29 raise Exception("Gaia didn't return auth token: " + result) |
OLD | NEW |