|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2015 François Kooman <[email protected]>. |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace fkooman\RemoteStorage\OAuth; |
|
20
|
|
|
|
|
21
|
|
|
use InvalidArgumentException; |
|
22
|
|
|
|
|
23
|
|
|
class Client |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var string */ |
|
26
|
|
|
private $clientId; |
|
27
|
|
|
|
|
28
|
|
|
/** @var string */ |
|
29
|
|
|
private $responseType; |
|
30
|
|
|
|
|
31
|
|
|
/** @var string */ |
|
32
|
|
|
private $redirectUri; |
|
33
|
|
|
|
|
34
|
|
|
/** @var string */ |
|
35
|
|
|
private $scope; |
|
36
|
|
|
|
|
37
|
|
|
/** @var string */ |
|
38
|
|
|
private $secret; |
|
39
|
|
|
|
|
40
|
|
|
public function __construct($clientId, $responseType, $redirectUri, $scope, $secret) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->setClientId($clientId); |
|
43
|
|
|
$this->setResponseType($responseType); |
|
44
|
|
|
$this->setRedirectUri($redirectUri); |
|
45
|
|
|
$this->setScope($scope); |
|
46
|
|
|
$this->setSecret($secret); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function setClientId($clientId) |
|
50
|
|
|
{ |
|
51
|
|
|
if (false === InputValidation::clientId($clientId)) { |
|
52
|
|
|
throw new InvalidArgumentException('invalid client_id'); |
|
53
|
|
|
} |
|
54
|
|
|
$this->clientId = $clientId; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function getClientId() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->clientId; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function setResponseType($responseType) |
|
63
|
|
|
{ |
|
64
|
|
|
if (false === InputValidation::responseType($responseType)) { |
|
65
|
|
|
throw new InvalidArgumentException('invalid response_type'); |
|
66
|
|
|
} |
|
67
|
|
|
$this->responseType = $responseType; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getResponseType() |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->responseType; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function setRedirectUri($redirectUri) |
|
76
|
|
|
{ |
|
77
|
|
|
if (false === InputValidation::redirectUri($redirectUri)) { |
|
78
|
|
|
throw new InvalidArgumentException('invalid redirect_uri'); |
|
79
|
|
|
} |
|
80
|
|
|
$this->redirectUri = $redirectUri; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function getRedirectUri() |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->redirectUri; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function setScope($scope) |
|
89
|
|
|
{ |
|
90
|
|
|
if (false === InputValidation::scope($scope)) { |
|
91
|
|
|
throw new InvalidArgumentException('invalid scope'); |
|
92
|
|
|
} |
|
93
|
|
|
$this->scope = $scope; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function getScope() |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->scope; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function setSecret($secret) |
|
102
|
|
|
{ |
|
103
|
|
|
// // XXX: validate secret as well |
|
|
|
|
|
|
104
|
|
|
// if(false === InputValidation::secret($secret)) { |
|
105
|
|
|
// throw new InvalidArgumentException('invalid secret'); |
|
106
|
|
|
// } |
|
107
|
|
|
$this->secret = $secret; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function getSecret() |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->secret; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.