Commit 968371e5 authored by Jacob Priddy's avatar Jacob Priddy 👌

start on integrating saml auth

parent cebf78db
......@@ -93,6 +93,10 @@ class ApiGuard implements Guard {
$token = $this->request->getPassword();
}
if (empty($token)) {
$token = $this->request->cookie($this->inputKey);
}
return $token;
}
......
......@@ -11,8 +11,7 @@ use Source\Exceptions\EntityNotFoundException;
use Source\UseCases\Users\Authenticate\APIPresenter;
use Source\UseCases\Users\Authenticate\AuthenticateUseCase;
class AuthController extends ApiController
{
class AuthController extends ApiController {
protected Request $request;
public function __construct(Request $request) {
......@@ -27,10 +26,13 @@ class AuthController extends ApiController
* @throws EntityNotFoundException
*/
public function login(AuthenticateUseCase $authenticateUseCase): JsonResponse {
$this->validate($this->request, [
$this->validate(
$this->request,
[
'email' => 'required',
'password' => 'required'
]);
'password' => 'required',
]
);
$presenter = new APIPresenter();
......@@ -40,6 +42,10 @@ class AuthController extends ApiController
throw new AuthenticationException();
}
return $this->respondWithData($presenter->getViewModel());
return $this->respondWithData($presenter->getViewModel())->cookie(
'api_token',
$presenter->getViewModel()['token']['value'],
$presenter->getViewModel()['token']['minutes']
);
}
}
......@@ -12,6 +12,6 @@ class EncryptCookies extends Middleware
* @var array
*/
protected $except = [
//
'api_token',
];
}
......@@ -2,6 +2,7 @@
namespace Source\UseCases\Users\Authenticate;
use Carbon\Carbon;
use Source\UseCases\BasePresenter;
class APIPresenter extends BasePresenter implements Presenter {
......@@ -16,6 +17,7 @@ class APIPresenter extends BasePresenter implements Presenter {
$this->viewModel['token'] = [
'value' => $token->getTokenString(),
'expires_at' => $this->formatDateTime($token->getExpiresAt()),
'minutes' => Carbon::now()->minutesUntil($token->getExpiresAt()),
];
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment