Merge lp:~dobey/ubuntuone-client/oauth-reauthorize into lp:ubuntuone-client

Proposed by dobey
Status: Merged
Approved by: Elliot Murphy
Approved revision: 147
Merged at revision: not available
Proposed branch: lp:~dobey/ubuntuone-client/oauth-reauthorize
Merge into: lp:ubuntuone-client
Diff against target: None lines
To merge this branch: bzr merge lp:~dobey/ubuntuone-client/oauth-reauthorize
Reviewer Review Type Date Requested Status
Elliot Murphy (community) Approve
Joshua Blount (community) Approve
Review via email: mp+10169@code.launchpad.net

Commit message

Make it so that AUTH_FAILED results in clearing the token and fetching anew.

To post a comment you must log in.
Revision history for this message
Joshua Blount (jblount) wrote :

This is a really smart way to handle authentication failing, nice work!

review: Approve
Revision history for this message
Elliot Murphy (statik) :
review: Approve
Revision history for this message
Elliot Murphy (statik) wrote :

text conflict in bin/ubuntuone-client-applet

148. By dobey

 Merged from trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/ubuntuone-client-applet'
2--- bin/ubuntuone-client-applet 2009-08-12 20:50:32 +0000
3+++ bin/ubuntuone-client-applet 2009-08-14 16:32:04 +0000
4@@ -60,6 +60,9 @@
5
6 DBUS_IFACE_AUTH_NAME = "com.ubuntuone.Authentication"
7
8+OAUTH_REALM = "https://ubuntuone.com"
9+OAUTH_CONSUMER = "ubuntuone"
10+
11 def dbus_async(*args):
12 """Simple handler to make dbus do stuff async."""
13 pass
14@@ -189,7 +192,7 @@
15 try:
16 client = self.__bus.get_object(DBUS_IFACE_AUTH_NAME, "/")
17 iface = dbus.Interface(client, DBUS_IFACE_AUTH_NAME)
18- iface.maybe_login("https://ubuntuone.com", "ubuntuone",
19+ iface.maybe_login(OAUTH_REALM, OAUTH_CONSUMER,
20 do_login,
21 reply_handler=dbus_async,
22 error_handler=self.dbus_error)
23@@ -342,8 +345,25 @@
24 self.set_from_icon_name("ubuntuone-client-offline")
25 self.set_tooltip(_("Authentication failed"))
26 self.__connected = False
27- if self.__main:
28- self.__main.check_for_token(True)
29+ try:
30+ def reauthorize_error(error):
31+ """Simple dbus error handler."""
32+ pass
33+
34+ def token_cleared():
35+ """Do the next step."""
36+ if self.__main:
37+ self.__main.check_for_token(True)
38+
39+ client = self.__bus.get_object(DBUS_IFACE_AUTH_NAME,
40+ "/")
41+ iface = dbus.Interface(client, DBUS_IFACE_AUTH_NAME)
42+ logger.debug("Clearing the token!")
43+ iface.clear_token(OAUTH_REALM, OAUTH_CONSUMER,
44+ reply_handler=token_cleared,
45+ error_handler=reauthorize_error)
46+ except DBusException:
47+ pass
48 else:
49 self.__connected = True
50 self.set_from_icon_name("ubuntuone-client")
51
52=== modified file 'ubuntuone/oauthdesktop/main.py'
53--- ubuntuone/oauthdesktop/main.py 2009-07-22 18:14:52 +0000
54+++ ubuntuone/oauthdesktop/main.py 2009-08-14 16:32:04 +0000
55@@ -95,6 +95,24 @@
56 logger.debug("Calling auth.client.ensure_access_token in thread")
57 deferToThread(client.ensure_access_token).addErrback(self.error_handler)
58
59+ def clear_token(self, realm, consumer_key):
60+ """Remove the currently stored OAuth token from the keyring."""
61+ self.realm = str(realm)
62+ self.consumer_key = str(consumer_key)
63+ (request_token_url, user_authorisation_url,
64+ access_token_url, consumer_secret) = self.get_config_urls(self.realm)
65+ from ubuntuone.oauthdesktop.auth import AuthorisationClient
66+ client = AuthorisationClient(self.realm,
67+ request_token_url,
68+ user_authorisation_url,
69+ access_token_url,
70+ self.consumer_key, consumer_secret,
71+ callback_parent=self.got_token,
72+ callback_denied=self.got_denial,
73+ callback_notoken=self.got_no_token,
74+ callback_error=self.got_error)
75+ deferToThread(client.clear_token).addErrback(self.error_handler)
76+
77 def error_handler(self, failure):
78 """Deal with errors returned from auth process"""
79 logger.debug("Error returned from auth process")
80@@ -239,6 +257,14 @@
81 self.currently_authing = True
82 self.processor.login(realm, consumer_key, do_login)
83
84+ @dbus.service.method(dbus_interface='com.ubuntuone.Authentication',
85+ in_signature='ss', out_signature='')
86+ def clear_token(self, realm, consumer_key):
87+ """
88+ D-Bus method, exported over the bus, to clear the existing token.
89+ """
90+ self.processor.clear_token(realm, consumer_key)
91+
92 @dbus.service.signal(dbus_interface='com.ubuntuone.Authentication',
93 signature='ss')
94 def NewCredentials(self, realm, consumer_key):

Subscribers

People subscribed via source and target branches