| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of web-stack | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace Slick\WebStack\Infrastructure\Http\Authenticator\Factory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Slick\Di\ContainerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Slick\WebStack\Domain\Security\Exception\LogicException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Slick\WebStack\Domain\Security\Http\AccessToken\AccessTokenHandlerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Slick\WebStack\Domain\Security\Http\AccessToken\Extractor\HeaderAccessTokenExtractor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Slick\WebStack\Domain\Security\Http\AuthenticatorFactoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Slick\WebStack\Domain\Security\Http\SecurityProfile\EntryPointAwareInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Slick\WebStack\Domain\Security\UserInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Slick\WebStack\Infrastructure\Http\Authenticator\AccessTokenAuthenticator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * AccessTokenAuthenticatorFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * @package Slick\WebStack\Infrastructure\Http\Authenticator\Factory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * @implements AuthenticatorFactoryInterface<UserInterface> | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 28 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  | final class AccessTokenAuthenticatorFactory implements AuthenticatorFactoryInterface | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |      * @var array<string, string> | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     private static array $defaultProperties = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |         "extractor" => HeaderAccessTokenExtractor::class, | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |         "handler" => AccessTokenHandlerInterface::class | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |      * @inheritDoc | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public static function create( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         ContainerInterface $container, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         array $properties = [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         ?EntryPointAwareInterface $factoryHandler = null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     ): AccessTokenAuthenticator { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $properties = array_merge(self::$defaultProperties, $properties); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         if (!$container->has($properties["handler"])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             throw new LogicException( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                 "Access token handler missing: define a class that implements the " . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 AccessTokenHandlerInterface::class ." and set it as the 'handler' parameter in the ". | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                 "'accessToken' authenticator within the 'settings.php' file." | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         return new AccessTokenAuthenticator( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             $container->make($properties["extractor"]), | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 59 |  |  |             $container->get($properties["handler"]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 62 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 63 |  |  |  |