Skip to content

Commit b353c44

Browse files
committed
Add factory to create configuration objects from (an array of) strings.
1 parent 1b7bffd commit b353c44

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

src/Factory/ConfigFactory.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Pdsinterop\Solid\Auth\Factory;
4+
5+
use League\OAuth2\Server\CryptKey;
6+
use Pdsinterop\Solid\Auth\Config;
7+
use Pdsinterop\Solid\Auth\Enum\OAuth2\GrantType;
8+
use Pdsinterop\Solid\Auth\Enum\Time;
9+
10+
class ConfigFactory
11+
{
12+
/** @var string */
13+
private $clientIdentifier;
14+
/** @var string */
15+
private $clientSecret;
16+
/** @var string */
17+
private $encryptionKey;
18+
/** @var string */
19+
private $privateKey;
20+
/** @var array */
21+
private $serverConfig;
22+
23+
final public function __construct(
24+
string $clientIdentifier,
25+
string $clientSecret,
26+
string $encryptionKey,
27+
string $privateKey,
28+
array $serverConfig
29+
) {
30+
$this->clientIdentifier = $clientIdentifier;
31+
$this->clientSecret = $clientSecret;
32+
$this->encryptionKey = $encryptionKey;
33+
$this->privateKey = $privateKey;
34+
$this->serverConfig = $serverConfig;
35+
}
36+
37+
final public function create() : Config
38+
{
39+
$clientIdentifier = $this->clientIdentifier;
40+
$clientSecret = $this->clientSecret;
41+
$encryptionKey = $this->encryptionKey;
42+
$privateKey = $this->privateKey;
43+
44+
$client = new Config\Client($clientIdentifier, $clientSecret);
45+
46+
$expiration = new Config\Expiration(Time::HOURS_1, Time::MINUTES_10, Time::MONTHS_1);
47+
48+
$grantTypes = [
49+
GrantType::AUTH_CODE,
50+
GrantType::CLIENT_CREDENTIALS,
51+
GrantType::REFRESH_TOKEN,
52+
];
53+
54+
$keys = new Config\Keys(
55+
new CryptKey($privateKey),
56+
$encryptionKey
57+
);
58+
59+
$server = new Config\Server($this->serverConfig);
60+
61+
return new Config(
62+
$client,
63+
$expiration,
64+
$grantTypes,
65+
$keys,
66+
$server
67+
);
68+
}
69+
}

0 commit comments

Comments
 (0)