Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow for connecting provider with existing user when not signed in #115

Open
danschultzer opened this issue Dec 12, 2019 · 5 comments
Open
Labels
enhancement New feature or request

Comments

@danschultzer
Copy link
Collaborator

Found this interesting, this is how CBS handles the exact flow (connect w/ email, then try and connect w/ an account w/ that email)

image

ie

  1. Require a password; don't let them chose a new email
  2. Upon entering the password, your accounts are linked so you can log in either way.

Originally posted by @coladarci in #113 (comment)

@danschultzer
Copy link
Collaborator Author

This makes a lot of sense. I’ll see if it’s possible with Pow. It ties in with the custom with flow planned with pow-auth/pow#6

@danschultzer
Copy link
Collaborator Author

danschultzer commented Mar 28, 2020

Related: #18

@sveredyuk
Copy link

Hi, @danhunsaker. I have a combination of all user issues. I am using Pow and PowAssent for API-bases authentication with my frontend client.

  1. Users registered with email/password can not register via OAuth (I am using Google and GitHub)
  2. Only new users can register with OAuth
  3. Users registered with Google can't log in with Github even if the same email been used.

Do you need any help with issues to resolve this blocker?

@danschultzer
Copy link
Collaborator Author

Hi @sveredyuk sorry I missed this comment.

So this issue would only resolve how the flow works on web rather than API, though it may make it easier to work with the plug methods.

To make this work I'll have to figure out the users current available auth methods. In your case, if the user has previously used Google and there's now a conflict on user id (email) trying to auth with Github, it should probably present the above dialog with an "Sign in with Google" method.

I also think in many cases it makes sense to bypass this if the email from the provider has been verified, though I don't want this to be enabled by default (email isn't a secure channel). I would like to update the docs on how you can sign in the user automatically if the verified email exists in the system already. This would apply to custom controllers as well (so can work in API).

Currently when there's a constraint error on the user id field, it's treated the same way as if the user id was invalid or missing, and you have to enter a new one. So you can listen for the :invalid_user_id_field error after calling PowAssent.Plug.callback_upsert/4 and then look up and upsert.

Alternatively you can bypass all this by having a custom user identities context with a create_user method where you look up the user first based on the user params.

@caspg
Copy link

caspg commented Feb 10, 2022

@danschultzer Is there any plan for how to solve this challenge? Maybe there is some example for that?

Thanks for this library 👍 👍

EDIT:

I'm playing with custom user identities context. I've added create_user method as suggested that look up the user first and then creates user_identitity using upsert. Does it look ok?

def create_user(user_identity_params, user_params, user_id_params) do
    case VelomapEx.Users.get_by(%{email: email}) do
      nil ->
        pow_assent_create_user(user_identity_params, user_params, user_id_params)

      user ->
        case pow_assent_upsert(user, user_identity_params) do
          {:ok, _} -> {:ok, user}
          err -> err
        end
    end
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants