diff --git a/CHANGELOG.md b/CHANGELOG.md index 9edcbe0..1a0f662 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/SSOfy/Client.php b/src/SSOfy/Client.php index ef3008f..66c31c0 100644 --- a/src/SSOfy/Client.php +++ b/src/SSOfy/Client.php @@ -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']), ]); } @@ -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']) ]); } diff --git a/src/SSOfy/Models/APIResponse.php b/src/SSOfy/Models/APIResponse.php index 0024786..8ed5ac6 100644 --- a/src/SSOfy/Models/APIResponse.php +++ b/src/SSOfy/Models/APIResponse.php @@ -5,8 +5,8 @@ use SSOfy\Models\Entities\UserEntity; /** - * @property Token token - * @property UserEntity $user + * @property Token token + * @property UserEntity user */ class APIResponse extends BaseModel { @@ -14,4 +14,29 @@ class APIResponse extends BaseModel '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); + } } diff --git a/src/SSOfy/Models/Signature.php b/src/SSOfy/Models/Signature.php index f8976cc..30f7ebf 100644 --- a/src/SSOfy/Models/Signature.php +++ b/src/SSOfy/Models/Signature.php @@ -4,7 +4,7 @@ /** * @property string hash - * @property string $salt + * @property string salt */ class Signature extends BaseModel { diff --git a/src/SSOfy/Models/Token.php b/src/SSOfy/Models/Token.php index 66302e0..5508650 100644 --- a/src/SSOfy/Models/Token.php +++ b/src/SSOfy/Models/Token.php @@ -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();