|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* balloon |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright Copryright (c) 2012-2019 gyselroth GmbH (https://gyselroth.com) |
|
9
|
|
|
* @license GPL-3.0 https://opensource.org/licenses/GPL-3.0 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Balloon\App\Idp\Migration\Delta; |
|
13
|
|
|
|
|
14
|
|
|
use Balloon\App\Idp\Storage\Db as OAuth2Storage; |
|
15
|
|
|
use Balloon\Migration\Delta\DeltaInterface; |
|
16
|
|
|
use MongoDB\Database; |
|
17
|
|
|
use ParagonIE\Halite\KeyFactory; |
|
18
|
|
|
|
|
19
|
|
|
class Installation implements DeltaInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* MongoDB. |
|
23
|
|
|
* |
|
24
|
|
|
* @var Database |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $db; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* OAuth2 storage. |
|
30
|
|
|
* |
|
31
|
|
|
* @var OAuth2Storage |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $storage; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Construct. |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct(OAuth2Storage $storage, Database $db) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->storage = $storage; |
|
41
|
|
|
$this->db = $db; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* {@inheritdoc} |
|
46
|
|
|
*/ |
|
47
|
|
|
public function start(): bool |
|
48
|
|
|
{ |
|
49
|
|
|
$this->storage->setClientDetails('balloon-client-web', null, null, 'password refresh_token password_mfa'); |
|
50
|
|
|
$this->storage->setClientDetails('balloon-client-desktop', null, null, 'password refresh_token password_mfa'); |
|
51
|
|
|
|
|
52
|
|
|
$this->db->oauth_access_tokens->createIndex(['access_token' => 1]); |
|
53
|
|
|
$this->db->oauth_access_tokens->createIndex(['expires' => 1], ['expireAfterSeconds' => 0]); |
|
54
|
|
|
$this->db->oauth_refresh_tokens->createIndex(['refresh_token' => 1]); |
|
55
|
|
|
$this->db->oauth_refresh_tokens->createIndex(['expires' => 1], ['expireAfterSeconds' => 0]); |
|
56
|
|
|
$this->db->oauth_authorization_codes->createIndex(['expires' => 1], ['expireAfterSeconds' => 0]); |
|
57
|
|
|
|
|
58
|
|
|
if ($this->db->oauth_keys->count() === 0) { |
|
59
|
|
|
$seal_keypair = KeyFactory::generateEncryptionKeyPair(); |
|
60
|
|
|
$seal_secret = $seal_keypair->getSecretKey(); |
|
61
|
|
|
$seal_public = $seal_keypair->getPublicKey(); |
|
62
|
|
|
|
|
63
|
|
|
$this->db->oauth_keys->insertOne([ |
|
64
|
|
|
'private_key' => KeyFactory::export($seal_secret)->getString(), |
|
65
|
|
|
'public_key' => KeyFactory::export($seal_public)->getString(), |
|
66
|
|
|
]); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return true; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|