Merge lp:~mvo/software-center/lp966514 into lp:software-center

Proposed by Michael Vogt
Status: Merged
Merged at revision: 2928
Proposed branch: lp:~mvo/software-center/lp966514
Merge into: lp:software-center
Diff against target: 149 lines (+22/-93)
2 files modified
softwarecenter/backend/piston/sso_helper.py (+0/-85)
utils/piston-helpers/piston_generic_helper.py (+22/-8)
To merge this branch: bzr merge lp:~mvo/software-center/lp966514
Reviewer Review Type Date Requested Status
Gary Lasker (community) Approve
Review via email: mp+99716@code.launchpad.net

Description of the change

This fixes bug #966514. To verify:
- open software-center
- click on reinstall-previous-purchases to ensure you are logged in
- close software-center
- stop the network connecion (e.g. via network manager or ifconfig down)
- click on reinstall-previous-purchases again
- verify that no "sign-in" dialog appears
(doing the same in trunk will trigger sign-in dialogs)

To post a comment you must log in.
Revision history for this message
Gary Lasker (gary-lasker) wrote :

Nice fix!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== removed file 'softwarecenter/backend/piston/sso_helper.py'
--- softwarecenter/backend/piston/sso_helper.py 2012-03-16 20:12:57 +0000
+++ softwarecenter/backend/piston/sso_helper.py 1970-01-01 00:00:00 +0000
@@ -1,85 +0,0 @@
1#!/usr/bin/python
2# Copyright (C) 2012 Canonical
3#
4# Authors:
5# Michael Vogt
6#
7# This program is free software; you can redistribute it and/or modify it under
8# the terms of the GNU General Public License as published by the Free Software
9# Foundation; version 3.
10#
11# This program is distributed in the hope that it will be useful, but WITHOUT
12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14# details.
15#
16# You should have received a copy of the GNU General Public License along with
17# this program; if not, write to the Free Software Foundation, Inc.,
18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20from gi.repository import GObject
21from gettext import gettext as _
22
23from softwarecenter.backend.login_sso import get_sso_backend
24from softwarecenter.backend.ubuntusso import UbuntuSSOAPI
25from softwarecenter.enums import (SOFTWARE_CENTER_NAME_KEYRING,
26 SOFTWARE_CENTER_SSO_DESCRIPTION,
27 )
28from softwarecenter.utils import clear_token_from_ubuntu_sso
29
30
31class SSOLoginHelper(object):
32 def __init__(self, xid=0):
33 self.oauth = None
34 self.xid = xid
35 self.loop = GObject.MainLoop(GObject.main_context_default())
36
37 def _login_successful(self, sso_backend, oauth_result):
38 self.oauth = oauth_result
39 # FIXME: actually verify the token against ubuntu SSO
40 self.loop.quit()
41
42 def verify_token(self, token):
43 def _whoami_done(sso, me):
44 self._whoami = me
45 self.loop.quit()
46
47 def _whoami_error(sso, err):
48 #print "ERRR", err
49 self.loop.quit()
50 self._whoami = None
51 sso = UbuntuSSOAPI()
52 sso.connect("whoami", _whoami_done)
53 sso.connect("error", _whoami_error)
54 sso.whoami()
55 self.loop.run()
56 # check if the token is valid
57 if self._whoami is None:
58 return False
59 else:
60 return True
61
62 def clear_token(self):
63 clear_token_from_ubuntu_sso(SOFTWARE_CENTER_NAME_KEYRING)
64
65 def get_oauth_token_and_verify_sync(self):
66 token = self.get_oauth_token_sync()
67 # check if the token is valid and reset it if it is not
68 if token and not self.verify_token(token):
69 self.clear_token()
70 # re-trigger login
71 token = self.get_oauth_token_sync()
72 return token
73
74 def get_oauth_token_sync(self):
75 self.oauth = None
76 sso = get_sso_backend(
77 self.xid,
78 SOFTWARE_CENTER_NAME_KEYRING,
79 _(SOFTWARE_CENTER_SSO_DESCRIPTION))
80 sso.connect("login-successful", self._login_successful)
81 sso.connect("login-failed", lambda s: self.loop.quit())
82 sso.connect("login-canceled", lambda s: self.loop.quit())
83 sso.login_or_register()
84 self.loop.run()
85 return self.oauth
860
=== modified file 'utils/piston-helpers/piston_generic_helper.py'
--- utils/piston-helpers/piston_generic_helper.py 2012-03-15 10:43:13 +0000
+++ utils/piston-helpers/piston_generic_helper.py 2012-03-28 12:45:48 +0000
@@ -32,6 +32,7 @@
32 httplib2.debuglevel = 132 httplib2.debuglevel = 1
3333
34import piston_mini_client.auth34import piston_mini_client.auth
35import piston_mini_client.failhandlers
35from piston_mini_client.failhandlers import APIError36from piston_mini_client.failhandlers import APIError
3637
37try:38try:
@@ -93,6 +94,11 @@
93 self.loop.quit()94 self.loop.quit()
9495
95 def verify_token_sync(self, token):96 def verify_token_sync(self, token):
97 """ Verify that the token is valid
98
99 Note that this may raise httplib2 exceptions if the server
100 is not reachable
101 """
96 LOG.debug("verify_token")102 LOG.debug("verify_token")
97 auth = piston_mini_client.auth.OAuthAuthorizer(103 auth = piston_mini_client.auth.OAuthAuthorizer(
98 token["token"], token["token_secret"],104 token["token"], token["token_secret"],
@@ -100,10 +106,10 @@
100 api = UbuntuSsoAPI(auth=auth)106 api = UbuntuSsoAPI(auth=auth)
101 try:107 try:
102 res = api.whoami()108 res = api.whoami()
103 except:109 except piston_mini_client.failhandlers.APIError as e:
104 LOG.exception("api.whoami failed")110 LOG.exception("api.whoami failed with APIError: '%s'" % e)
105 return None111 return False
106 return res112 return len(res) > 0
107113
108 def clear_token(self):114 def clear_token(self):
109 clear_token_from_ubuntu_sso(SOFTWARE_CENTER_NAME_KEYRING)115 clear_token_from_ubuntu_sso(SOFTWARE_CENTER_NAME_KEYRING)
@@ -124,10 +130,18 @@
124 def get_oauth_token_and_verify_sync(self):130 def get_oauth_token_and_verify_sync(self):
125 token = self.get_oauth_token_sync()131 token = self.get_oauth_token_sync()
126 # check if the token is valid and reset it if it is not132 # check if the token is valid and reset it if it is not
127 if token and not self.verify_token_sync(token):133 if token:
128 self.clear_token()134 # verify token will return false if there is a API error,
129 # re-trigger login135 # but there maybe httplib2 errors if there is no network,
130 token = self.get_oauth_token_sync()136 # so ignore them
137 try:
138 if not self.verify_token_sync(token):
139 self.clear_token()
140 # re-trigger login once
141 token = self.get_oauth_token_sync()
142 except Exception as e:
143 LOG.warn(
144 "token could not be verified (network problem?): %s" % e)
131 return token145 return token
132146
133147

Subscribers

People subscribed via source and target branches