http://web2py.com/books/default/chapter/29/09/access-control?search=oauth#Other-login-methods-and-login-forms


Grab the file google_auth.json from the google developer console and put in
private dir of your app

put  code similar to the one below in db.py:


from gluon.contrib.login_methods.oauth20_account import OAuthAccount

try:
    import json
except ImportError:
    from gluon.contrib import simplejson as json


class GoogleAccount(OAuthAccount):
    "OAuth 2.0 for Google"

    def __init__(self):
        with open(os.path.join(request.folder, 'private/google_auth.json'),
'rb') as f:
            gai = Storage(json.load(f)['web'])

        OAuthAccount.__init__(self, None, gai.client_id, gai.client_secret,
                              gai.auth_uri, gai.token_uri,
                              scope='
https://www.googleapis.com/auth/userinfo.profile
https://www.googleapis.com/auth/userinfo.email',
                              approval_prompt='force',
state="auth_provider=google")


    def get_user(self):

        token = self.accessToken()
        if not token:
            return None

        uinfo_url = '
https://www.googleapis.com/oauth2/v1/userinfo?access_token=%s' %
urllib2.quote(token, safe='')

        uinfo = None

        try:
            uinfo_stream = urllib2.urlopen(uinfo_url)
        except:
            session.token = None
            return
        data = uinfo_stream.read()
        uinfo = json.loads(data)

        username = uinfo['id']

        return dict(first_name = uinfo['given_name'],
                    last_name = uinfo['family_name'],
                    username = username,
                    email = uinfo['email'])

auth.settings.login_form = GoogleAccount()


2015-10-22 11:02 GMT+02:00 Leonel Câmara <leonelcam...@gmail.com>:

> I would try to use this:
>
> https://code.google.com/p/w2p-social-auth/
>
> --
> 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 web2py+unsubscr...@googlegroups.com.
> 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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to