summaryrefslogtreecommitdiffstats
path: root/remoting/tools/gaia_auth.py
blob: 392f2f3d2549ec97bebb31468ed980851efb15f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Copyright (c) 2010 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import getpass
import os
import urllib

DEFAULT_GAIA_URL = "https://www.google.com:443/accounts/ClientLogin"

class GaiaAuthenticator:
  def __init__(self, service, url = DEFAULT_GAIA_URL):
    self._service = service
    self._url = url

  ## Logins to gaia and returns auth token.
  def authenticate(self, email, passwd):
    params = urllib.urlencode({'Email': email, 'Passwd': passwd,
                               'source': 'chromoting',
                               'service': self._service,
                               'PersistentCookie': 'true',
                               'accountType': 'GOOGLE'})
    f = urllib.urlopen(self._url, params);
    result = f.read()
    for line in result.splitlines():
      if line.startswith('Auth='):
        auth_string = line[5:]
        return auth_string
    raise Exception("Gaia didn't return auth token: " + result)