Michele,

When is get_user() called during the login or account creation
process?

Background:
I use a custom login method which leverages a Web service to
authenticate a user.  The authentication Web service only returns a
pass/fail value.  I need to use a second Web service to pull user
account information, such as first and last name.  I'd like to set up
a get_user method which would call this second Web service to populate
the user name. To do that, I need to pull the 'username' variable, I
suppose from the auth object?

I appreciate your help.
--Scott

On Aug 10, 8:42 am, Michele Comitini <[email protected]>
wrote:
> Just return a dictionary with the properties you defined in the auth
> table in db.py.
>
> For instance to use facebook with oauth20_account you need to override
> get_user() method in the OAuthAccount class as you need.
> Below is how I implement it for the test application 
> onhttp://grafbook.appspot.com/helloFacebook
>
> You can find the code of the example 
> here:http://code.google.com/r/michelecomitini-facebookaccess/source/browse...
>
> the important parts in db.py:
>
> .
> .
> .
> auth_table = db.define_table(
>     auth.settings.table_user_name,
>     Field('first_name', length=128, default=""),
>     Field('last_name', length=128, default=""),
>     Field('username', length=128, default="", unique=True),
>     Field('password', 'password', length=256,
>           readable=False, label='Password'),
>     Field('registration_key', length=128, default= "",
>           writable=False, readable=False))
>
> auth_table.username.requires = IS_NOT_IN_DB(db, auth_table.username)
>
> auth.define_tables()                           # creates all needed tables
>
> .
> .
> .
>
> import sys, os
> path = os.path.join(request.folder, 'modules')
> if not path in sys.path:
>     sys.path.append(path)
> from fbappauth import CLIENT_ID,CLIENT_SECRET
> from facebook import GraphAPI
> from gluon.contrib.login_methods.oauth20_account import OAuthAccount
>
> 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, g):
>         OAuthAccount.__init__(self, g, CLIENT_ID, CLIENT_SECRET,
>                               self.AUTH_URL, self.TOKEN_URL)
>         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:
>             self.session.token = None
>             self.graph = None
>
>         if user:
>             return dict(first_name = user['first_name'],
>                         last_name = user['last_name'],
>                         username = user['id'])
>
> auth.settings.login_form=FaceBookAccount(globals())
>
> 2010/8/9 Matt <[email protected]>:
>
>
>
> > I have acustomlogin method.  I would like to set the group, and
> > names etc.  I noticed the mappings for facebook in the docs, but was a
> > little confised about how to apply it.  Can I apply a mapping from
> > within the actuallogin_methodclass, and if so how?
>
> > Thanks.

Reply via email to