I have a GAE Python app which I am transitioning from using the App Engine users library to oauth2 using oauth2client.
I read some questions (eg, Managing users authentication in Google App Engine) about using oauth2 with App Engine, and it seemed that the users library does not understand if any other authentication systems (ie, oauth2) are being used to authenticate users.
So I was planning to hand-roll my logged-in/out model using oauth2 instead of the users library. However, I was then surprised to find out that when using the oauth2client.appengine library, the calls to the users library returned data from the oauth2 authenticated user, as shown in this sample code:
import webapp2
from google.appengine.api import users
from oauth2client.appengine import OAuth2Decorator
oauth2deco = OAuth2Decorator(...)
class TestOauth(webapp2.RequestHandler):
@oauth2deco.oauth_required
def get(self):
print users.get_current_user() # Prints user's email
app = webapp2.WSGIApplication([
('/', TestOauth),
(oauth2deco.callback_path, oauth2deco.callback_handler())
])
In this sample above, the user is prompted to log in with an oauth2 login screen (and not the traditional App Engine login screen from users.CreateLoginURL), but the call to users.get_current_user() works as expected.
I'm curious, how does this work? I see that the users.get_current_user() function returns a new User() object, which seems to read some environment variables: https://cloud.google.com/appengine/docs/standard/python/refdocs/modules/google/appengine/api/users#User
However, I never saw these being set by oauth2client, so I'm still confused.