Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit a07eab0

Browse files
committed
:octocat: OAuthStorageInterface: changed return type of store/delete/clear methods from self to bool to allow feedback
1 parent edb4fb8 commit a07eab0

File tree

5 files changed

+46
-60
lines changed

5 files changed

+46
-60
lines changed

src/Storage/MemoryStorage.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ class MemoryStorage extends OAuthStorageAbstract{
3131
/**
3232
* @inheritDoc
3333
*/
34-
public function storeAccessToken(string $service, AccessToken $token):OAuthStorageInterface{
34+
public function storeAccessToken(string $service, AccessToken $token):bool{
3535
$this->tokens[$service] = $token;
3636

37-
return $this;
37+
return true;
3838
}
3939

4040
/**
@@ -59,36 +59,36 @@ public function hasAccessToken(string $service):bool{
5959
/**
6060
* @inheritDoc
6161
*/
62-
public function clearAccessToken(string $service):OAuthStorageInterface{
62+
public function clearAccessToken(string $service):bool{
6363

6464
if(array_key_exists($service, $this->tokens)){
6565
unset($this->tokens[$service]);
6666
}
6767

68-
return $this;
68+
return true;
6969
}
7070

7171
/**
7272
* @inheritDoc
7373
*/
74-
public function clearAllAccessTokens():OAuthStorageInterface{
74+
public function clearAllAccessTokens():bool{
7575

7676
foreach(array_keys($this->tokens) as $service){
7777
unset($this->tokens[$service]);
7878
}
7979

8080
$this->tokens = [];
8181

82-
return $this;
82+
return true;
8383
}
8484

8585
/**
8686
* @inheritDoc
8787
*/
88-
public function storeCSRFState(string $service, string $state):OAuthStorageInterface{
88+
public function storeCSRFState(string $service, string $state):bool{
8989
$this->states[$service] = $state;
9090

91-
return $this;
91+
return true;
9292
}
9393

9494
/**
@@ -113,22 +113,22 @@ public function hasCSRFState(string $service):bool{
113113
/**
114114
* @inheritDoc
115115
*/
116-
public function clearCSRFState(string $service):OAuthStorageInterface{
116+
public function clearCSRFState(string $service):bool{
117117

118118
if(array_key_exists($service, $this->states)){
119119
unset($this->states[$service]);
120120
}
121121

122-
return $this;
122+
return true;
123123
}
124124

125125
/**
126126
* @inheritDoc
127127
*/
128-
public function clearAllCSRFStates():OAuthStorageInterface{
128+
public function clearAllCSRFStates():bool{
129129
$this->states = [];
130130

131-
return $this;
131+
return true;
132132
}
133133

134134
}

src/Storage/OAuthStorageInterface.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ interface OAuthStorageInterface extends LoggerAwareInterface{
2323
* @param string $service
2424
* @param \chillerlan\OAuth\Core\AccessToken $token
2525
*
26-
* @return \chillerlan\OAuth\Storage\OAuthStorageInterface
26+
* @return bool
2727
* @throws \chillerlan\OAuth\Storage\OAuthStorageException
2828
*/
29-
public function storeAccessToken(string $service, AccessToken $token):OAuthStorageInterface;
29+
public function storeAccessToken(string $service, AccessToken $token):bool;
3030

3131
/**
3232
* Retrieves an AccessToken for the given $service
@@ -52,26 +52,26 @@ public function hasAccessToken(string $service):bool;
5252
*
5353
* @param string $service
5454
*
55-
* @return \chillerlan\OAuth\Storage\OAuthStorageInterface
55+
* @return bool
5656
*/
57-
public function clearAccessToken(string $service):OAuthStorageInterface;
57+
public function clearAccessToken(string $service):bool;
5858

5959
/**
6060
* Deletes all access tokens (for the current user)
6161
*
62-
* @return \chillerlan\OAuth\Storage\OAuthStorageInterface
62+
* @return bool
6363
*/
64-
public function clearAllAccessTokens():OAuthStorageInterface;
64+
public function clearAllAccessTokens():bool;
6565

6666
/**
6767
* Stores a CSRF <state> value for the given $service
6868
*
6969
* @param string $service
7070
* @param string $state
7171
*
72-
* @return \chillerlan\OAuth\Storage\OAuthStorageInterface
72+
* @return bool
7373
*/
74-
public function storeCSRFState(string $service, string $state):OAuthStorageInterface;
74+
public function storeCSRFState(string $service, string $state):bool;
7575

7676
/**
7777
* Retrieves a CSRF <state> value for the given $service
@@ -97,16 +97,16 @@ public function hasCSRFState(string $service):bool;
9797
*
9898
* @param string $service
9999
*
100-
* @return \chillerlan\OAuth\Storage\OAuthStorageInterface
100+
* @return bool
101101
*/
102-
public function clearCSRFState(string $service):OAuthStorageInterface;
102+
public function clearCSRFState(string $service):bool;
103103

104104
/**
105105
* Deletes all stored CSRF states (for the current user)
106106
*
107-
* @return \chillerlan\OAuth\Storage\OAuthStorageInterface
107+
* @return bool
108108
*/
109-
public function clearAllCSRFStates():OAuthStorageInterface;
109+
public function clearAllCSRFStates():bool;
110110

111111
/**
112112
* Prepares an AccessToken for storage (serialize, encrypt etc.)

src/Storage/SessionStorage.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ public function __destruct(){
7272
/**
7373
* @inheritDoc
7474
*/
75-
public function storeAccessToken(string $service, AccessToken $token):OAuthStorageInterface{
75+
public function storeAccessToken(string $service, AccessToken $token):bool{
7676
$_SESSION[$this->sessionVar][$service] = $this->toStorage($token);
7777

78-
return $this;
78+
return true;
7979
}
8080

8181
/**
@@ -100,36 +100,36 @@ public function hasAccessToken(string $service):bool{
100100
/**
101101
* @inheritDoc
102102
*/
103-
public function clearAccessToken(string $service):OAuthStorageInterface{
103+
public function clearAccessToken(string $service):bool{
104104

105105
if(array_key_exists($service, $_SESSION[$this->sessionVar])){
106106
unset($_SESSION[$this->sessionVar][$service]);
107107
}
108108

109-
return $this;
109+
return true;
110110
}
111111

112112
/**
113113
* @inheritDoc
114114
*/
115-
public function clearAllAccessTokens():OAuthStorageInterface{
115+
public function clearAllAccessTokens():bool{
116116

117117
foreach(array_keys($_SESSION[$this->sessionVar]) as $service){
118118
unset($_SESSION[$this->sessionVar][$service]);
119119
}
120120

121121
unset($_SESSION[$this->sessionVar]);
122122

123-
return $this;
123+
return true;
124124
}
125125

126126
/**
127127
* @inheritDoc
128128
*/
129-
public function storeCSRFState(string $service, string $state):OAuthStorageInterface{
129+
public function storeCSRFState(string $service, string $state):bool{
130130
$_SESSION[$this->stateVar][$service] = $state;
131131

132-
return $this;
132+
return true;
133133
}
134134

135135
/**
@@ -154,22 +154,22 @@ public function hasCSRFState(string $service):bool{
154154
/**
155155
* @inheritDoc
156156
*/
157-
public function clearCSRFState(string $service):OAuthStorageInterface{
157+
public function clearCSRFState(string $service):bool{
158158

159159
if(array_key_exists($service, $_SESSION[$this->stateVar])){
160160
unset($_SESSION[$this->stateVar][$service]);
161161
}
162162

163-
return $this;
163+
return true;
164164
}
165165

166166
/**
167167
* @inheritDoc
168168
*/
169-
public function clearAllCSRFStates():OAuthStorageInterface{
169+
public function clearAllCSRFStates():bool{
170170
unset($_SESSION[$this->stateVar]);
171171

172-
return $this;
172+
return true;
173173
}
174174

175175
}

tests/OAuthTestMemoryStorage.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace chillerlan\OAuthTest;
1414

1515
use chillerlan\OAuth\Core\AccessToken;
16-
use chillerlan\OAuth\Storage\{MemoryStorage, OAuthStorageException, OAuthStorageInterface};
16+
use chillerlan\OAuth\Storage\{MemoryStorage, OAuthStorageException};
1717
use chillerlan\Settings\SettingsContainerInterface;
1818

1919
class OAuthTestMemoryStorage extends MemoryStorage{
@@ -36,27 +36,20 @@ public function __construct(SettingsContainerInterface $options = null, string $
3636
}
3737

3838
/**
39-
* @param string $service
40-
* @param \chillerlan\OAuth\Core\AccessToken $token
41-
*
42-
* @return \chillerlan\OAuth\Storage\OAuthStorageInterface
43-
* @throws \chillerlan\OAuth\Storage\OAuthStorageException
39+
* @inheritDoc
4440
*/
45-
public function storeAccessToken(string $service, AccessToken $token):OAuthStorageInterface{
41+
public function storeAccessToken(string $service, AccessToken $token):bool{
4642
parent::storeAccessToken($service, $token);
4743

4844
if(@\file_put_contents($this->storagepath.'/'.$service.'.token.json', $token->toJSON()) === false){
4945
throw new OAuthStorageException('unable to access file storage');
5046
}
5147

52-
return $this;
48+
return true;
5349
}
5450

5551
/**
56-
* @param string $service
57-
*
58-
* @return \chillerlan\OAuth\Core\AccessToken
59-
* @throws \chillerlan\OAuth\Storage\OAuthStorageException
52+
* @inheritDoc
6053
*/
6154
public function getAccessToken(string $service):AccessToken{
6255

tests/OAuthTestSessionStorage.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace chillerlan\OAuthTest;
1414

1515
use chillerlan\OAuth\Core\AccessToken;
16-
use chillerlan\OAuth\Storage\{OAuthStorageException, OAuthStorageInterface, SessionStorage};
16+
use chillerlan\OAuth\Storage\{OAuthStorageException, SessionStorage};
1717
use chillerlan\Settings\SettingsContainerInterface;
1818

1919
class OAuthTestSessionStorage extends SessionStorage{
@@ -36,27 +36,20 @@ public function __construct(SettingsContainerInterface $options = null, string $
3636
}
3737

3838
/**
39-
* @param string $service
40-
* @param \chillerlan\OAuth\Core\AccessToken $token
41-
*
42-
* @return \chillerlan\OAuth\Storage\OAuthStorageInterface
43-
* @throws \chillerlan\OAuth\Storage\OAuthStorageException
39+
* @inheritDoc
4440
*/
45-
public function storeAccessToken(string $service, AccessToken $token):OAuthStorageInterface{
41+
public function storeAccessToken(string $service, AccessToken $token):bool{
4642
parent::storeAccessToken($service, $token);
4743

4844
if(@\file_put_contents($this->storagepath.'/'.$service.'.token.json', $token->toJSON()) === false){
4945
throw new OAuthStorageException('unable to access file storage');
5046
}
5147

52-
return $this;
48+
return true;
5349
}
5450

5551
/**
56-
* @param string $service
57-
*
58-
* @return \chillerlan\OAuth\Core\AccessToken
59-
* @throws \chillerlan\OAuth\Storage\OAuthStorageException
52+
* @inheritDoc
6053
*/
6154
public function getAccessToken(string $service):AccessToken{
6255

0 commit comments

Comments
 (0)