-
Notifications
You must be signed in to change notification settings - Fork 21
/
OAuthFlow.php
136 lines (109 loc) · 2.84 KB
/
OAuthFlow.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
declare(strict_types=1);
namespace GoldSpecDigital\ObjectOrientedOAS\Objects;
use GoldSpecDigital\ObjectOrientedOAS\Exceptions\InvalidArgumentException;
use GoldSpecDigital\ObjectOrientedOAS\Utilities\Arr;
/**
* @property string|null $flow
* @property string|null $authorizationUrl
* @property string|null $tokenUrl
* @property string|null $refreshUrl
* @property array|null $scopes
*/
class OAuthFlow extends BaseObject
{
const FLOW_IMPLICIT = 'implicit';
const FLOW_PASSWORD = 'password';
const FLOW_CLIENT_CREDENTIALS = 'clientCredentials';
const FLOW_AUTHORIZATION_CODE = 'authorizationCode';
/**
* @var string|null
*/
protected $flow;
/**
* @var string|null
*/
protected $authorizationUrl;
/**
* @var string|null
*/
protected $tokenUrl;
/**
* @var string|null
*/
protected $refreshUrl;
/**
* @var array|null
*/
protected $scopes;
/**
* @param string|null $flow
* @return static
*/
public function flow(?string $flow): self
{
$instance = clone $this;
$instance->flow = $flow;
return $instance;
}
/**
* @param string|null $authorizationUrl
* @return static
*/
public function authorizationUrl(?string $authorizationUrl): self
{
$instance = clone $this;
$instance->authorizationUrl = $authorizationUrl;
return $instance;
}
/**
* @param string|null $tokenUrl
* @return static
*/
public function tokenUrl(?string $tokenUrl): self
{
$instance = clone $this;
$instance->tokenUrl = $tokenUrl;
return $instance;
}
/**
* @param string|null $refreshUrl
* @return static
*/
public function refreshUrl(?string $refreshUrl): self
{
$instance = clone $this;
$instance->refreshUrl = $refreshUrl;
return $instance;
}
/**
* @param array|null $scopes
* @throws \GoldSpecDigital\ObjectOrientedOAS\Exceptions\InvalidArgumentException
* @return static
*/
public function scopes(?array $scopes): self
{
// Ensure the scopes are string => string.
foreach ($scopes as $key => $value) {
if (is_string($key) && is_string($value)) {
continue;
}
throw new InvalidArgumentException('Each scope must have a string key and a string value.');
}
$instance = clone $this;
$instance->scopes = $scopes;
return $instance;
}
/**
* @return array
*/
protected function generate(): array
{
return Arr::filter([
'authorizationUrl' => $this->authorizationUrl,
'tokenUrl' => $this->tokenUrl,
'refreshUrl' => $this->refreshUrl,
'scopes' => $this->scopes,
]);
}
}