views:

33

answers:

1

I'm writing an application with Google Web Toolkit and am trying to figure out the Google Apps domain of the user currently logged in.

public LoginInfo login(String requestUri) {
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    LoginInfo loginInfo = new LoginInfo();

    if (user != null) {
        loginInfo.setLoggedIn(true);
        loginInfo.setEmailAddress(user.getEmail());
        loginInfo.setNickname(user.getNickname());
        loginInfo.setAuthDomain(user.getAuthDomain());
        loginInfo.setLogoutUrl(userService.createLogoutURL(requestUri));
        loginInfo.setIsAdmin(userService.isUserAdmin());
    } else {
        loginInfo.setLoggedIn(false);
        loginInfo.setLoginUrl(userService.createLoginURL(requestUri));
    }
    return loginInfo;
}

But user.getAuthDomain() is always returning "gmail.com".

which should be correct for non-google-apps-users. But it also returns gmail.com when I log in with my google apps account.

Any ideas why? Or is there an other method to get the users current domain?

+1  A: 

I would use GWT.getHostPageBaseUrl() to access the host page's base URL, and parse the domain name from that.

eneveu
Unfortunately that does not help much. I'm writing a GMail gadget and when adding the gadget to google, google runs the code through a proxy, so the URL I get with the function above is https://uh3gufbh6g8qo19mvti4ckvkp41gbe51-a-gm-opensocial.googleusercontent.com/gadgets/ and not the domain the gadget is loaded from.
JochenJung
Ouch, didn't think about the proxy... I guess you'll have to solve this using the AppEngine API then. I'm no expert, but couldn't you parse the domain from the user's email (user.getEmail())? Or are those separate too?We were using Google Apps at my last company, and my email address was [email protected]
eneveu
This would indeed be a solution, though I'm not sure whether this is always the same domain. Could be there are Companies setting up multiple domains for one apps account. I would like user.getAuthDomain() then to return a unique, primary domain for this company, though I'm quite sure it will always return the domain of the users email, if it worked. So yes, maybe parsing the email is the best solution, there is.
JochenJung