Essentially I am looking to create a custom get_user method which will
invoke the second Web service to retrieve to user's first name and
last name, which in turn will populate the appropriate fields in the
auth_user table. I've tried a few variations with no luck. The
current iteration is below. Logins are successful, but I haven't been
able to populate the auth_user table with the firstname and
lastname...
#########################################################################
## Custom Web Service authentication
#########################################################################
import os
from gluon.contrib.pysimplesoap.client import SoapClient, SoapFault
def webservice_auth():
def webservice_login_aux(username,
password):
client =
SoapClient(wsdl=os.path.abspath(os.path.join('applications/test/
private/UserAuthentication.wsdl')))
response = client.getUserAuthentication(UserID=username)
try:
result = str(response.message)
if result == 'OK':
return True
except SoapFault:
return False
return webservice_login_aux
def get_user(self):
client =
SoapClient(wsdl=os.path.abspath(os.path.join('applications/test/
private/UserProfile.wsdl')))
response = client.getUserProfile(Userid=auth.user.username)
return dict(first_name = str(response.firstname),
last_name = str(response.lastname))
On Sep 15, 2:30 pm, Scott <[email protected]> wrote:
> 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.