Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
Doorcode
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Guardians of the Kretschmar Elock System
Doorcode
Commits
1b4497fa
Commit
1b4497fa
authored
Mar 01, 2020
by
Jacob Priddy
👌
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
authentication and authorization are different lmao
parent
d3ea6714
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
8 deletions
+31
-8
src/web/backend/app/Exceptions/Handler.php
src/web/backend/app/Exceptions/Handler.php
+9
-0
src/web/backend/app/Http/Controllers/AuthController.php
src/web/backend/app/Http/Controllers/AuthController.php
+2
-2
src/web/backend/src/Exceptions/AuthenticationException.php
src/web/backend/src/Exceptions/AuthenticationException.php
+14
-0
src/web/backend/src/Exceptions/AuthorizationException.php
src/web/backend/src/Exceptions/AuthorizationException.php
+1
-1
src/web/backend/src/UseCases/Users/Authenticate/Authenticate.php
.../backend/src/UseCases/Users/Authenticate/Authenticate.php
+3
-3
src/web/backend/src/UseCases/Users/Authenticate/AuthenticateUseCase.php
...d/src/UseCases/Users/Authenticate/AuthenticateUseCase.php
+2
-2
No files found.
src/web/backend/app/Exceptions/Handler.php
View file @
1b4497fa
...
...
@@ -7,6 +7,7 @@ use Illuminate\Http\Request;
use
Illuminate\Http\JsonResponse
;
use
Source\Exceptions\EntityExistsException
;
use
Illuminate\Auth\AuthenticationException
;
use
Source\Exceptions\AuthorizationException
;
use
Source\Exceptions\EntityNotFoundException
;
use
Illuminate\Validation\ValidationException
;
use
Illuminate\Foundation\Exceptions\Handler
as
ExceptionHandler
;
...
...
@@ -54,6 +55,14 @@ class Handler extends ExceptionHandler {
return
$this
->
respondWithError
(
$exception
->
getMessage
(),
$exception
->
getCode
());
}
if
(
$exception
instanceof
\
Source\Exceptions\AuthenticationException
)
{
return
response
()
->
json
([
'message'
=>
$exception
->
getMessage
()],
401
);
}
if
(
$exception
instanceof
AuthorizationException
)
{
return
response
()
->
json
([
'message'
=>
$exception
->
getMessage
()],
403
);
}
return
parent
::
render
(
$request
,
$exception
);
}
...
...
src/web/backend/app/Http/Controllers/AuthController.php
View file @
1b4497fa
...
...
@@ -8,7 +8,7 @@ use Illuminate\Http\JsonResponse;
use
Illuminate\Http\RedirectResponse
;
use
Illuminate\Support\Facades\Cookie
;
use
Illuminate\Auth\AuthenticationException
;
use
Source\Exceptions\Auth
oriz
ationException
;
use
Source\Exceptions\Auth
entic
ationException
;
use
Source\Exceptions\EntityNotFoundException
;
use
Source\UseCases\Users\Authenticate\APIPresenter
;
use
Source\UseCases\Users\Authenticate\AuthenticateUseCase
;
...
...
@@ -35,7 +35,7 @@ class AuthController extends ApiController {
try
{
$authenticateUseCase
->
attempt
(
$presenter
,
$this
->
request
->
all
());
}
catch
(
Auth
oriz
ationException
$e
)
{
}
catch
(
Auth
entic
ationException
$e
)
{
throw
new
AuthenticationException
();
}
...
...
src/web/backend/src/Exceptions/AuthenticationException.php
0 → 100644
View file @
1b4497fa
<?php
namespace
Source\Exceptions
;
use
Exception
;
use
Throwable
;
class
AuthenticationException
extends
Exception
{
public
function
__construct
(
$message
=
'Unauthenticated'
,
$code
=
401
,
Throwable
$previous
=
null
)
{
parent
::
__construct
(
$message
,
$code
,
$previous
);
}
}
src/web/backend/src/Exceptions/AuthorizationException.php
View file @
1b4497fa
...
...
@@ -8,7 +8,7 @@ use Exception;
use
Throwable
;
class
AuthorizationException
extends
Exception
{
public
function
__construct
(
$message
=
'Unauthorized'
,
$code
=
0
,
Throwable
$previous
=
null
)
{
public
function
__construct
(
$message
=
'Unauthorized'
,
$code
=
403
,
Throwable
$previous
=
null
)
{
parent
::
__construct
(
$message
,
$code
,
$previous
);
}
}
src/web/backend/src/UseCases/Users/Authenticate/Authenticate.php
View file @
1b4497fa
...
...
@@ -9,7 +9,7 @@ use Illuminate\Support\Str;
use
Source\Gateways\Saml\SamlRepository
;
use
Source\Gateways\Users\UsersRepository
;
use
Source\Gateways\Tokens\TokensRepository
;
use
Source\Exceptions\Auth
oriz
ationException
;
use
Source\Exceptions\Auth
entic
ationException
;
class
Authenticate
implements
AuthenticateUseCase
{
protected
UsersRepository
$users
;
...
...
@@ -32,13 +32,13 @@ class Authenticate implements AuthenticateUseCase {
$password
=
$credentials
[
'password'
]
??
null
;
if
(
!
$email
||
!
$password
)
{
throw
new
Auth
oriz
ationException
();
throw
new
Auth
entic
ationException
();
}
$user
=
$this
->
users
->
findByCredentials
(
strtolower
(
$email
),
$password
);
if
(
!
$user
)
{
throw
new
Auth
oriz
ationException
();
throw
new
Auth
entic
ationException
();
}
$token
=
$this
->
tokens
->
create
(
...
...
src/web/backend/src/UseCases/Users/Authenticate/AuthenticateUseCase.php
View file @
1b4497fa
...
...
@@ -4,7 +4,7 @@
namespace
Source\UseCases\Users\Authenticate
;
use
Source\Exceptions\Auth
oriz
ationException
;
use
Source\Exceptions\Auth
entic
ationException
;
use
Source\Exceptions\EntityNotFoundException
;
interface
AuthenticateUseCase
{
...
...
@@ -13,7 +13,7 @@ interface AuthenticateUseCase {
*
* @param Presenter $presenter
* @param array $credentials
* @throws Auth
oriz
ationException
* @throws Auth
entic
ationException
* @throws EntityNotFoundException
*/
public
function
attempt
(
Presenter
$presenter
,
array
$credentials
):
void
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment