generated from rohsyl/skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add middleware and authentication (session)
- Loading branch information
Showing
7 changed files
with
196 additions
and
5 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
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,28 @@ | ||
<?php | ||
|
||
namespace rohsyl\LaravelOtc\Http\Middlewares; | ||
|
||
use Closure; | ||
use Illuminate\Http\Client\HttpClientException; | ||
use rohsyl\LaravelOtc\Otc; | ||
use Symfony\Component\HttpKernel\Exception\HttpException; | ||
|
||
class OtcMiddleware | ||
{ | ||
|
||
public function handle($request, Closure $next, $inputs = null) | ||
{ | ||
if(!Otc::check()) { | ||
abort(401, 'Unauthorized1'); | ||
} | ||
$inputs = explode(',', $inputs ?? ''); | ||
|
||
$authenticatable = $inputs[0] ?? config('otc.default-authenticatable', 'user'); | ||
$modelClass = config('otc.authenticatables.'.$authenticatable.'.model'); | ||
if(get_class(Otc::user()) !== $modelClass) { | ||
abort(401, 'Unauthorized2'); | ||
} | ||
|
||
return $next($request); | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -74,6 +74,23 @@ public function it_request_code_controller_redirect() | |
Notification::assertSentTo($this->user, OneTimeCodeNotification::class); | ||
} | ||
|
||
/** @test */ | ||
public function it_throw_error_when_entity_not_found_and_not_registerable() | ||
{ | ||
|
||
Notification::fake(); | ||
|
||
$response = $this->post( | ||
uri: route('laravel-otc.request-code'), | ||
data: [ | ||
'type' => 'user', | ||
'identifier' => '[email protected]', | ||
] | ||
); | ||
|
||
$response->assertStatus(403); | ||
} | ||
|
||
/** @test */ | ||
public function it_auth_and_return_token() | ||
{ | ||
|
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