openID login (on localhost) at google app engine

848 Views Asked by At

I've written openID login for google App engine.

static {
        openIdProviders = new HashMap<String, String>();
        openIdProviders.put("Google", "https://www.google.com/accounts/o8/id");
        openIdProviders.put("Yahoo", "yahoo.com");
    }

    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        UserService userService = UserServiceFactory.getUserService();

        User user = userService.getCurrentUser(); // or req.getUserPrincipal()
        Set<String> attributes = new HashSet();

        resp.setContentType("text/html");
        PrintWriter out = resp.getWriter();

        if (user != null) {
            out.println("Hello <i>" + user.getNickname() + "</i>!");
            out.println("[<a href=\"" + userService.createLogoutURL(req.getRequestURI())+ "\">sign out</a>]");
        } else {
            out.println("Sign in at: ");
            for (String providerName : openIdProviders.keySet()) {
                String providerUrl = openIdProviders.get(providerName);
                String loginUrl = userService.createLoginURL(req.getRequestURI(), null, providerUrl, attributes);
                out.println("[<a href=\"" + loginUrl + "\">" + providerName+ "</a>] ");
            }
        }
    }

everything works very well when I deploy my app. No problems. after choosing openID provider, I'm redirected to that page:

sample.appspot.com/_ah/login_redir?claimid=[OPen ID provider]=[my sample page]/_ah/login_required

that's my servlet.

 <servlet>
        <servlet-name>Authorization</servlet-name>
        <servlet-class>ge.eid.test.Authorization</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>Authorization</servlet-name>
        <url-pattern>/_ah/login_required</url-pattern>
    </servlet-mapping>

ok. everything is fine! but, when I run the sampe app at localhost, I have another redirection URL:

http://localhost:8888/_ah/login?continue=/F_ah/Flogin_required

so I do not have OpenID login. I have something like that:

enter image description here question 1) How to create openID login at localhost too.

1

There are 1 best solutions below

0
On

This is a normal behaviour, because on localhost you might want to try many different accounts and it would be a mess if you had to actually login every time with a real one. So when on localhost you can just simulate an OpenID user just by providing any email you want and checking if you want to be an admin or not.