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 3 # found in the LICENSE file. 4 5 import getpass 6 import os 7 import urllib 8 9 DEFAULT_GAIA_URL = "https://www.google.com:443/accounts/ClientLogin" 10 11 class GaiaAuthenticator: 12 def __init__(self, service, url = DEFAULT_GAIA_URL): 13 self._service = service 14 self._url = url 15 16 ## Logins to gaia and returns auth token. 17 def authenticate(self, email, passwd): 18 params = urllib.urlencode({'Email': email, 'Passwd': passwd, 19 'source': 'chromoting', 20 'service': self._service, 21 'PersistentCookie': 'true', 22 'accountType': 'GOOGLE'}) 23 f = urllib.urlopen(self._url, params); 24 result = f.read() 25 for line in result.splitlines(): 26 if line.startswith('Auth='): 27 auth_string = line[5:] 28 return auth_string 29 raise Exception("Gaia didn't return auth token: " + result) 30