Tip: Saving Google OAuth Profile Pictures

85 views
Skip to first unread message

Ali

unread,
Apr 19, 2025, 4:09:08 PM4/19/25
to py4web

Hi all,

This is a comment, not a question.

By default, the scaffold app using Google OAuth stores the user's first name, last name, and email in the auth_user table—but not the profile picture. You can include the profile picture URL with just two lines of code added to common.py:

1. Add the following line here (adds a new field to auth_user):
auth = Auth(session, db, define_tables=False)
auth.extra_auth_user_fields = [Field('profile_picture', 'text',
                                     readable=False, writable=False)]

2. Add the following line here:
    from py4web.utils.auth_plugins.oauth2google import OAuth2Google  # TESTED
    OAuth2Google.maps['profile_picture'] = 'picture'

Once the profile picture URL is stored in auth_user, you can easily use it along with other user information.

-ali

Massimo

unread,
May 10, 2025, 2:32:21 PM5/10/25
to py4web
added to docs

Ali

unread,
May 11, 2025, 8:29:22 PM5/11/25
to py4web
Thank you!

I wonder when the changes will be available on py4web.com.

Also, a minor point. It may not be clear where the word "here" in the sentence "Add the following line here (adds a new field to auth_user):" refers to in the documentation. It might be a good idea to remove this sentence altogether and add a comment in the following code section indicating that the new line adds a new field to auth_user. 
Reply all
Reply to author
Forward
0 new messages