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
=== modified file 'bin/ubuntuone-client-applet'
--- bin/ubuntuone-client-applet 2009-08-12 20:50:32 +0000
+++ bin/ubuntuone-client-applet 2009-08-14 16:32:04 +0000
@@ -60,6 +60,9 @@
6060
61DBUS_IFACE_AUTH_NAME = "com.ubuntuone.Authentication"61DBUS_IFACE_AUTH_NAME = "com.ubuntuone.Authentication"
6262
63OAUTH_REALM = "https://ubuntuone.com"
64OAUTH_CONSUMER = "ubuntuone"
65
63def dbus_async(*args):66def dbus_async(*args):
64 """Simple handler to make dbus do stuff async."""67 """Simple handler to make dbus do stuff async."""
65 pass68 pass
@@ -189,7 +192,7 @@
189 try:192 try:
190 client = self.__bus.get_object(DBUS_IFACE_AUTH_NAME, "/")193 client = self.__bus.get_object(DBUS_IFACE_AUTH_NAME, "/")
191 iface = dbus.Interface(client, DBUS_IFACE_AUTH_NAME)194 iface = dbus.Interface(client, DBUS_IFACE_AUTH_NAME)
192 iface.maybe_login("https://ubuntuone.com", "ubuntuone",195 iface.maybe_login(OAUTH_REALM, OAUTH_CONSUMER,
193 do_login,196 do_login,
194 reply_handler=dbus_async,197 reply_handler=dbus_async,
195 error_handler=self.dbus_error)198 error_handler=self.dbus_error)
@@ -342,8 +345,25 @@
342 self.set_from_icon_name("ubuntuone-client-offline")345 self.set_from_icon_name("ubuntuone-client-offline")
343 self.set_tooltip(_("Authentication failed"))346 self.set_tooltip(_("Authentication failed"))
344 self.__connected = False347 self.__connected = False
345 if self.__main:348 try:
346 self.__main.check_for_token(True)349 def reauthorize_error(error):
350 """Simple dbus error handler."""
351 pass
352
353 def token_cleared():
354 """Do the next step."""
355 if self.__main:
356 self.__main.check_for_token(True)
357
358 client = self.__bus.get_object(DBUS_IFACE_AUTH_NAME,
359 "/")
360 iface = dbus.Interface(client, DBUS_IFACE_AUTH_NAME)
361 logger.debug("Clearing the token!")
362 iface.clear_token(OAUTH_REALM, OAUTH_CONSUMER,
363 reply_handler=token_cleared,
364 error_handler=reauthorize_error)
365 except DBusException:
366 pass
347 else:367 else:
348 self.__connected = True368 self.__connected = True
349 self.set_from_icon_name("ubuntuone-client")369 self.set_from_icon_name("ubuntuone-client")
350370
=== modified file 'ubuntuone/oauthdesktop/main.py'
--- ubuntuone/oauthdesktop/main.py 2009-07-22 18:14:52 +0000
+++ ubuntuone/oauthdesktop/main.py 2009-08-14 16:32:04 +0000
@@ -95,6 +95,24 @@
95 logger.debug("Calling auth.client.ensure_access_token in thread")95 logger.debug("Calling auth.client.ensure_access_token in thread")
96 deferToThread(client.ensure_access_token).addErrback(self.error_handler)96 deferToThread(client.ensure_access_token).addErrback(self.error_handler)
9797
98 def clear_token(self, realm, consumer_key):
99 """Remove the currently stored OAuth token from the keyring."""
100 self.realm = str(realm)
101 self.consumer_key = str(consumer_key)
102 (request_token_url, user_authorisation_url,
103 access_token_url, consumer_secret) = self.get_config_urls(self.realm)
104 from ubuntuone.oauthdesktop.auth import AuthorisationClient
105 client = AuthorisationClient(self.realm,
106 request_token_url,
107 user_authorisation_url,
108 access_token_url,
109 self.consumer_key, consumer_secret,
110 callback_parent=self.got_token,
111 callback_denied=self.got_denial,
112 callback_notoken=self.got_no_token,
113 callback_error=self.got_error)
114 deferToThread(client.clear_token).addErrback(self.error_handler)
115
98 def error_handler(self, failure):116 def error_handler(self, failure):
99 """Deal with errors returned from auth process"""117 """Deal with errors returned from auth process"""
100 logger.debug("Error returned from auth process")118 logger.debug("Error returned from auth process")
@@ -239,6 +257,14 @@
239 self.currently_authing = True257 self.currently_authing = True
240 self.processor.login(realm, consumer_key, do_login)258 self.processor.login(realm, consumer_key, do_login)
241259
260 @dbus.service.method(dbus_interface='com.ubuntuone.Authentication',
261 in_signature='ss', out_signature='')
262 def clear_token(self, realm, consumer_key):
263 """
264 D-Bus method, exported over the bus, to clear the existing token.
265 """
266 self.processor.clear_token(realm, consumer_key)
267
242 @dbus.service.signal(dbus_interface='com.ubuntuone.Authentication',268 @dbus.service.signal(dbus_interface='com.ubuntuone.Authentication',
243 signature='ss')269 signature='ss')
244 def NewCredentials(self, realm, consumer_key):270 def NewCredentials(self, realm, consumer_key):

Subscribers

People subscribed via source and target branches