Google Sign-In OAuth2.0

107 views
Skip to first unread message

Daniel Guilhermino

unread,
Dec 11, 2019, 12:50:47 AM12/11/19
to web2py-users
Hi,

I have been trying to use Google Sign-in on web2py through the book example, but Google allows us to receive user information on the same login page after the user has entered the login data.


I'm following this flow:

web2py login page -> google login page -> web2py login page (receiving user data) -> check and login page -> authorizes access.

With google's js feature:

function onSignIn (googleUser) {
        var profile = googleUser.getBasicProfile ();
}

I can get the data:

profile.getGivenName ()
profile.getFamilyName ()
profile.getEmail ()

and was redirecting the page to check and authorize access:

var page = 'https://myurl.com/oauth2callback?first_name=' + profile.getGivenName () + '& last_name =' + profile.getFamilyName () + '& email =' + profile.getEmail ();
 window.location.href = page;

In the oauth2callback controller:

Already tried:

registration_id = request.vars ['ident']
email = request.vars ['email']
first_name = request.vars ['first_name']
last_name = request.vars ['last_name']
    
class GoogleOAuth (OAuthAccount):
        def get_user (self):
            return dict (first_name = first_name, last_name = last_name, email = email)

auth.settings.login_form = GoogleOAuth ()

Already tried:

auth.settings.login_form = lambda profile: dict (registration_id =
                  request.vars ['ident'],
                 email = request.vars ['email'],
                 first_name = request.vars ['first_name'],
                 last_name = request.vars ['last_name'])

And always the result is None.

Has anyone been able to implement or knows about it?

Thanks in advance!

Best regards,

Daniel

Dave S

unread,
Dec 11, 2019, 2:41:14 AM12/11/19
to web2py-users

Perhaps I'm being a little slow, but I don't see "ident" in your URL ('var page = ....'), but you try to pull it out of request.vars[] in your callback.

Am I missing something?

/dps
 

Daniel Guilhermino

unread,
Dec 11, 2019, 6:54:10 AM12/11/19
to web2py-users
You're right!

But I've tried with 'ident' arg too... and return None.

I believe I am not passing all the correct arguments to:

auth.settings.login_form()

Thanks Dave!

Daniel Guilhermino

unread,
Dec 12, 2019, 12:44:45 PM12/12/19
to web2py-users
Hi,

Any ideas what parameters should I pass to auth.settings.login_form()?

Dave S

unread,
Dec 12, 2019, 7:44:15 PM12/12/19
to web2py-users


On Thursday, December 12, 2019 at 9:44:45 AM UTC-8, Daniel Guilhermino wrote:
Hi,

Any ideas what parameters should I pass to auth.settings.login_form()?


From the book,
<URL:http://www.web2py.com/books/default/chapter/29/09/access-control#Other-login-methods-and-login-forms>
it appears that you're supposed to pass a new class instance.
The book includes an example class for Facebook (Graph API),
and mentions importing the X509 class (in-box)
from gluon.contrib.login_methods.x509_auth import X509Account


From tools.py, there seems to be a CasAuth class used when web2py is the provider.

Since I haven't tried  implementing an OAuth2.0 deployment, I can't give you more detail.

/dps

 

Daniel Guilhermino

unread,
Dec 13, 2019, 8:54:06 AM12/13/19
to web2py-users
Hi Dave!

I have tried several ways proposed in this chapter of the book, I will devote the next few days to try again, as this is the only part of my project pending for publication ...

Thanks for the tip, I'll be back here with news ... and hope they are good!

Best regards!

Daniel Guilhermino
Reply all
Reply to author
Forward
0 new messages