2010-08-28 67 views
14

使用App Engine上的内置OpenId可以实现SSO吗?我一直在尝试整合Marketplace应用,并在Google Apps(管理面板或通用导航)来访时登录用户。我失败了,然后现在我发现这个:使用Google Apps + App Engine的单一登录

“一个例外是做混合OpenID/OAuth的应用程序 - 白名单目前不适用这种方法。” (从here

我认为我必须使用库来实现OpenId,而不是使用内置的库在我的应用中使用Google Apps实现SSO?或者,如果可以使用内置的OpenId,有没有一个例子可以说明如何做到这一点?

+0

您没有具体说明您是否确认了您要集成的市场应用程序是否混合使用OpenID/OAuth或它是哪个市场应用程序。 – 2010-09-04 12:02:04

回答

6

之后,谷歌发布了关于如何做到这一点在Python的一篇文章:

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

的总结是:

  • 必须列入白名单的 “OpenID领域”(应用程序市场清单XML中的域)。
  • 用于Google通用导航的入口点必须包含当前的Google Apps域。
  • 您的应用中的入口点将通过Google Apps网域的用户重定向为federated_identity

例如:

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) 
1

错误,我没有得到这个功能的全部新闻,但我确实使用JanRain Engage(其中Stackoverflow使用)与GAE应用程序。我认为openid4java也可以完成这项工作。

1

难道你已经知道this link

UserService userService = UserServiceFactory.getUserService(); 

if (userService.isUserLoggedIn()) { 
    User user = userService.getCurrentUser(); 
    /* ...Do something with user.getFederatedIdentity(), which is the OpenID URL. */ 
} 
2

这在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);  

确保包括

<Edition id="free"> 
    <Name>Cloud App Studio</Name> 
    <Extension ref="navLink" /> 
    <Extension ref="realm" /> 
</Edition> 
在应用程序的manifest.xml

。也就是说,如果它是免费的。重要的部分是包括参考领域。

+1

谢谢保罗,这个作品很棒!请注意:如下所示,将其放置在映射到/ _ah/login_required的servlet中:http://code.google.com/appengine/articles/openid.html – Stefan 2012-03-21 15:19:04