Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.shin1ogawa;
import java.io.IOException;
import java.util.Set;
import java.util.logging.*;
import javax.servlet.http.*;
import com.google.appengine.api.users.*;
import com.google.appengine.repackaged.com.google.common.collect.Sets;
@SuppressWarnings("serial")
public class OpenIdTestServlet extends HttpServlet {
static final Logger LOGGER = Logger.getLogger(OpenIdTestServlet.class
.getName());
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
UserService us = UserServiceFactory.getUserService();
User currentUser = us.getCurrentUser();
if (currentUser != null) {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, " + currentUser.getEmail());
resp.getWriter().print(
"logoutUrl=" + us.createLogoutURL(req.getRequestURI()));
return;
}
Set<String> attributes = Sets.newHashSet("openid.mode=checkid_immediate",
"openid.ns=http://specs.openid.net/auth/2.0", "openid.return_to="
+ req.getRequestURI());
String federatedIdentity = null;
try {
String url = us.createLoginURL(req.getRequestURI(), "shin1.appspot.com",
federatedIdentity, attributes);
LOGGER.info("loginurl=" + url);
resp.sendRedirect(url);
} catch (Throwable th) {
LOGGER.log(Level.WARNING, "", th);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment