Single Sign-On with Google Apps + App Engine

百般思念 提交于 2019-12-04 01:31:22

Later Google posted an article about how to do it in Python:

http://code.google.com/googleapps/marketplace/tutorial_python_gae.html

The summary is:

  • You must whitelist your "OpenID realm" (the app domain) in the Marketplace manifest XML.
  • The entry point used for the Google's universal navigation must contain the current Google Apps domain.
  • The entry point in your app redirects the user passing the Google Apps domain as federated_identity.

For example:

from google.appengine.api import users

# [...]

login_url = users.create_login_url(dest_url='http://my-app.appspot.com/',
                                   _auth_domain=None,
                                   federated_identity=google_apps_domain_name)
self.redirect(login_url)

This worked for me in Java:

Set<String> attributesRequest = new HashSet<String>();
String loginRealm = "http://myapp.appspot.com"; //Important that it is exactly the same as in application-manifest.xml, watch out for trailing slashes.
String destinationURL = req.getRequestURI() + "?" + req.getQueryString();
String federatedIdentity = null;
String authDomain = req.getParameter("hd"); //hd is the default parameter name. Contains the google apps domain name of the user logging on. example.com for example.
String loginUrl = userService.createLoginURL(destinationURL, federatedIdentity, authDomain, attributesRequest);     

Make sure to include

<Edition id="free">
    <Name>Cloud App Studio</Name>
    <Extension ref="navLink" />
    <Extension ref="realm" />
</Edition>

in the application-manifest.xml. That is, if it's free. The important part is to include the ref to realm.

Err, I haven't got the full scoop on this feature, but I do use both JanRain Engage (which Stackoverflow uses) with GAE apps. I think openid4java could do the job as well.

you didn't specify which language you are using. if it is java there is google library for openid+oauth.

http://code.google.com/p/step2/

Did you already know this link?

UserService userService = UserServiceFactory.getUserService();

if (userService.isUserLoggedIn()) {
  User user = userService.getCurrentUser();
  /* ...Do something with user.getFederatedIdentity(), which is the OpenID URL. */
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!