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 on
http://grafbook.appspot.com/helloFacebook

You can find the code of the example here:
http://code.google.com/r/michelecomitini-facebookaccess/source/browse#hg/applications/helloFacebook

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 <mattsn...@gmail.com>:
> I have a custom login 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 actual login_method class, and if so how?
>
> Thanks.

Reply via email to