[web2py] Re: Auth with OpenId

2011-02-19 Thread drebbin
At first I struggled with OpenId myself, using the python-openid lib. It did 
cost me several nerves and reading many other implementations was necessary 
before I understood the inner workings. But now I do - it was worth it, and 
I got a simple login working. Then I wanted to combine it with web2py's auth 
mechanisms -- when I realised that web2py already has such, in 
contrib/login_methods. Well...

Unfortunately, the above mentioned issues stop the show.
So, I would like to debug that module and am currently stuck in 
understanding the DAL, *sigh* Sources are sparsely documented. The exception 
throws in method `represent()'. What does it do? I am planning to read 
through the sources from bottom to top, following the backtrace.

Considering success, I also would like to extend that module. OpenId also 
allows to query the provider about some information about the user (called 
attribute exchange), like name, email address (user is asked, of course, if 
she allows to disclose these). It would be nice if web2py's openid module 
would also have this feature.

Any help here is greatly appreciated. :)

KR, drebbin


[web2py] Logging SQL

2011-02-19 Thread drebbin
Hi all,

to debug the SQL statements used during auth with openid I would like to log 
them to a file. I have setup logging according to 
http://web2pyslices.com/main/slices/take_slice/91 and calling 
logger.debug('foo') from a controller logs that message.
But if I try to log sth. out of DAL, nothing happens.
E.g (in dal.py).
def _insert(self,table,fields):
   global logger
   logger.debug(Inserting into %s: %s %(table, fields))
   ...

Replacing logger.debug with raise Exception show, that _insert() gets 
called.

Any ideas?

KR, drebbin


[web2py] Re: Auth with OpenId

2011-02-18 Thread drebbin
Thanks for your hint. Upon Janrain I already stumbled because of their 
python-openid lib. For my current project I only need Google, and so I would 
really like to not enroll with another 3rd party. Besides, Janrain wants to 
have the domain registered with them. Wouldn't that mean to register one for 
the customer's production site, one for the staging site and at least one 
for my development site? *shudder* if I'm seeing this right.

KR, drebbin


[web2py] Auth with OpenId

2011-02-17 Thread drebbin
Hello,
investigating authentication with OpenId in web2py I encountered some
issues. For testing purposes I used the wizard to create a new
application tmp1 with all default settings (notably sqlite db).
According to the book I added the 2 lines to db.py to import and
activate OpenId. In the default controller I added a new method
secure and decorated it with @auth.requires_login(), and in the
index-template i added a link that leads to 'secure'.

When I click that link I properly get the login form asking for an
OpenId Url, I can login with that, web2py tells, verification is ok.
Then I get asked to login as web2py user or register.

Here the issues start:
(1) I am not registered yet, so I choose that. After registering, I am
logged in, but no association to my OpenId is stored.

(2) When I want to login a second time, web2py tells me again, that it
has no association with my OpenId and again asks for local login or
registration. Since now I have an account, I enter my username and
password, and then this error occurs:
Traceback (most recent call last):

  File /web2py/gluon/restricted.py, line 188, in restricted
exec ccode in environment
  File /web2py/applications/tmp1/controllers/default.py, line 19, in
module
  File /web2py/gluon/globals.py, line 95, in lambda
self._caller = lambda f: f()
  File /web2py/applications/tmp1/controllers/default.py, line 3, in
user
def user(): return dict(form=auth())
  File /web2py/gluon/tools.py, line 1034, in __call__
return self.login()
  File /web2py/gluon/tools.py, line 1503, in login
cas_user = cas.get_user()
  File /web2py/gluon/contrib/login_methods/openid_auth.py, line 200,
in get_user
self._associate_user_openid(self.auth.user, oid)
  File /web2py/gluon/contrib/login_methods/openid_auth.py, line 244,
in _associate_user_openid
self.db.alt_logins.insert(username=oid, user=user)
  File /web2py/gluon/dal.py, line 3952, in insert
return self._db._adapter.insert(self,self._listify(fields))
  File /web2py/gluon/dal.py, line 711, in insert
query = self._insert(table,fields)
  File /web2py/gluon/dal.py, line 707, in _insert
values = ','.join(self.expand(v,f.type) for f,v in fields)
  File /web2py/gluon/dal.py, line 707, in genexpr
values = ','.join(self.expand(v,f.type) for f,v in fields)
  File /web2py/gluon/dal.py, line 821, in expand
return self.represent(expression,field_type)
  File /web2py/gluon/dal.py, line 1131, in represent
return str(int(obj))
TypeError: 'NoneType' object is not callable

Can someone please shed some light on this and/or point me in the
right direction. Thanks.

KR, drebbin