From 3fbe66507d7ffc47c84d483d227b89c0c18ab934 Mon Sep 17 00:00:00 2001 From: Brad Stinson Date: Tue, 15 Apr 2014 07:26:08 -0500 Subject: [PATCH 1/2] Added ability to specify a column to use for username field in basic authentication provider --- src/ApiServiceProvider.php | 2 +- src/Auth/BasicProvider.php | 5 +++-- src/config/config.php | 12 ++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) 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..8666e4cf4 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -41,6 +41,18 @@ 'auth' => ['basic'], + /* + |-------------------------------------------------------------------------- + | Username Column for Basic Provider + |-------------------------------------------------------------------------- + | + | Username column to use when attempting to authenticate an incoming + | API request with basic provider. + | + */ + + 'username_column' => 'email', + /* |-------------------------------------------------------------------------- | Response Formats From b2b7f00c5835b3cdc35014851f942988fefa22e2 Mon Sep 17 00:00:00 2001 From: Brad Stinson Date: Tue, 15 Apr 2014 13:12:41 -0500 Subject: [PATCH 2/2] Revised wording for config variable --- src/config/config.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/config/config.php b/src/config/config.php index 8666e4cf4..8d1321db5 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -43,11 +43,13 @@ /* |-------------------------------------------------------------------------- - | Username Column for Basic Provider + | Username Column for Basic Authentication Provider |-------------------------------------------------------------------------- | - | Username column to use when attempting to authenticate an incoming - | API request with basic provider. + | Name of column to use when attempting to authenticate an incoming + | API request with basic authentication provider. + | + | Default: "email" | */