Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App Engine Java - Currently Using Federated Login/Openid - How Should I Persist a Successfully Authenticated Facebook User?

I have my Google App Engine Java application humming along nicely using openid/federated login.

I save a UserProfile object that I persist once we have a logged in user that saves a reference to the UserService.getCurrentUser() object (and its userid) like so:


    UserService userService = UserServiceFactory.getUserService();
    user = userService.getCurrentUser();
    userId = user.getUserId();
    profile = UserProfileBin.getInstance().getByUserId(user.getUserId());
    if (profile == null) {
        profile = new UserProfile();
        profile.setUser(user);
        profile.setUserId(user.getUserId());
        profile.setCreatedDate(new Date());
        pm.makePersistent(profile);
        id = profile.getId().getId();
    }

...

Well, that is all working fantastically. I'm using the openId selector and am logging into the app using a bunch of different openid providers. There are no issues.

Now, I want to let people use their facebook logins, and I have that part going as well. I'm using the server side authentication flow. I'm able to complete the authorization and retrieve the access token, and I am using restFB. I can connect to the graph api and get whatever I need.

So my question is this: I don't know what the best way is to go about taking this information and letting my app know that somebody is logged in.

I assume Userservice.getCurrentUser() is a no go.

I see OauthService.getCurrentUser(). That would be awesome if that "knew" that I had a Facebook user logged in. Then my user checks would just be along the lines of:


User user = UserService.getCurrentUser()
if(user == null)
{
    user = OAuthService.getCurrentUser();
}

and merrily on my way I would go.

However, I don't see a way to register my Facebook user with OAuthService or anything.

I'm sure this has been done before.

How should I go about it? Is there a cute way to do this, or am I stuck turning on sessions and making a custom user object for my Facebook user and sticking it in the session and running a filter?

like image 724
dyeryn Avatar asked Feb 08 '11 03:02

dyeryn


1 Answers

You'll need to enable sessions and store the relevant info about the user's login in the session. You may be able to configure things so that session data isn't loaded for users who are logged in using OpenID. I'm not sure, though, because I'm not overly familiar with Java.

like image 171
Nick Johnson Avatar answered Nov 22 '22 17:11

Nick Johnson