Skip to content

The third-party login lacks a bit of flexibility #4694

Closed

Description

@oallouch

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.

What do you think of it ?

Olivier from Paris

Activity

  1. changed the title [-]The third-party login lack a bit of flexibility[/-] [+]The third-party login lacks a bit of flexibility[/+] on Apr 2, 2018
  2. flovilmart commented on Apr 2, 2018

    @flovilmart
    Contributor

    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?

  3. oallouch commented on Apr 3, 2018

    @oallouch
    ContributorAuthor

    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.

  4. oallouch commented on Apr 3, 2018

    @oallouch
    ContributorAuthor

    Oups. I forgot : I would have loved to have a server _linkWith with the masterKey (see the workaround above)

    Thx

  5. stale commented on Sep 18, 2018

    @stale

    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.

  6. mikecann commented on Oct 27, 2018

    @mikecann

    @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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions