You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The third-party login lacks a bit of flexibility #4694
My usernames are emails.
I'd like Facebook or Google logins to automatically link with a potential existing account.
What I did was:
On the client side:
. I use hello.js to retrieve an access-token
. I send the token to the server. I don't call _linkWith on the client, otherwise a User might be created with a random username.
. The server uses the access_token to retrieve the email using an OAuth service. I also check that the e-mail is verified if necessary.
. I search for the User using its email (it's the username). If not found, I create it. I can now create the user. The username is the email and my beforeSave hook will work (it wants e-mails). If the user is created, it has a random password.
. Then I do a server _linkWith. Looking at the js sdk source, I saw it's only a save with some specific data. My code for this is:
//---- linkWith (the server version) ----//
await user.save({
authData: {
[provider]: authData
}
}, {useMasterKey: true}); // see ParseUser's UserController's linkWith
. Then I return a Parse sessionToken, taken from the User returned the signup call or from a server login. For this server login, I had to dig deep (for me) inside the Parse codebase. The code I used is:
/**
* . creates a session using the masterKey
* . code taken from Parse.UsersRouter's handleLogIn
* @param userId
* @param can be 'password' or 'facebook' (or 'google'...)
*/
function serverLogin({ userId, authProvider, installationId }) {
// if we put Auth on top of this file, it's too early and throws an exception
const Auth = require('../node_modules/parse-server/lib/Auth');
const Config = require('../node_modules/parse-server/lib/Config');
const config = Config.get(Parse.applicationId);
const { sessionData, createSession } = Auth.createSession(config, {
userId: userId,
createdWith: {
action: 'login',
authProvider
},
installationId
});
createSession();
return sessionData.sessionToken;
}
I think you should be able to login on the server like we can signup Using the sessionToken with 'become' is nice and elegant.
I'm not sure this is an issue with parse-server itself. It seems to tie together the 3rd party auth and a particular piece of your logic (that you require emails and username to be the same and only thing) and make additional assumptions on the mail provided by facebook / google (they are optional) etc...
I'd love to be able to login on the server (using the masterKey) and retrieve the sessionToken.
Passing the username for a _linkWith with an automatic linkage would be great, but it would add the notion of verified e-mail and an interface change for the OAuth modules, so no.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@oallouch hi mate, Im trying to user _linkWith on the client as per the docs (https://docs.parseplatform.org/js/guide/#linking-users) to use social logins to link to an existing user. Have you had any luck with this or is that the reason you have had to do the above workarounds?
Activity
[-]The third-party login lack a bit of flexibility[/-][+]The third-party login lacks a bit of flexibility[/+]flovilmart commentedon Apr 2, 2018
I'm not sure this is an issue with parse-server itself. It seems to tie together the 3rd party auth and a particular piece of your logic (that you require emails and username to be the same and only thing) and make additional assumptions on the mail provided by facebook / google (they are optional) etc...
What changes do you want to see in parse-server?
oallouch commentedon Apr 3, 2018
I'd love to be able to login on the server (using the masterKey) and retrieve the sessionToken.
Passing the username for a _linkWith with an automatic linkage would be great, but it would add the notion of verified e-mail and an interface change for the OAuth modules, so no.
oallouch commentedon Apr 3, 2018
Oups. I forgot : I would have loved to have a server _linkWith with the masterKey (see the workaround above)
Thx
stale commentedon Sep 18, 2018
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
mikecann commentedon Oct 27, 2018
@oallouch hi mate, Im trying to user _linkWith on the client as per the docs (https://docs.parseplatform.org/js/guide/#linking-users) to use social logins to link to an existing user. Have you had any luck with this or is that the reason you have had to do the above workarounds?