forked from joh/gnome-shell-google-calendar
-
Notifications
You must be signed in to change notification settings - Fork 24
/
oauth.py
64 lines (50 loc) · 2.21 KB
/
oauth.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'''
Created on 17.02.2012
@author: flocki
'''
import dbus
import gdata.calendar.client
def oauth_prompt():
bus = dbus.SessionBus()
online_accounts = bus.get_object('org.gnome.OnlineAccounts',
'/org/gnome/OnlineAccounts')
l = online_accounts.GetManagedObjects(
dbus_interface='org.freedesktop.DBus.ObjectManager')
accounts = []
for account_info in l.values():
if 'org.gnome.OnlineAccounts.Account' in account_info:
email = str(account_info['org.gnome.OnlineAccounts.Account']
['PresentationIdentity'])
print "%d. %s" % (len(accounts), email)
accounts.append(email)
email = accounts[int(raw_input('Please choose the Account: '))]
print "You choose '{0}'".format(email)
return email
def oauth_login(email):
bus = dbus.SessionBus()
online_accounts = bus.get_object('org.gnome.OnlineAccounts',
'/org/gnome/OnlineAccounts')
l = online_accounts.GetManagedObjects(
dbus_interface='org.freedesktop.DBus.ObjectManager')
for account_path, account_info in l.items():
if 'org.gnome.OnlineAccounts.Account' in account_info and \
str(account_info['org.gnome.OnlineAccounts.Account']
['PresentationIdentity']) == email:
consumer_key = str(
account_info['org.gnome.OnlineAccounts.OAuthBased']
['ConsumerKey'])
consumer_secret = str(
account_info['org.gnome.OnlineAccounts.OAuthBased']
['ConsumerSecret'])
o = bus.get_object('org.gnome.OnlineAccounts', account_path)
oauth_data = o.get_dbus_method('GetAccessToken',
'org.gnome.OnlineAccounts.OAuthBased')()
access_token = str(oauth_data[0])
access_token_secret = str(oauth_data[1])
client = gdata.calendar.client.CalendarClient(
source='gnome-shell-google-calendar')
client.auth_token = gdata.gauth.OAuthHmacToken(consumer_key,
consumer_secret, access_token, access_token_secret,
gdata.gauth.ACCESS_TOKEN)
return client
raise Exception