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 { ...@@ -93,6 +93,10 @@ class ApiGuard implements Guard {
$token = $this->request->getPassword(); $token = $this->request->getPassword();
} }
if (empty($token)) {
$token = $this->request->cookie($this->inputKey);
}
return $token; return $token;
} }
......
...@@ -11,8 +11,7 @@ use Source\Exceptions\EntityNotFoundException; ...@@ -11,8 +11,7 @@ use Source\Exceptions\EntityNotFoundException;
use Source\UseCases\Users\Authenticate\APIPresenter; use Source\UseCases\Users\Authenticate\APIPresenter;
use Source\UseCases\Users\Authenticate\AuthenticateUseCase; use Source\UseCases\Users\Authenticate\AuthenticateUseCase;
class AuthController extends ApiController class AuthController extends ApiController {
{
protected Request $request; protected Request $request;
public function __construct(Request $request) { public function __construct(Request $request) {
...@@ -27,10 +26,13 @@ class AuthController extends ApiController ...@@ -27,10 +26,13 @@ class AuthController extends ApiController
* @throws EntityNotFoundException * @throws EntityNotFoundException
*/ */
public function login(AuthenticateUseCase $authenticateUseCase): JsonResponse { public function login(AuthenticateUseCase $authenticateUseCase): JsonResponse {
$this->validate($this->request, [ $this->validate(
'email' => 'required', $this->request,
'password' => 'required' [
]); 'email' => 'required',
'password' => 'required',
]
);
$presenter = new APIPresenter(); $presenter = new APIPresenter();
...@@ -40,6 +42,10 @@ class AuthController extends ApiController ...@@ -40,6 +42,10 @@ class AuthController extends ApiController
throw new AuthenticationException(); 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 ...@@ -12,6 +12,6 @@ class EncryptCookies extends Middleware
* @var array * @var array
*/ */
protected $except = [ protected $except = [
// 'api_token',
]; ];
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Source\UseCases\Users\Authenticate; namespace Source\UseCases\Users\Authenticate;
use Carbon\Carbon;
use Source\UseCases\BasePresenter; use Source\UseCases\BasePresenter;
class APIPresenter extends BasePresenter implements Presenter { class APIPresenter extends BasePresenter implements Presenter {
...@@ -16,6 +17,7 @@ class APIPresenter extends BasePresenter implements Presenter { ...@@ -16,6 +17,7 @@ class APIPresenter extends BasePresenter implements Presenter {
$this->viewModel['token'] = [ $this->viewModel['token'] = [
'value' => $token->getTokenString(), 'value' => $token->getTokenString(),
'expires_at' => $this->formatDateTime($token->getExpiresAt()), '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