diff --git a/src/ApiServiceProvider.php b/src/ApiServiceProvider.php index 1f059e6e4..87b818618 100644 --- a/src/ApiServiceProvider.php +++ b/src/ApiServiceProvider.php @@ -135,7 +135,7 @@ protected function registerAuthentication() $providers = []; $resolvers = [ - 'basic' => function($app) { return new BasicProvider($app['auth']); }, + 'basic' => function($app) { return new BasicProvider($app['auth'], $app['config']['api::username_column']); }, 'oauth2' => function($app) { return new OAuth2Provider($app['dingo.oauth.resource']); } ]; diff --git a/src/Auth/BasicProvider.php b/src/Auth/BasicProvider.php index ae9a2c485..57d3c6f56 100644 --- a/src/Auth/BasicProvider.php +++ b/src/Auth/BasicProvider.php @@ -11,9 +11,10 @@ class BasicProvider extends Provider { * @param \Illuminate\Auth\AuthManager $auth * @return void */ - public function __construct(AuthManager $auth) + public function __construct(AuthManager $auth, $username_column) { $this->auth = $auth; + $this->username_column = $username_column; } /** @@ -24,7 +25,7 @@ public function __construct(AuthManager $auth) */ public function authenticate(array $scopes) { - if ($response = $this->auth->onceBasic() and $response->getStatusCode() === 401) + if ($response = $this->auth->onceBasic($this->username_column) and $response->getStatusCode() === 401) { throw new UnauthorizedHttpException('Basic', 'Invalid credentials.'); } diff --git a/src/config/config.php b/src/config/config.php index 8de82194b..8d1321db5 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -41,6 +41,20 @@ 'auth' => ['basic'], + /* + |-------------------------------------------------------------------------- + | Username Column for Basic Authentication Provider + |-------------------------------------------------------------------------- + | + | Name of column to use when attempting to authenticate an incoming + | API request with basic authentication provider. + | + | Default: "email" + | + */ + + 'username_column' => 'email', + /* |-------------------------------------------------------------------------- | Response Formats