delight-im / Android-DDP

[UNMAINTAINED] Meteor's Distributed Data Protocol (DDP) for clients on Android
Apache License 2.0
274 stars 54 forks source link

facebook login #84

Closed romaluca closed 8 years ago

romaluca commented 8 years ago

Hi, in your library therisn't loginWithFacebook method. I created a method in meteor for get params of accounts facebook and login the user with them.

let user = Accounts.updateOrCreateUserFromExternalService('facebook', params, {});
                var stampedToken = Accounts._generateStampedLoginToken();
                var hashStampedToken = Accounts._hashStampedToken(stampedToken);
                this.setUserId(user.userId);
                Meteor.users.update(user.userId,
                    {$push: {'services.resume.loginTokens': hashStampedToken}}
                );
                user = Meteor.users.findOne(user.userId);

It seems work. The user is logged. The problem is that if i do it, the property of your library: .meteor.isLoggedIn() continues to return false. Is there a way for set it a true, so i can use it everywhere like in the normal login?

Thanks!

ocram commented 8 years ago

Thanks a lot for trying this!

Maybe you can look into the code for the existing third-party logins in Extensions.md.

They also have a server-side part. So that could be what's missing to make this work.

Maybe @cprakashagr can help as well.

romaluca commented 8 years ago

Anyway my code is not good. Everytime that meteor or android studio restart the projects the session is lost and i have to do the login again. with normal login this not happens. I try to ask in the meteor's forum

romaluca commented 8 years ago

Hi, i've seen in your code that there is this private function:

private void saveLoginToken(final String token) {
        final SharedPreferences prefs = getSharedPreferences();
        final SharedPreferences.Editor editor = prefs.edit();
        editor.putString(Preferences.Keys.LOGIN_TOKEN, token);
        editor.apply();
    }

Can you set a mode where i can pass you my token so you can save it in your sharedpreferences? In this way i can do login with facebook manually and persist it.

Thanks!

ocram commented 8 years ago

Have you tried the Google+ or LinkedIn logins that are referenced here? Do they have the same problem that your code has?

Regarding the private function saveLoginToken, that actually saves the login token that the Meteor servers sends upon successful login with username/email and password.

Is this really the correct place for storing the Facebook token? Is that token something that you receive from the Meteor server as well?

As you can see in the initSession method, the token is used in loginWithToken to sign in using this token as a "resume" token. So it must be a token for a Meteor session.

romaluca commented 8 years ago

Excuse me i've solved. before from meteor i returned { userId: .., authToken: ... } i've seen that you catch id and token so i changed the parameters name and it works!

ocram commented 8 years ago

Thanks!

Great to hear that it's working now. Your solution will also be useful for others trying to implement social sign-in in the future.

Do you want to put all your server-side and client-side code for this feature into a repository or "Gist"? We could link to it from the Extensions.md file then.

romaluca commented 8 years ago

I've nevere done it before. i'll try it :)

xpluscal commented 8 years ago

Is the GIST for the solution somewhere available? Thanks

ocram commented 8 years ago

@xpluscal Not yet, unfortunately, but @romaluca created it and wanted to share it :)