1#!/usr/bin/env python
2# Copyright (c) 2011 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Get auth token from Gaia.
7
8It asks username and password and then prints token on the screen.
9"""
10
11import getpass
12import os
13import urllib
14
15import gaia_auth
16
17
18def main():
19  basepath = os.path.expanduser('~')
20  chromoting_auth_filepath = os.path.join(basepath, '.chromotingAuthToken')
21  chromoting_dir_auth_filepath = os.path.join(
22      basepath, '.chromotingDirectoryAuthToken')
23
24  print "Email:",
25  email = raw_input()
26
27  passwd = getpass.getpass("Password: ")
28
29  chromoting_authenticator = gaia_auth.GaiaAuthenticator('chromiumsync');
30  chromoting_auth_token = chromoting_authenticator.authenticate(email, passwd)
31
32  chromoting_dir_authenticator = gaia_auth.GaiaAuthenticator('chromoting');
33  chromoting_dir_auth_token = chromoting_dir_authenticator.authenticate(
34      email, passwd)
35
36  # Set permission mask for created files.
37  os.umask(0066)
38
39  chromoting_auth_file = open(chromoting_auth_filepath, 'w')
40  chromoting_auth_file.write(email)
41  chromoting_auth_file.write('\n')
42  chromoting_auth_file.write(chromoting_auth_token)
43  chromoting_auth_file.close()
44
45  print
46  print 'Chromoting (sync) Auth Token:'
47  print
48  print chromoting_auth_token
49  print '...saved in', chromoting_auth_filepath
50
51  chromoting_dir_auth_file = open(chromoting_dir_auth_filepath, 'w')
52  chromoting_dir_auth_file.write(email)
53  chromoting_dir_auth_file.write('\n')
54  chromoting_dir_auth_file.write(chromoting_dir_auth_token)
55  chromoting_dir_auth_file.close()
56
57  print
58  print 'Chromoting Directory Auth Token:'
59  print
60  print chromoting_dir_auth_token
61  print '...saved in', chromoting_dir_auth_filepath
62  return 0
63
64
65if __name__ == '__main__':
66  sys.exit(main())
67