Framework: [5.2] TokenRepositoryInterface is not bound

Created on 27 Dec 2015  Â·  7Comments  Â·  Source: laravel/framework

In 5.1 if you run this command on tinker:

app()->make('Illuminate\Auth\Passwords\TokenRepositoryInterface');

The IoC container would instantiate the correct concrete class.

In 5.2 it outputs this error:

ReflectionException with message 'Class auth.password.tokens does not exist'

I tried to fix the error, but didn't have success. It seems that this issue has something to do with the new multi-auth architecture.

On my app I am binding the concrete class (DatabaseTokenRepository) directly on the AppServiceProvider.

bug

Most helpful comment

You can get an instance of the token repository via
Password::getRepository().

On Sun, Dec 27, 2015 at 11:20 AM, Rodrigo Pedra Brum <
[email protected]> wrote:

Hi @taylorotwell https://github.com/taylorotwell ,

I used it to let the user change the password whille logged in without the
need to send the reset e-mail.

As the ResetsPasswords@postReset method requires the token field, I
injected the TokenRepositoryInterface to generate the token for the
auth.reset view:

public function getReset( $token = null )    {        if (auth()->guest() && is_null( $token )) {            return $this->getEmail();        }        if (auth()->check() && is_null( $token )) {            $token = $this->tokenRepository->create( auth()->user() );        }        return view( 'auth.reset' )->with( 'token', $token );    }

—
Reply to this email directly or view it on GitHub
https://github.com/laravel/framework/issues/11555#issuecomment-167428208
.

All 7 comments

Thanks for reporting. Ping @taylorotwell. The auth:clear-resets command is also broken.

Hey @rodrigopedra,

Yeah I can see how this would be an issue in 5.2. Can you tell me your use case for wanting to access the token repository directly?

@GrahamCampbell auth:clear-resets is fixed now.

Hi @taylorotwell ,

I used it to let the user change the password whille logged in without the need to send the reset e-mail.

As the ResetsPasswords@postReset method requires the token field, I injected the TokenRepositoryInterface to generate the token for the auth.reset view:

    public function getReset( $token = null )
    {
        if (auth()->guest() && is_null( $token )) {
            return $this->getEmail();
        }

        if (auth()->check() && is_null( $token )) {
            // EDIT: $this->tokenRepository is the concrete instance of TokenRepositoryInterface
            // injected in the constructor
            $token = $this->tokenRepository->create( auth()->user() );
        }

        return view( 'auth.reset' )->with( 'token', $token );
    }

You can get an instance of the token repository via
Password::getRepository().

On Sun, Dec 27, 2015 at 11:20 AM, Rodrigo Pedra Brum <
[email protected]> wrote:

Hi @taylorotwell https://github.com/taylorotwell ,

I used it to let the user change the password whille logged in without the
need to send the reset e-mail.

As the ResetsPasswords@postReset method requires the token field, I
injected the TokenRepositoryInterface to generate the token for the
auth.reset view:

public function getReset( $token = null )    {        if (auth()->guest() && is_null( $token )) {            return $this->getEmail();        }        if (auth()->check() && is_null( $token )) {            $token = $this->tokenRepository->create( auth()->user() );        }        return view( 'auth.reset' )->with( 'token', $token );    }

—
Reply to this email directly or view it on GitHub
https://github.com/laravel/framework/issues/11555#issuecomment-167428208
.

ok, thanks!

It's not protected: http://d.pr/i/1jwTI/4fvqZTRv

On Mon, Jan 4, 2016 at 4:22 PM, Lukasz Brodowski [email protected]
wrote:

The getRepository method is protected so it gives me a

call_user_func_array() expects parameter 1 to be a valid callback, cannot
access protected method
Illuminate\Auth\Passwords\PasswordBroker::getRepository().

Any other way to get the token repository?

—
Reply to this email directly or view it on GitHub
https://github.com/laravel/framework/issues/11555#issuecomment-168829716
.

@taylorotwell yup, sorry for that. Mine was still protected, all fixed now thank you so much. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gabriellimo picture gabriellimo  Â·  3Comments

RomainSauvaire picture RomainSauvaire  Â·  3Comments

PhiloNL picture PhiloNL  Â·  3Comments

lzp819739483 picture lzp819739483  Â·  3Comments

progmars picture progmars  Â·  3Comments