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