manager = new ConsumerManager();
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
//取得GoogleOpenID
String userSuppliedString = "https://www.google.com/accounts/o8/id";
List discoveries = manager.discover(userSuppliedString);
DiscoveryInformation discovered = manager.associate(discoveries);
request.getSession().setAttribute("openid-disc", discovered);
String returnURL = "http://localhost:8084/WebOpenIdTomcat/faces/index.xhtml";
AuthRequest authReq = manager.authenticate(discovered, returnURL);
FetchRequest fetch = FetchRequest.createFetchRequest();
fetch.addAttribute("email", "http://axschema.org/contact/email", true);
fetch.addAttribute("firstname", "http://axschema.org/namePerson/first", true);
fetch.addAttribute("lastname", "http://axschema.org/namePerson/last", true);
fetch.addAttribute("country", "http://axschema.org/contact/country/home", true);
fetch.addAttribute("language", "http://axschema.org/pref/language", true);
authReq.addExtension(fetch);
//重定向到OP認証
response.sendRedirect(authReq.getDestinationUrl(true)); |
B03.安全性(Security)與風險管理 > OpenID / OAuth >