Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add authenticator for the Sense controllers (#9)
Add authenticator for the Sense controllers
- Loading branch information
1 parent
0ae072f
commit 5bde570
Showing
8 changed files
with
113 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
# Changelog | ||
|
||
## 1.0.0 - 2018-09-25 | ||
All notable changes to `laravel-sense` will be documented in this file. | ||
|
||
## [0.2.0] - 2018-09-26 | ||
|
||
### Added | ||
|
||
- ([#9](https://github.com/cybercog/laravel-sense/pull/9)) Dashboard Authenticator | ||
|
||
## 0.1.0 - 2018-09-25 | ||
|
||
- Initial release | ||
|
||
All notable changes to `laravel-sense` will be documented in this file. | ||
[0.2.0]: https://github.com/cybercog/laravel-sense/compare/0.1.0...0.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Laravel Authenticator. | ||
* | ||
* (c) Anton Komarev <a.komarev@cybercog.su> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cog\Laravel\Sense\Authentication\Services; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
|
||
class Authenticator | ||
{ | ||
/** | ||
* The callback that should be used to authenticate Sense users. | ||
* | ||
* @var \Closure | ||
*/ | ||
public static $using; | ||
|
||
/** | ||
* Determine if the given request can access the Sense dashboard. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return bool | ||
*/ | ||
public static function check(Request $request): bool | ||
{ | ||
return (static::$using ?: function () { | ||
return app()->environment('local'); | ||
})($request); | ||
} | ||
|
||
/** | ||
* Set the callback that should be used to authenticate Sense users. | ||
* | ||
* @param \Closure $callback | ||
* @return void | ||
*/ | ||
public static function using(Closure $callback): void | ||
{ | ||
static::$using = $callback; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,5 @@ public function __invoke($requestId = null) | |
->get(); | ||
|
||
return view('sense::requests', compact('summaries')); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Laravel Sense. | ||
* | ||
* (c) Anton Komarev <a.komarev@cybercog.su> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cog\Laravel\Sense\Http\Middleware; | ||
|
||
use Cog\Laravel\Sense\Authentication\Services\Authenticator; | ||
|
||
class Authenticate | ||
{ | ||
/** | ||
* Handle the incoming request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure $next | ||
* @return \Illuminate\Http\Response|null | ||
*/ | ||
public function handle($request, $next) | ||
{ | ||
return Authenticator::check($request) ? $next($request) : abort(403); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters