~mvo/ubuntu-sso-client/strawman-lp711413

« back to all changes in this revision

Viewing changes to ubuntu/sso/main.py

  • Committer: natalia.bidart at canonical
  • Date: 2010-06-09 18:23:27 UTC
  • mfrom: (533.1.4 rename)
  • Revision ID: natalia.bidart@canonical.com-20100609182327-kmd0rjjb1f0eojhu
Renaming modules and Dbus service to make them more generic.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
 
# ubuntuone.oauthdesktop.main - main login handling interface
 
3
# ubuntu.sso.main - main login handling interface
4
4
#
5
5
# Author: Stuart Langridge <stuart.langridge@canonical.com>
6
6
#
30
30
 
31
31
from dbus.mainloop.glib import DBusGMainLoop
32
32
 
33
 
from ubuntuone.oauthdesktop.config import get_config
 
33
from ubuntu.sso import DBUS_IFACE_AUTH_NAME
 
34
from ubuntu.sso.config import get_config
34
35
 
35
 
from ubuntuone.oauthdesktop.logger import setupLogging
36
 
logger = setupLogging("UbuntuOne.OAuthDesktop.main")
 
36
from ubuntu.sso.logger import setupLogging
 
37
logger = setupLogging("ubuntu.sso.main")
37
38
 
38
39
DBusGMainLoop(set_as_default=True)
39
40
 
77
78
                     "access='%s', secret='%s'", request_token_url,
78
79
                     user_authorisation_url, access_token_url, consumer_secret)
79
80
 
80
 
        from ubuntuone.oauthdesktop.auth import AuthorisationClient
 
81
        from ubuntu.sso.auth import AuthorisationClient
81
82
        client = AuthorisationClient(self.realm,
82
83
                                     request_token_url,
83
84
                                     user_authorisation_url,
98
99
        self.consumer_key = str(consumer_key)
99
100
        (request_token_url, user_authorisation_url,
100
101
          access_token_url, consumer_secret) =  self.get_config_urls(self.realm)
101
 
        from ubuntuone.oauthdesktop.auth import AuthorisationClient
 
102
        from ubuntu.sso.auth import AuthorisationClient
102
103
        client = AuthorisationClient(self.realm,
103
104
                                     request_token_url,
104
105
                                     user_authorisation_url,
216
217
        self.currently_authing = False
217
218
        logger.debug("Login D-Bus service starting up")
218
219
 
219
 
    @dbus.service.method(dbus_interface='com.ubuntuone.Authentication',
 
220
    @dbus.service.method(dbus_interface=DBUS_IFACE_AUTH_NAME,
220
221
                                           in_signature='ss', out_signature='')
221
222
    def login(self, realm, consumer_key):
222
223
        """D-Bus method, exported over the bus, to initiate an OAuth login"""
228
229
        self.currently_authing = True
229
230
        self.processor.login(realm, consumer_key)
230
231
 
231
 
    @dbus.service.method(dbus_interface='com.ubuntuone.Authentication',
 
232
    @dbus.service.method(dbus_interface=DBUS_IFACE_AUTH_NAME,
232
233
                                           in_signature='ssb', out_signature='')
233
234
    def maybe_login(self, realm, consumer_key, do_login):
234
235
        """
242
243
        self.currently_authing = True
243
244
        self.processor.login(realm, consumer_key, do_login)
244
245
 
245
 
    @dbus.service.method(dbus_interface='com.ubuntuone.Authentication',
 
246
    @dbus.service.method(dbus_interface=DBUS_IFACE_AUTH_NAME,
246
247
                         in_signature='ss', out_signature='')
247
248
    def clear_token(self, realm, consumer_key):
248
249
        """
250
251
        """
251
252
        self.processor.clear_token(realm, consumer_key)
252
253
 
253
 
    @dbus.service.signal(dbus_interface='com.ubuntuone.Authentication',
254
 
                                             signature='ss')
 
254
    @dbus.service.signal(dbus_interface=DBUS_IFACE_AUTH_NAME, signature='ss')
255
255
    def NewCredentials(self, realm, consumer_key):
256
256
        """Fire D-Bus signal when the user accepts authorization."""
257
257
        logger.debug("Firing the NewCredentials signal")
258
258
        self.currently_authing = False
259
259
        return (self.processor.realm, self.processor.consumer_key)
260
260
 
261
 
    @dbus.service.signal(dbus_interface='com.ubuntuone.Authentication')
 
261
    @dbus.service.signal(dbus_interface=DBUS_IFACE_AUTH_NAME)
262
262
    def AuthorizationDenied(self):
263
263
        """Fire the signal when the user denies authorization."""
264
264
        self.currently_authing = False
265
265
 
266
 
    @dbus.service.signal(dbus_interface='com.ubuntuone.Authentication')
 
266
    @dbus.service.signal(dbus_interface=DBUS_IFACE_AUTH_NAME)
267
267
    def NoCredentials(self):
268
268
        """Fired when the user does not have a token in the keyring."""
269
269
        self.currently_authing = False
270
270
 
271
 
    @dbus.service.signal(dbus_interface='com.ubuntuone.Authentication',
272
 
                         signature='s')
 
271
    @dbus.service.signal(dbus_interface=DBUS_IFACE_AUTH_NAME, signature='s')
273
272
    def OAuthError(self, message):
274
273
        """Fire the signal when an error needs to be propagated to the user."""
275
274
        self.currently_authing = False
284
283
    from twisted.internet import reactor
285
284
 
286
285
    logger.debug("Creating the D-Bus service")
287
 
    Login(dbus.service.BusName("com.ubuntuone.Authentication",
 
286
    Login(dbus.service.BusName(DBUS_IFACE_AUTH_NAME,
288
287
                               bus=dbus.SessionBus()))
289
288
    # cleverness here to say:
290
289
    # am I already running (bound to this d-bus name)?