Skip to content

Commit

Permalink
Fix: issue with missing user hash property and APIResponse validations
Browse files Browse the repository at this point in the history
  • Loading branch information
SSOfy committed Mar 14, 2023
1 parent 28796f6 commit 42397b6
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 1.1.5 - 2023-03-14

* Fixed issues with APIResponse and Token models

## 1.1.4 - 2023-02-28

* Compliance with Draft 1.30 signature style
Expand Down
5 changes: 3 additions & 2 deletions src/SSOfy/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public function verifyAuthentication($token)
$response = $this->requestAndCache($path, $token);

return new APIResponse([
'token' => new Token($response['token'])
'token' => new Token($response['token']),
'user' => new UserEntity($response['user']),
]);
}

Expand All @@ -75,8 +76,8 @@ public function authenticatedUser($token, $cache = false)
$response = $this->requestAndCache($path, $token, [], $cache);

return new APIResponse([
'token' => new Token($response['token']),
'user' => new UserEntity($response['user']),
'token' => new Token($response['token'])
]);
}

Expand Down
29 changes: 27 additions & 2 deletions src/SSOfy/Models/APIResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,38 @@
use SSOfy\Models\Entities\UserEntity;

/**
* @property Token token
* @property UserEntity $user
* @property Token token
* @property UserEntity user
*/
class APIResponse extends BaseModel
{
protected $properties = [
'token',
'user',
];

protected function validate($attr, $value)
{
if (is_null($value)) {
return true;
}

switch ($attr) {
case 'token':
if (!is_a($value, Token::class)) {
return 'value must be ' . Token::class;
}

return true;

case 'user':
if (!is_a($value, UserEntity::class)) {
return 'value must be ' . UserEntity::class;
}

return true;
}

return parent::validate($attr, $value);
}
}
2 changes: 1 addition & 1 deletion src/SSOfy/Models/Signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* @property string hash
* @property string $salt
* @property string salt
*/
class Signature extends BaseModel
{
Expand Down
18 changes: 18 additions & 0 deletions src/SSOfy/Models/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ class Token extends BaseModel
'expires_at',
];

protected function validate($attr, $value)
{
if (is_null($value)) {
return true;
}

switch ($attr) {
case 'scopes':
if (!is_array($value)) {
return 'value must be array';
}

return true;
}

return parent::validate($attr, $value);
}

public function export()
{
$export = parent::export();
Expand Down

0 comments on commit 42397b6

Please sign in to comment.