Giter Site home page Giter Site logo

Comments (4)

VasquezSRE avatar VasquezSRE commented on June 9, 2024

Hello, Is there any way you can have two suppliers for the same user?

from eloquent-oauth.

adamwathan avatar adamwathan commented on June 9, 2024

Hey, unfortunately this isn't supported automatically yet. It's also not a good idea to rely on the email address provided by Facebook/GitHub to determine if two users are the same.

More details on that here: #19

It sounds like you are saving the email like this, yeah?

OAuth::login('github', function ($user, $details) {
    $user->email = $details->email;
    $user->save();
});

Since you can't guarantee uniqueness of emails from third-parties and you can't guarantee two third party users are really the same user based on email, you either need to remove the unique constraint (guessing this is not an option and you are providing email/password login as well) or save the email to a different column or table. Maybe a contact_email column that has no unique constraint.

Then implement a mutator on your User class that looks something like:

public function getEmailAttribute()
{
    return $this->attributes['email'] ?: $this->attributes['contact_email'];
}

...or check the oauth_identities table explicitly if you'd like to confirm the user definitely came from a third party source and their email is stored somewhere else.

I'm considering adding the ability to link an existing third party account with a new third party account, so if you login with GitHub, you could click a link that says "link with Facebook" so you could then login with either option. Trying to support connecting two existing accounts however is beyond the scope of this project, because it involves combining all sorts of existing data that will be specific to your app. Like if you are building a Reddit type of app, I can't possibly know how to assign all of one user's comments to another user, because this package knows nothing about comments. Maybe I can come up with a decent API for getting that process started and leave the data merging to the implementer but I'll have to think about it.

from eloquent-oauth.

dhruba-sarma avatar dhruba-sarma commented on June 9, 2024

A simple solution might help others.....

In core package root directory Authenticator.php return the user in callback like bellow

if ($callback) {
       $user = $callback($user, $userDetails);
 }

and in your application

OAuth::login($provider, function ($user, $details) {
   $exist = User::where('email', $details->email)->first();
     if($exist){
         $user = $exist;
     }
    $user->email = $details->email;
   return $user;
});

You got the idea It works for me .... Thank you
pn: $provider (facebook, google, or github)

from eloquent-oauth.

adamwathan avatar adamwathan commented on June 9, 2024

@dhruba-sarma Yeah I was thinking that as well, great idea. Going to get that in the next release.

from eloquent-oauth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.