imanghafoori1 / laravel-MasterPass

Helps you securely setup a master password and login into user accounts with it.
MIT License
364 stars 29 forks source link

Enhancement : Configure the auth provider #17

Closed Nuranto closed 5 years ago

Nuranto commented 5 years ago

Suggestion :

     private function changeUsersDriver()
     {
-        $driver = config()->get('auth.providers.users.driver');
+        $driver = config()->get('auth.providers.'.confi
g('master_password.auth_provider').'.driver');
         if (in_array($driver, ['eloquent', 'database'])) {
-            config()->set('auth.providers.users.driver', $driver.'MasterPassword');
+            config()->set('auth.providers.'.config('master_password.auth_provider').'.driver', $driver.'MasterPassword');
         }
     }

and in config :

     'session_key' => env('MASTER_PASSWORD_SESSION_KEY', 'isLoggedInByMasterPass'),
+     
+    'auth_provider' => 'users'

Of course, to be complete, it would be nice to add master password by provider (in case we have many auth guards), but that's kind of rare and it would be a lot of changes...

imanghafoori1 commented 5 years ago

I am currently seeking a solution like that, due to an email I received recently. but this does not solve the issue.

that users needs to be fetched dynamically for each auth()->check() call.

Nuranto commented 5 years ago

Well, it did solved my issue. Maybe we're not talking about the same thing ?

imanghafoori1 commented 5 years ago
private function changeUsersDriver()
    {
        foreach(config('auth.providers', []) as $providerName => $providerConfig) {
            $driver = $providerConfig['driver'];

            if (in_array($driver, ['eloquent', 'database'])) {
                config()->set("auth.providers.$providerName.driver", $driver.'MasterPassword');
            }
        }
    }

this should do the job

imanghafoori1 commented 5 years ago

Support for multiple guards is added in the v2.0.3