App Engine’s integration of Google Accounts functionality generally works very well, however, it doesn’t have any direct support for Google’s multiple accounts feature. So if a user is signed into multiple Google accounts in their browser, then there is no easy way to give them the option to choose which of their accounts is used with your App Engine application.
This is especially troublesome if you need them to sign in with a specific account, e.g. if you have a whitelist of admin users, or you’re using verification URLs which have tokens tied to specific accounts, and therefore you need them to use a specific one.
But as App Engine doesn’t have direct support for Google Accounts’ multiple sign in feature, providing the user with a way of switching which of their Google accounts is used to authenticate with your app is a little bit tricky. But it is possible, read on...
users.create_login_urlwill show them the dialogue which lets them choose which account to use.
users.create_login_urlwill just redirect them straight back to your site. No good.
users.create_logout_urlso that they can then sign in again with the desired account.
users.create_logout_urlwill log them out of all of their accounts. So any Gmail/Calendar/Drive/Google+ pages that they had open will be logged out. That’s no good either.
So in order for the user to switch accounts, we need to use either
users.create_logout_url, but which one depends on whether or not the user is using the multiple accounts feature, which is something which we don’t know, until we try.
users.create_login_url(). If they come back signed into a different account (checked against their session), then we know they are using the multiple accounts feature and they have now selected a different account. Done. But if they are redirected straight back, still logged into the same account, then we know they are not using Google’s multiple accounts feature.
users.create_logout_url(users.create_login_url()). This should log the user out of whichever Google account they are logged into, and then send them back to the login screen where they can log in with a different account, and then return to our App Engine app.
(This assumes you’re using Django views and sessions, but the principal is the same with webapp.)
By Rob K and Adam A