DarkGhostHunter / Laraguard

"On-premises 2FA Authentication for all your users out-of-the-box
MIT License
266 stars 24 forks source link

Class name must be a valid object or a string #39

Closed cpraught closed 4 years ago

cpraught commented 4 years ago

Installed as per instructions, getting the following error:

Error Class name must be a valid object or a string

    $secret = $User->createTwoFactorAuth();

App/User.php

// 3rd Party Components

use \Spatie\Tags\HasTags; use Spatie\Permission\Traits\HasRoles; use DarkGhostHunter\Laraguard\TwoFactorAuthentication; use DarkGhostHunter\Laraguard\Contracts\TwoFactorAuthenticatable;

class User extends Authenticatable implements TwoFactorAuthenticatable { use Notifiable; use HasRoles; use HasTags; use TwoFactorAuthentication;

...

App/Http/Controllers/UserController.php

public function prepareTwoFactor(Request $request) { if( TRUE == ( $User = Auth::user() ) ) { $secret = $User->createTwoFactorAuth();

    return view('user.enable2fa', [
        'as_qr_code' => $secret->toQr(),     // As QR Code
        'as_uri'     => $secret->toUri(),    // As "otpauth://" URI.
        'as_string'  => $secret->toString(), // As a string
    ]);
}
...
DarkGhostHunter commented 4 years ago

Put the stack trace

cpraught commented 4 years ago

Right here! https://flareapp.io/share/17DkRyPv

DarkGhostHunter commented 4 years ago

Found the error.

This is not a package error, you seems to have edited your config and the Model is not being found. You should be able to debug further by checking if the class in laraguard.model exists.

cpraught commented 4 years ago

I didn't edit the config file - to test, I went back to scratch, and redid the package install using just the following commands. Still getting the same error, and /config/laraguard.php doesn't exist - it's pulling the config from the vendor directory:

Error Class name must be a valid object or a string

class UserController extends Controller {

public function prepareTwoFactor(Request $request) { > $secret = $request->user()->createTwoFactorAuth();

Command list

composer require darkghosthunter/laraguard composer update composer dumpautoload php artisan migrate vi app/User.php vi app/Http/Controllers/UserController.php mkdir resources/views/user/ vi resources/views/user/2fa.blade.php vi routes/web.php

cpraught commented 4 years ago

Sorry to keep blowing this up - if I dump out class_implements and test with interface_exists, both show that DarkGhostHunter\Laraguard\Contracts\TwoFactorAuthenticatable is there.

Array ( [Illuminate\Contracts\Auth\CanResetPassword] => Illuminate\Contracts\Auth\CanResetPassword [Illuminate\Contracts\Auth\Access\Authorizable] => Illuminate\Contracts\Auth\Access\Authorizable [Illuminate\Contracts\Auth\Authenticatable] => Illuminate\Contracts\Auth\Authenticatable [Illuminate\Contracts\Support\Arrayable] => Illuminate\Contracts\Support\Arrayable [ArrayAccess] => ArrayAccess [Illuminate\Contracts\Support\Jsonable] => Illuminate\Contracts\Support\Jsonable [JsonSerializable] => JsonSerializable [Illuminate\Contracts\Queue\QueueableEntity] => Illuminate\Contracts\Queue\QueueableEntity [Illuminate\Contracts\Routing\UrlRoutable] => Illuminate\Contracts\Routing\UrlRoutable [DarkGhostHunter\Laraguard\Contracts\TwoFactorAuthenticatable] => DarkGhostHunter\Laraguard\Contracts\TwoFactorAuthenticatable ) interface exists

DarkGhostHunter commented 4 years ago

Edit the vendor files and dump what does it gets, and the whole laraguard config just to be sure.

It SHOULD get the name of the class. For what the error says, it's getting anything but the class name.

DarkGhostHunter commented 4 years ago

PS: I'm talking about ddd() on the config on this line.

cpraught commented 4 years ago

Weirdly, the laraguard config didn't appear at all in a dump of the application's config object.

I started a fresh laravel project and installed laraguard and it seems to be working fine now.

mtveerman commented 4 years ago

I have this too. It happened when updating dependencies. I was using v1.0.1, after update it is now at v1.4.0. But in the meantime, this commit took place: https://github.com/DarkGhostHunter/Laraguard/commit/a6daa79f9dfecfaf23d21ad2cd3e561215fd5377

And this commit changes the config file. And the old config file does not have a 'model' property, and the 'listener' is still set to true.

php artisan vendor:publish --provider="DarkGhostHunter\Laraguard\LaraguardServiceProvider" --tag="config" --force

did the trick

DarkGhostHunter commented 4 years ago

Thanks, I'll put it on the readme for upgrading.