Skip to content

Commit

Permalink
Allow multiple auth drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioribeiro committed Aug 23, 2016
1 parent 2e3dd3c commit aef183b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
31 changes: 24 additions & 7 deletions src/Services/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,44 @@ class Authentication
{
private $config;

private $authentication;
private $authentication = [];

public function __construct(Config $config, Application $app)
{
$this->config = $config;

$this->authentication = $app->make($this->config->get('authentication_ioc_binding'));
$this->instantiateAuthentication($app);
}

public function check()
{
$method = $this->config->get('authenticated_check_method');
return $this->executeAuthMethod($this->config->get('authenticated_check_method'));
}

return $this->authentication->{$method}();
private function executeAuthMethod($method)
{
foreach ($this->authentication as $auth) {
if($data = $auth->{$method}()) {
return $data;
}
}

return false;
}

public function user()
/**
* @param Application $app
*/
private function instantiateAuthentication(Application $app)
{
$method = $this->config->get('authenticated_user_method');
foreach ((array) $this->config->get('authentication_ioc_binding') as $binding) {
$this->authentication[] = $app->make($binding);
}
}

return $this->authentication->{$method}();
public function user()
{
return $this->executeAuthMethod($this->config->get('authenticated_user_method'));
}

public function getCurrentUserId()
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
/*
* Laravel internal variables on user authentication and login.
*/
'authentication_ioc_binding' => 'auth', // defaults to 'auth' in Illuminate\Support\Facades\Auth
'authentication_ioc_binding' => ['auth'], // defaults to 'auth' in Illuminate\Support\Facades\Auth

'authenticated_check_method' => 'check', // to Auth::check()

Expand Down

0 comments on commit aef183b

Please sign in to comment.