|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace OAuthServer\Bridge; |
| 4 | + |
| 5 | +use Defuse\Crypto\Key; |
| 6 | +use League\OAuth2\Server\AuthorizationServer; |
| 7 | +use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; |
| 8 | +use League\OAuth2\Server\Repositories\ClientRepositoryInterface; |
| 9 | +use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; |
| 10 | +use OAuthServer\Bridge\Repository\AccessTokenRepository; |
| 11 | +use OAuthServer\Bridge\Repository\ClientRepository; |
| 12 | +use OAuthServer\Bridge\Repository\ScopeRepository; |
| 13 | + |
| 14 | +/** |
| 15 | + * Build AuthorizationServer |
| 16 | + */ |
| 17 | +class AuthorizationServerFactory |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @var ClientRepositoryInterface |
| 21 | + */ |
| 22 | + private $clientRepository; |
| 23 | + |
| 24 | + /** |
| 25 | + * @var AccessTokenRepositoryInterface |
| 26 | + */ |
| 27 | + private $accessTokenRepository; |
| 28 | + |
| 29 | + /** |
| 30 | + * @var ScopeRepositoryInterface |
| 31 | + */ |
| 32 | + private $scopeRepository; |
| 33 | + |
| 34 | + /** |
| 35 | + * @var string |
| 36 | + */ |
| 37 | + private $privateKeyPath; |
| 38 | + |
| 39 | + /** |
| 40 | + * @var Key|string |
| 41 | + */ |
| 42 | + private $encryptionKey; |
| 43 | + |
| 44 | + /** |
| 45 | + * @return AuthorizationServer |
| 46 | + */ |
| 47 | + public function create() |
| 48 | + { |
| 49 | + return new AuthorizationServer( |
| 50 | + $this->getClientRepository(), |
| 51 | + $this->getAccessTokenRepository(), |
| 52 | + $this->getScopeRepository(), |
| 53 | + $this->getPrivateKeyPath(), |
| 54 | + $this->getEncryptionKey() |
| 55 | + ); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @return ClientRepositoryInterface |
| 60 | + */ |
| 61 | + public function getClientRepository(): ClientRepositoryInterface |
| 62 | + { |
| 63 | + if ($this->clientRepository) { |
| 64 | + $this->clientRepository = new ClientRepository(); |
| 65 | + } |
| 66 | + |
| 67 | + return $this->clientRepository; |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * @param ClientRepositoryInterface $clientRepository the Repository |
| 72 | + */ |
| 73 | + public function setClientRepository(ClientRepositoryInterface $clientRepository): void |
| 74 | + { |
| 75 | + $this->clientRepository = $clientRepository; |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * @return AccessTokenRepositoryInterface |
| 80 | + */ |
| 81 | + public function getAccessTokenRepository(): AccessTokenRepositoryInterface |
| 82 | + { |
| 83 | + if (!$this->accessTokenRepository) { |
| 84 | + $this->accessTokenRepository = new AccessTokenRepository(); |
| 85 | + } |
| 86 | + |
| 87 | + return $this->accessTokenRepository; |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * @param AccessTokenRepositoryInterface $accessTokenRepository the Repository |
| 92 | + */ |
| 93 | + public function setAccessTokenRepository(AccessTokenRepositoryInterface $accessTokenRepository): void |
| 94 | + { |
| 95 | + $this->accessTokenRepository = $accessTokenRepository; |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * @return ScopeRepositoryInterface |
| 100 | + */ |
| 101 | + public function getScopeRepository(): ScopeRepositoryInterface |
| 102 | + { |
| 103 | + if (!$this->scopeRepository) { |
| 104 | + $this->scopeRepository = new ScopeRepository(); |
| 105 | + } |
| 106 | + |
| 107 | + return $this->scopeRepository; |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * @param ScopeRepositoryInterface $scopeRepository the Repository |
| 112 | + */ |
| 113 | + public function setScopeRepository(ScopeRepositoryInterface $scopeRepository): void |
| 114 | + { |
| 115 | + $this->scopeRepository = $scopeRepository; |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * @return string |
| 120 | + */ |
| 121 | + public function getPrivateKeyPath(): string |
| 122 | + { |
| 123 | + return $this->privateKeyPath; |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * @param string $privateKeyPath the PrivateKey's path |
| 128 | + */ |
| 129 | + public function setPrivateKeyPath(string $privateKeyPath): void |
| 130 | + { |
| 131 | + $this->privateKeyPath = $privateKeyPath; |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * @return Key|string |
| 136 | + */ |
| 137 | + public function getEncryptionKey(): Key |
| 138 | + { |
| 139 | + return $this->encryptionKey; |
| 140 | + } |
| 141 | + |
| 142 | + /** |
| 143 | + * @param Key|string $encryptionKey the Encryption key string or Key object |
| 144 | + */ |
| 145 | + public function setEncryptionKey($encryptionKey): void |
| 146 | + { |
| 147 | + $this->encryptionKey = $encryptionKey; |
| 148 | + } |
| 149 | +} |
0 commit comments