Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ SSO_BROKER_SECRET=
```
`SSO_SERVER_URL` is your server's http url without trailing slash. `SSO_BROKER_NAME` and `SSO_BROKER_SECRET` must be data which exists in your server's `brokers` table.


Optionally set the column of your authentication username field on your server ('username' by default) `.env` file:
```shell
SSO_USERNAME_FIELD=email
```

Edit your `app/Http/Kernel.php` by adding `\Zefy\LaravelSSO\Middleware\SSOAutoLogin::class` middleware to `web` middleware group. It should look like this:
```php
Expand Down
3 changes: 3 additions & 0 deletions config/laravel-sso.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// Table used in Zefy\LaravelSSO\Models\Broker model
'brokersTable' => 'brokers',

// What is the name of the column that users use to login with (generally 'username' or 'email)
'usernameField' => env('SSO_USERNAME_FIELD', 'username'),

// Logged in user fields sent to brokers.
'userFields' => [
// Return array field name => database column name
Expand Down
4 changes: 2 additions & 2 deletions src/LaravelSSOServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected function returnJson(?array $response = null, int $httpResponseCode = 2
*/
protected function authenticate(string $username, string $password)
{
if (!Auth::attempt(['username' => $username, 'password' => $password])) {
if (!Auth::attempt([config('laravel-sso.usernameField') => $username, 'password' => $password])) {
return false;
}

Expand Down Expand Up @@ -107,7 +107,7 @@ protected function getBrokerInfo(string $brokerId)
protected function getUserInfo(string $username)
{
try {
$user = config('laravel-sso.usersModel')::where('username', $username)->firstOrFail();
$user = config('laravel-sso.usersModel')::where(config('laravel-sso.usernameField'), $username)->firstOrFail();
} catch (ModelNotFoundException $e) {
return null;
}
Expand Down