I looked through the code gluon.contrib.login_methods.oauth20_account and
just banged out something to test in the module for the Facebook class.
from gluon import current
print current.request.vars #gave <Storage {}>
Looks like it isn't getting the request.vars.code it's supposed to get...
On Friday, August 8, 2014 10:50:53 AM UTC+8, lyn2py wrote:
>
> Good one Michele!
>
> This was what I did:
>
> if not self.accessToken():
> print 'no accesstoken'
> return None
>
> No accessToken(), what then should I do? Or where should I consult?
>
> On Friday, August 8, 2014 5:40:09 AM UTC+8, Michele Comitini wrote:
>>
>> Could be a session problem.
>> Check that your session is created and works across page reloads.
>>
>> Also check the get_user() method there could be some error raised there
>> (most likely by the GraphApi), use the debugger or simply put some logging
>> statements to see what's going on
>>
>> I had also troubles with https not properly setup on my side so check
>> that too
>>
>>
>> 2014-08-07 19:37 GMT+02:00 lyn2py <[email protected]>:
>>
>>> Hello,
>>>
>>> I have setup the code for FB oauth per web2py book here:
>>> http://web2py.com/books/default/chapter/29/09/access-control
>>>
>>> The code here:
>>>
>>> ## Define oauth application id and secret.
>>>
>>> FB_CLIENT_ID='xxx'
>>> FB_CLIENT_SECRET="yyyy"
>>>
>>> ## import required modules
>>> try:
>>> import json
>>> except ImportError:
>>> from gluon.contrib import simplejson as json
>>> from facebook import GraphAPI, GraphAPIError
>>> from gluon.contrib.login_methods.oauth20_account import OAuthAccount
>>>
>>>
>>> ## extend the OAUthAccount class
>>> class FaceBookAccount(OAuthAccount):
>>>
>>> """OAuth impl for FaceBook"""
>>> AUTH_URL="https://graph.facebook.com/oauth/authorize"
>>>
>>> TOKEN_URL="https://graph.facebook.com/oauth/access_token"
>>>
>>> def __init__(self):
>>>
>>> OAuthAccount.__init__(self, None, FB_CLIENT_ID, FB_CLIENT_SECRET,
>>>
>>> self.AUTH_URL, self.TOKEN_URL,
>>>
>>> scope='email,user_about_me,user_activities,
>>> user_birthday, user_education_history, user_groups, user_hometown,
>>> user_interests, user_likes, user_location, user_relationships,
>>> user_relationship_details, user_religion_politics, user_subscriptions,
>>> user_work_history, user_photos, user_status, user_videos, publish_actions,
>>> friends_hometown, friends_location,friends_photos',
>>>
>>> state="auth_provider=facebook",
>>> display='popup')
>>>
>>> self.graph = None
>>>
>>> def get_user(self):
>>>
>>> '''Returns the user using the Graph API.
>>> '''
>>> if not self.accessToken():
>>>
>>> return None
>>>
>>> if not self.graph:
>>>
>>> self.graph = GraphAPI((self.accessToken()))
>>>
>>> user = None
>>> try:
>>>
>>> user = self.graph.get_object("me")
>>>
>>> except GraphAPIError, e:
>>>
>>> session.token = None
>>>
>>> self.graph = None
>>>
>>> if user:
>>> if not user.has_key('username'):
>>>
>>> username = user['id']
>>>
>>> else:
>>> username = user['username']
>>>
>>>
>>> if not user.has_key('email'):
>>>
>>> email = '%s.fakemail' %(user['id'])
>>>
>>> else:
>>> email = user['email']
>>>
>>> return dict(first_name = user['first_name'],
>>>
>>> last_name = user['last_name'],
>>>
>>> username = username,
>>> email = '%s' %(email) )
>>>
>>> ## use the above class to build a new login form
>>> auth.settings.login_form=FaceBookAccount()
>>>
>>>
>>>
>>> And I have tried logging in, the page displays and asks for my
>>> permissions, which is all good.
>>>
>>> But then, it doesn't appear that I have logged in, in my app. I keep
>>> returning to the login page like I have not logged in.
>>> And I checked the database, no new auth_user entries have been created
>>> there either…
>>>
>>> May I know if I had missed a step or did something incorrectly?
>>>
>>> I appreciate any help or guidance. Thank you.
>>>
>>> --
>>> Resources:
>>> - http://web2py.com
>>> - http://web2py.com/book (Documentation)
>>> - http://github.com/web2py/web2py (Source code)
>>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "web2py-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.