First of all you need to get the google_auth.json file to use OAuth
To get that you need to register your Google account as a webdeveloper
You can find how get the information on Google :)
Â
Then u can change ur auth table in this way
Â
In the model.py
Â
from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db,secure=True)
crud, service, plugins = Crud(db), Service(), PluginManager()
## ------------TABELLE USER ------------------- ##
## create all tables needed by auth if not custom tables
auth.settings.extra_fields['auth_user']= [
 Field('phone', type='string', label='Telefono'),
 Field('country',type='string', label='Nazione'),
 Field('city',type='string', label='Città '),
 Field('address',type='string', label='Indirizzo'),
 Field('auth_login', type='string', default='basic', label='Tipo Login',readable=False, writable=False),
 Field('url_img', requires=IS_EMPTY_OR(IS_URL()), label='Link Immagine Profile',readable=False, writable=False),
 Field('nickname', type='string', label='Nickname'),
 Field('birthdate', type='date', label='Data Di nascita'),
 Field('gender', type = 'string', label='Genere' ,requires = IS_IN_SET(['M','F']), default = 'M'),
 Field('facebook_id', type='string', label='Username di Facebook',readable=False, writable=False),
 Field('twitter_id', type='string', label='Username di Twitter',readable=False, writable=False),
 Field('google_id', type='string', label='Username di Google',readable=False, writable=False ),
 Field('linkedin_id', type='string', label='Username di Linkedin',readable=False, writable=False),
 ]
auth.define_tables(username=False, signature=True)
Â
In The Controller
Â
Import AccountAccess
def google():
   if auth.is_logged_in():
       redirect(URL(r=request, c='default', f='index'))
   folder = request.folder
   google_access = AccountAccess.GoogleAccount(folder)
   auth.settings.login_form=google_access
Â
   return auth.login(next=URL(r=request, c='default', f='index'))
Â
Â
In the Module section
Create the AccountAccess module
import oauth2 as oauth
from gluon.contrib.login_methods.oauth10a_account import OAuthAccount as OAuthAccount10a
from gluon.contrib.login_methods.oauth20_account import OAuthAccount
from oauthtwitter_account import OAuthAccount as OauthAccountTwitter
import os
import storage
import urllib2
from oauth2 import Client, Consumer, Token
class GoogleAccount(OAuthAccount):
   "OAuth 2.0 for Google"
   def __init__(self,db,session,request,response,folder):
       with open(os.path.join(folder,
'private/google_auth.json'), 'rb') as f:
           gai = storage.Storage(json.load(f)['web'])
       self.db = db
       self.request = request
       self.response = response
       self.session = session
       g = dict(
               request=request,
               response=response,
               session=session,
               )
       OAuthAccount.__init__(self,g, 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 https://www.googleapis.com/auth/plus.login',
                             approval_prompt='auto',
                             access_type = 'offline',
                             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 None
       data = uinfo_stream.read()
       uinfo = json.loads(data)
       username = uinfo['id']
       if uinfo:
           gender = 'M'
           if uinfo['gender'][0].lower() == 'f':
               gender = 'F'
           existent = self.db(self.db.auth_user.email == uinfo["email"]).select(
self.db.auth_user.id,self.db.auth_user.auth_login).first()
           if existent:
               if existent.auth_login <> 'Google':
                   diz_account = dict(
                        username = uinfo['email'],
                        gender = gender,
                        auth_login = 'Google',
                        url_img = uinfo.get('picture', ''),
                        google_id = uinfo['id'],
                        registration_id = uinfo['id']
                   )
                   existent.update_record(**diz_account)
               return dict(first_name = uinfo.get('given_name', uinfo["name"].split()[0]),
                           last_name = uinfo.get('family_name', uinfo["name"].split()[-1]),
                           username = uinfo['email'],
                           email = uinfo['email'],
                           gender = gender,
                           auth_login = 'Google',
                           birthdate = uinfo.get('birthday', ''),
                           url_img = uinfo.get('picture', ''),
                           google_id = uinfo['id'],
                           registration_id = uinfo['id']
                           )
           else:
#Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.db.auth.send_welcome_email(user)
               return dict(first_name = uinfo.get('given_name', uinfo["name"].split()[0]),
                           last_name = uinfo.get('family_name', uinfo["name"].split()[-1]),
                           username = uinfo['email'],
                           email = uinfo['email'],
                           gender = gender,
                           auth_login = 'Google',
                           birthdate = uinfo.get('birthday', ''),
                           url_img = uinfo.get('picture', ''),
                           google_id = uinfo['id'],
                           registration_id = uinfo['id']
                           )
   def call_api(self):
       api_return = urllib.urlopen("
https://www.googleapis.com/oauth2/v1/userinfo?access_token=%s" % self.accessToken())
       user = json.loads(api_return.read())
       if user:
           return user
       else:
           session.token = None
           return None
Â
Â
It worked for me