1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Aweapi\Openapi\Objects; |
6
|
|
|
|
7
|
|
|
use Aweapi\Openapi\Extensions; |
8
|
|
|
use Aweapi\Openapi\ValueObject; |
9
|
|
|
|
10
|
|
|
final class OAuthFlow extends ValueObject |
11
|
|
|
{ |
12
|
|
|
use Properties\OptionalExtensions; |
13
|
|
|
|
14
|
|
|
private $authorizationUrl; |
15
|
|
|
|
16
|
|
|
private $refreshUrl; |
17
|
|
|
|
18
|
|
|
private $scopes = []; |
19
|
|
|
|
20
|
|
|
private $tokenUrl; |
21
|
|
|
|
22
|
5 |
|
public function __construct( |
23
|
|
|
iterable $scopes, |
24
|
|
|
string $authorizationUrl = null, |
25
|
|
|
string $tokenUrl = null, |
26
|
|
|
string $refreshUrl = null, |
27
|
|
|
Extensions $extensions = null |
28
|
|
|
) { |
29
|
5 |
|
foreach ($scopes as $name => $shortDescription) { |
30
|
3 |
|
$name = $this->filterString($name); |
31
|
3 |
|
$shortDescription = $this->filterString($shortDescription); |
32
|
3 |
|
$this->scopes[$name] = $shortDescription; |
33
|
|
|
} |
34
|
|
|
|
35
|
5 |
|
$this->authorizationUrl = $authorizationUrl; |
36
|
5 |
|
$this->tokenUrl = $tokenUrl; |
37
|
5 |
|
$this->refreshUrl = $refreshUrl; |
38
|
5 |
|
$this->extensions = $extensions; |
39
|
|
|
} |
40
|
|
|
|
41
|
1 |
|
public function getAuthorizationUrl(): string |
42
|
|
|
{ |
43
|
1 |
|
return $this->authorizationUrl; |
44
|
|
|
} |
45
|
|
|
|
46
|
1 |
|
public function getRefreshUrl(): string |
47
|
|
|
{ |
48
|
1 |
|
return $this->refreshUrl; |
49
|
|
|
} |
50
|
|
|
|
51
|
5 |
|
public function getScopes(): array |
52
|
|
|
{ |
53
|
5 |
|
return $this->scopes; |
54
|
|
|
} |
55
|
|
|
|
56
|
1 |
|
public function getTokenUrl(): string |
57
|
|
|
{ |
58
|
1 |
|
return $this->tokenUrl; |
59
|
|
|
} |
60
|
|
|
|
61
|
5 |
|
public function hasAuthorizationUrl(): bool |
62
|
|
|
{ |
63
|
5 |
|
return isset($this->authorizationUrl); |
64
|
|
|
} |
65
|
|
|
|
66
|
5 |
|
public function hasRefreshUrl(): bool |
67
|
|
|
{ |
68
|
5 |
|
return isset($this->refreshUrl); |
69
|
|
|
} |
70
|
|
|
|
71
|
5 |
|
public function hasTokenUrl(): bool |
72
|
|
|
{ |
73
|
5 |
|
return isset($this->tokenUrl); |
74
|
|
|
} |
75
|
|
|
|
76
|
5 |
|
public function jsonSerialize(): ?array |
77
|
|
|
{ |
78
|
5 |
|
return $this->extendedProperties(parent::jsonSerialize()); |
79
|
|
|
} |
80
|
|
|
|
81
|
5 |
|
protected function normalizeOptionalProperties(): array |
82
|
|
|
{ |
83
|
|
|
return [ |
84
|
5 |
|
'authorizationUrl' => $this->hasAuthorizationUrl() ? $this->getAuthorizationUrl() : null, |
85
|
5 |
|
'tokenUrl' => $this->hasTokenUrl() ? $this->getTokenUrl() : null, |
86
|
5 |
|
'refreshUrl' => $this->hasRefreshUrl() ? $this->getRefreshUrl() : null, |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
|
90
|
5 |
|
protected function normalizeRequiredProperties(): array |
91
|
|
|
{ |
92
|
|
|
return [ |
93
|
5 |
|
'scopes' => $this->getScopes(), |
94
|
|
|
]; |
95
|
|
|
} |
96
|
|
|
|
97
|
3 |
|
private function filterString(string $value): string |
98
|
|
|
{ |
99
|
3 |
|
return $value; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|