I think that it can be considered as the example code was using an
undocumented feature. I.e. the registration_id was not necessary at the
time.
So it's the example that must be modified.
This the affecting change in web2py tools.py.
- if 'registration_id' in table_user.fields() and \
- 'registration_id' in keys:
- username = 'registration_id'
- elif 'username' in table_user.fields():
- username = 'username'
- elif 'email' in table_user.fields():
- username = 'email'
- else:
- raise SyntaxError, "user must have username or email"
- user = self.db(table_user[username] ==
keys[username]).select().first()
+ user = None
+ checks = []
+ # make a guess about who this user is
+ for fieldname in ['registration_id','username','email']:
+ if fieldname in table_user.fields() and
keys.get(fieldname,None):
+ checks.append(fieldname)
+ user = user or table_user(**{fieldname:keys[fieldname]})
+ # if we think we found the user but registration_id does not
match, make new user
+ if 'registration_id' in checks and user and user.registration_id
and user.registration_id!=keys.get('registration_id',None):
+ user = None # THINK MORE ABOUT THIS? DO WE TRUST OPENID
PROVIDER?
Il giorno mercoledì 20 giugno 2012 15:20:55 UTC+2, Michele Comitini ha
scritto:
>
> I opened an issue here:
> https://github.com/mdipierro/web2py-recipes-source/issues/2
>
> mic
>
> 2012/6/20 Massimo Di Pierro <[email protected]>:
> > Can you please open a ticket?
> >
> >
> > On Wednesday, 20 June 2012 07:02:28 UTC-5, Michele Comitini wrote:
> >>
> >> Alec,
> >>
> >> Thanks to you!
> >> You have found a bug either in the book or in the authentication code.
> >> web2py changed behavior.
> >> I have to check if a compatibility breach happened somewhere or if that
> >> code was using some undocumented feature.
> >>
> >> mic
> >>
> >>
> >> Il giorno mercoledì 20 giugno 2012 02:33:36 UTC+2, Alec Taylor ha
> scritto:
> >>>
> >>> On Wed, Jun 20, 2012 at 7:49 AM, Michele Comitini
> >>> <[email protected]> wrote:
> >>> > You don't return a dictionary with the registration_id key in the
> >>> > get_user() method.
> >>> >
> >>> > change the code as follows:
> >>> >
> >>> > return dict(first_name = user['first_name'], last_name =
> >>> > user['last_name'], username = user['id'], registration_id =
> >>> > user['id'])
> >>> >
> >>> > This is stated in the web2py book as required parameter when using
> >>> > third party authentication.
> >>> >
> >>> > mic
> >>>
> >>> Thanks, that worked.
> >>>
> >>> I guess I was reading the wrong book... I got the previous snippet
> >>> from the "web2py Application Development Cookbook".
> >>>
> >>> > 2012/6/16 Alec Taylor
> >>> >> Unfortunately I haven't been able to get Facebook login with OAuth2
> >>> >> working.
> >>> >>
> >>> >> I've created a tiny test-case below with the problem.
> >>> >>
> >>> >> The only major changes I have made is to models/db.py with a minor
> >>> >> function (foobar) in controllers/default.py.
> >>> >>
> >>> >> https://gist.github.com/9967cb95fe026890dae7
> >>> >>
> >>> >> I have placed the facebook.py file in the modules folder and the
> >>> >> CLIENT_ID and CLIENT_SECRET in another .py file in my modules
> >>> >> directory [file starts with `from gluon import *`].
> >>> >>
> >>> >> Please tell me how I can get this to work.
> >>> >>
> >>> >> Thanks for all suggestions,
> >>> >>
> >>> >> Alec Taylor
> >>> >>
> >>> >> FYI: Not showing a ticket because it actually is stuck in an
> infinite
> >>> >> loop. However when I take out the `@auth.requires_login()`
> decorator
> >>> >> before the `foobar` function the page loads, but "Login" still
> appears
> >>> >> in the top-right.
>