Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

BindsLdapUserModel - Laravel 5.8 #696

Closed
wants to merge 2 commits into from
Closed

BindsLdapUserModel - Laravel 5.8 #696

wants to merge 2 commits into from

Conversation

andrefigueira93
Copy link

@andrefigueira93 andrefigueira93 commented Mar 21, 2019

File Being Edited => Adldap\Laravel\Listeners\BindsLdapUserModel

In Laravel 5.8 i have had to change from

public function handle($event)
    {
        if (
            $this->isUsingAdldapProvider($event->guard)
            && $this->canBind($event->user)
            && $user = Resolver::byModel($event->user)
        ) {
            $event->user->setLdapUser($user);
        }
    }

    protected function isUsingAdldapProvider($guard) : bool
    {
        return Auth::guard($guard)->getProvider() instanceof DatabaseUserProvider;
    }

to

public function handle($event)
    {
        if (
            $this->isUsingAdldapProvider()
            && $this->canBind($event->user)
            && $user = Resolver::byModel($event->user)
        ) {
            $event->user->setLdapUser($user);
        }
    }

    protected function isUsingAdldapProvider() : bool
    {
        return Auth::guard()->getProvider() instanceof DatabaseUserProvider;
    }

Unique way that works

@andrefigueira93 andrefigueira93 changed the title V5.0 V10.0 Mar 21, 2019
@andrefigueira93 andrefigueira93 changed the title V10.0 BindsLdapUserModel - Laravel 5.8 Mar 21, 2019
@stevebauman
Copy link
Member

Hi @andrefigueira93, I don't think this change would resolve the issue you're having.

The Authenticated and Login events both have the $guard property set to the name of the guard that your user is authenticated with. This property allows us to locate the correct guard and ensure you're using an Adldap2 provider with it so no exceptions are generated.

Authenticated Event:
https://github.com/laravel/framework/blob/cd7486a4355be57e8928f89048a25f30883f202f/src/Illuminate/Auth/Events/Authenticated.php#L16

Login Event:
https://github.com/laravel/framework/blob/cd7486a4355be57e8928f89048a25f30883f202f/src/Illuminate/Auth/Events/Login.php#L16

What is the guard property set to on the Login and Authenticated events?

@andrefigueira93
Copy link
Author

andrefigueira93 commented Mar 21, 2019

Reproduction of the error
Captura de Tela 2019-03-21 às 11 32 52

The problem is here -> dd($event)
Captura de Tela 2019-03-21 às 11 36 36

The $event doesn't have the ->guard property.

Auth::guard()->getProvider() instanceof DatabaseUserProvider is enough to verify.

@stevebauman
Copy link
Member

Strange, are you sure you're using Laravel 5.8?

This is definitely a bug though, I thought the $guard property was available for Laravel 5.5 or greater, but it's only available on Laravel 5.7 or greater.

Going to patch this now, thanks @andrefigueira93!

@andrefigueira93
Copy link
Author

Tried in 5.6, 5.7 and 5.8 =/ all of them are reproducing this error =/

You're welcome! I'm here to help =)

@stevebauman
Copy link
Member

Are you sure you're using those versions? I'm using v6.0 model binding in 5.7 and 5.8 and don't receive this exception.

stevebauman added a commit that referenced this pull request Mar 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants