-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from buggregator/feature/139
Adds Kinde auth support
- Loading branch information
Showing
38 changed files
with
1,382 additions
and
229 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
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,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application\Exception; | ||
|
||
class AuthProviderException extends \Exception {} |
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,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application\Exception; | ||
|
||
final class AuthProviderNotFound extends AuthProviderException {} |
7 changes: 7 additions & 0 deletions
7
app/src/Application/Exception/InvalidCredentialsException.php
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,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application\Exception; | ||
|
||
final class InvalidCredentialsException extends AuthProviderException {} |
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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application\HTTP\Middleware; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\MiddlewareInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
use Spiral\Auth\Middleware\AuthTransportWithStorageMiddleware; | ||
use Spiral\Core\FactoryInterface; | ||
|
||
final class ApiAuthMiddleware implements MiddlewareInterface | ||
{ | ||
private ?MiddlewareInterface $middleware = null; | ||
|
||
public function __construct( | ||
private readonly FactoryInterface $factory, | ||
) {} | ||
|
||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||
{ | ||
if ($this->middleware === null) { | ||
$this->initMiddleware(); | ||
} | ||
|
||
return $this->middleware->process($request, $handler); | ||
} | ||
|
||
private function initMiddleware(): void | ||
{ | ||
$this->middleware = $this->factory->make(AuthTransportWithStorageMiddleware::class, [ | ||
'transportName' => 'header', | ||
]); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application\OAuth; | ||
|
||
use Psr\Http\Message\UriInterface; | ||
use Spiral\Http\Request\InputManager; | ||
|
||
interface AuthProviderInterface | ||
{ | ||
public function getLoginUrl(): UriInterface; | ||
|
||
public function isAuthenticated(): bool; | ||
|
||
public function getUser(): ?User; | ||
|
||
public function authenticate(InputManager $input): void; | ||
|
||
public function getLogoutUrl(): ?UriInterface; | ||
|
||
public function logout(): void; | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/Application/OAuth/AuthProviderRegistryInterface.php
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application\OAuth; | ||
|
||
use App\Application\Exception\AuthProviderNotFound; | ||
|
||
interface AuthProviderRegistryInterface | ||
{ | ||
/** | ||
* @param class-string<AuthProviderInterface> $provider | ||
*/ | ||
public function register(string $name, string $provider): void; | ||
|
||
/** | ||
* @throws AuthProviderNotFound | ||
*/ | ||
public function get(string $name): AuthProviderInterface; | ||
} |
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,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application\OAuth; | ||
|
||
use App\Application\Exception\AuthProviderException; | ||
use App\Application\Exception\AuthProviderNotFound; | ||
use Psr\Container\ContainerInterface; | ||
use Spiral\Core\Attribute\Singleton; | ||
|
||
#[Singleton] | ||
final class AuthProviderService implements AuthProviderRegistryInterface | ||
{ | ||
/** @var array<non-empty-string, class-string<AuthProviderInterface>> */ | ||
private array $providers = []; | ||
|
||
public function __construct( | ||
private readonly ContainerInterface $container, | ||
) {} | ||
|
||
public function register(string $name, string $provider): void | ||
{ | ||
if (!\is_subclass_of($provider, AuthProviderInterface::class)) { | ||
throw new AuthProviderException( | ||
\sprintf('Provider "%s" must implement AuthProviderInterface', $provider), | ||
); | ||
} | ||
|
||
$this->providers[$name] = $provider; | ||
} | ||
|
||
public function get(string $name): AuthProviderInterface | ||
{ | ||
if (!isset($this->providers[$name])) { | ||
throw new AuthProviderNotFound(\sprintf('Auth provider "%s" not found', $name)); | ||
} | ||
|
||
return $this->container->get($this->providers[$name]); | ||
} | ||
} |
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
Oops, something went wrong.