Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Google App Engine User Service work internally?

I'm just curious about how Google app engine's user service works. The way I understand it, the user logged in state is stored in the cookie. To get the cookie, one has to have a http servlet request object (for java servlet at least). But the user service api doesn't require any http servlet request as input, so how does it get the cookie to check the whether the user is logged in or not?

Tim

like image 714
Tim Avatar asked Dec 13 '10 15:12

Tim


People also ask

How does Google App Engine works?

App Engine is a fully managed, serverless platform for developing and hosting web applications at scale. You can choose from several popular languages, libraries, and frameworks to develop your apps, and then let App Engine take care of provisioning servers and scaling your app instances based on demand.

What service account does App Engine use?

The App Engine default service account is associated with your Cloud project and executes tasks on behalf of your apps running in App Engine.

How do I use Google App Engine locally?

Running your application locallySelect File > Open to open the project you want to run. Browse to the directory containing your project. Select Tools > Cloud Code > App Engine Run on a local App Engine Standard dev server.

Which programming environment is used for Google App Engine?

The App Engine standard environment is based on container instances running on Google's infrastructure. Containers are preconfigured with one of several available runtimes. The standard environment makes it easy to build and deploy an application that runs reliably even under heavy load and with large amounts of data.


2 Answers

During requests, user setup is handled by Google's servlet implementation.

[I]f the user is signed in and get the user's email address or OpenID identifier using the standard servlet API, with the request object's getUserPrincipal() method.

During the login process, the service works using redirects, similar to OpenID or OAuth. Take a look a the URLs throughout the login process.

  1. Users are redirected to a URL, which is handled by App Engine, on your app, something like:

    http://app.appspot.com/_ah/login?continue=http://app.appspot.com/dosomething

  2. The login handler redirects to the Google login service, something like:

    https://www.google.com/accounts/ServiceLogin?service=ah&continue=http://app.appspot.com/_ah/login%3Fcontinue%3Dhttp://app.appspot.com/dosomething&ltmpl=gm&ahname=Your+App+Name&sig=hf3322hdsk98fd8fh3u29hfh24as

  3. You login, then Google redirects you back to the app engine login handler:

    http://app.appspot.com/_ah/login?continue=http://app.appspot.com/dosomething

    When Google redirects, some query parameters will be passed to the App Engine login handler, and the built-in login handler will set the cookie.

  4. You are then redirected to the URL you specified, or where you 'started' from. Something like:

    http://app.appspot.com/dosomething

like image 79
Robert Kluin Avatar answered Oct 11 '22 07:10

Robert Kluin


What about the in the subsequent calls? For example (continuing from your point 4)

  1. User calls the servlet http://app.appspot.com/dosomethingelse

In the servlet dosoemthingelse, I can again call UserService like this

UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
String userId = user.getUserId();

How does this userService instance gets the cookie to know who is the currently logged in user?

like image 36
Tim Shi Avatar answered Oct 11 '22 06:10

Tim Shi