Changeset 1722
- Timestamp:
- 12/20/06 21:07:00 (2 years ago)
- Files:
-
- openidplugin/trunk/openidauth/auth.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openidplugin/trunk/openidauth/auth.py
r1695 r1722 5 5 import time 6 6 import thread 7 import cPickle 7 8 8 9 from openid.store import dumbstore … … 30 31 """Whether we should ask the ID provider for the user's 31 32 full name and email address.""") 33 34 openid_session_key = 'openid_session_data' 32 35 33 36 def __init__(self): … … 101 104 return self._getTrustRoot(req) + self.env.href.openid_return() 102 105 106 def _getConsumer(self, req): 107 s = self._get_session(req) 108 return consumer.Consumer(s, self._get_store()), s 109 103 110 def _start_login(self, req, url): 104 111 """Initiates OpenID login phase.""" 105 oidconsumer = consumer.Consumer(self._get_session(req), self._get_store())112 oidconsumer, session = self._getConsumer(req) 106 113 try: 107 114 authreq = oidconsumer.begin(url) … … 110 117 return False 111 118 119 self._commit_session(session, req) 120 112 121 if self.require_personal_details: 113 122 # tell the IdP that we need the user's email address … … 123 132 124 133 The IdP sends the user back to us.""" 125 oidconsumer = consumer.Consumer(self._get_session(req), self._get_store())134 oidconsumer, session = self._getConsumer(req) 126 135 response = oidconsumer.complete(req.args) 136 self._commit_session(session, req) 137 127 138 if response.status == consumer.SUCCESS: 128 139 if response.getReturnTo().split('?')[0] == self._getReturnTo(req): … … 192 203 193 204 def _get_session(self, req): 194 """Returns a session dict that can store any kind of object. 195 196 This is a hack to get around the OpenID library's limitations.""" 205 """Returns a session dict that can store any kind of object.""" 197 206 198 207 # we must be thread-safe 199 208 self.lock.acquire() 200 201 # first get rid of old sessions 202 now = int(time.time()) 203 for k, v in self.sessions.items(): 204 if v['_last_access'] + 3 * 60 < now: 205 del self.sessions[k] 206 207 # now find an existing session or create a new one 208 session = {} 209 sid = req.session.sid 210 if self.sessions.has_key(sid): 211 session = self.sessions[sid] 212 else: 213 self.sessions[sid] = session 214 215 session['_last_access'] = now 209 try: 210 session = cPickle.loads(str(req.session[self.openid_session_key])) 211 except KeyError: 212 session = {} 216 213 self.lock.release() 217 214 218 215 return session 216 217 def _commit_session(self, session, req): 218 req.session[self.openid_session_key] = str(cPickle.dumps(session)) 219 219 220 220 def _get_store(self):
