diff --git a/README.md b/README.md index 07d428c..794ba0e 100644 --- a/README.md +++ b/README.md @@ -344,7 +344,7 @@ $users = new ByJG\Authenticate\UsersDBDataset( Just type: ``` -composer require "byjg/authuser=4.0.*" +composer require "byjg/authuser=4.1.*" ``` # Running Tests @@ -355,3 +355,6 @@ Because this project uses PHP Session you need to run the unit test the followin phpunit --stderr ``` + +---- +[Open source ByJG](http://opensource.byjg.com) diff --git a/_config.yml b/_config.yml index 34de2f0..314227d 100644 --- a/_config.yml +++ b/_config.yml @@ -1,7 +1,7 @@ name: authuser project: - version: 4.0.0 + version: 1.0.0 download_url: https://github.com/byjg/authuser/releases license: @@ -41,13 +41,26 @@ social: hash: opensourcebyjg account: facebook: - enabled: false + enabled: true + url: https://opensource.byjg.com/ profileUrl: +author: + twitter: byjg + +twitter: + card: summary + username: byjg + +logo: https://opensource.byjg.com/images/logo_byjg.png + analytics: google: UA-130014324-1 +plugins: + - jekyll-seo-tag + # Build settings markdown: kramdown -remote_theme: allejo/jekyll-docs-theme +remote_theme: byjg/jekyll-docs-theme diff --git a/composer.json b/composer.json index 58f1c84..0f569cc 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "php": ">=5.6.0", "byjg/micro-orm": "4.0.*", "byjg/cache-engine": "4.0.*", - "byjg/jwt-wrapper": "1.0.*" + "byjg/jwt-wrapper": "2.0.*" }, "require-dev": { "phpunit/phpunit": ">5.7" diff --git a/src/Interfaces/UsersInterface.php b/src/Interfaces/UsersInterface.php index 05a83db..0fa894f 100644 --- a/src/Interfaces/UsersInterface.php +++ b/src/Interfaces/UsersInterface.php @@ -4,9 +4,10 @@ use ByJG\AnyDataset\Core\IteratorFilter; use ByJG\AnyDataset\Core\Row; -use ByJG\Authenticate\Definition\UserPropertiesDefinition; use ByJG\Authenticate\Definition\UserDefinition; +use ByJG\Authenticate\Definition\UserPropertiesDefinition; use ByJG\Authenticate\Model\UserModel; +use ByJG\Util\JwtWrapper; /** * IUsersBase is a Interface to Store and Retrive USERS from an AnyDataset or a DBDataset structure. @@ -142,8 +143,7 @@ public function removeAllProperties($propertyName, $value = null); * * @param string $login * @param string $password - * @param string $serverUri - * @param string $secret + * @param JwtWrapper $jwtWrapper * @param int $expires * @param array $updateUserInfo * @param array $updateTokenInfo @@ -152,8 +152,7 @@ public function removeAllProperties($propertyName, $value = null); public function createAuthToken( $login, $password, - $serverUri, - $secret, + $jwtWrapper, $expires = 1200, $updateUserInfo = [], $updateTokenInfo = [] @@ -163,12 +162,11 @@ public function createAuthToken( * Check if the Auth Token is valid * * @param string $login - * @param string $uri - * @param string $secret + * @param JwtWrapper $jwtWrapper * @param string $token * @return bool */ - public function isValidToken($login, $uri, $secret, $token); + public function isValidToken($login, $jwtWrapper, $token); /** * @return UserDefinition Description diff --git a/src/UsersAnyDataset.php b/src/UsersAnyDataset.php index a6714af..50916ce 100644 --- a/src/UsersAnyDataset.php +++ b/src/UsersAnyDataset.php @@ -3,14 +3,14 @@ namespace ByJG\Authenticate; use ByJG\AnyDataset\Core\AnyDataset; -use ByJG\AnyDataset\Core\IteratorFilter; use ByJG\AnyDataset\Core\Enum\Relation; +use ByJG\AnyDataset\Core\IteratorFilter; use ByJG\AnyDataset\Core\IteratorInterface; use ByJG\AnyDataset\Core\Row; -use ByJG\Authenticate\Definition\UserPropertiesDefinition; use ByJG\Authenticate\Definition\UserDefinition; -use ByJG\Authenticate\Model\UserPropertiesModel; +use ByJG\Authenticate\Definition\UserPropertiesDefinition; use ByJG\Authenticate\Model\UserModel; +use ByJG\Authenticate\Model\UserPropertiesModel; class UsersAnyDataset extends UsersBase { diff --git a/src/UsersBase.php b/src/UsersBase.php index 1fb27f1..9b3a6cf 100644 --- a/src/UsersBase.php +++ b/src/UsersBase.php @@ -4,8 +4,8 @@ use ByJG\AnyDataset\Core\Enum\Relation; use ByJG\AnyDataset\Core\IteratorFilter; -use ByJG\Authenticate\Definition\UserPropertiesDefinition; use ByJG\Authenticate\Definition\UserDefinition; +use ByJG\Authenticate\Definition\UserPropertiesDefinition; use ByJG\Authenticate\Exception\NotAuthenticatedException; use ByJG\Authenticate\Exception\UserExistsException; use ByJG\Authenticate\Exception\UserNotFoundException; @@ -309,20 +309,18 @@ public function isAdmin($userId) * * @param string $login * @param string $password - * @param string $serverUri - * @param string $secret + * @param JwtWrapper $jwtWrapper * @param int $expires * @param array $updateUserInfo * @param array $updateTokenInfo * @return string the TOKEN or false if dont. - * @throws \ByJG\Authenticate\Exception\UserNotFoundException + * @throws UserNotFoundException * @throws \ByJG\Serializer\Exception\InvalidArgumentException */ public function createAuthToken( $login, $password, - $serverUri, - $secret, + $jwtWrapper, $expires = 1200, $updateUserInfo = [], $updateTokenInfo = [] @@ -340,15 +338,14 @@ public function createAuthToken( $user->set($key, $value); } - $jwt = new JwtWrapper($serverUri, $secret); $updateTokenInfo['login'] = $login; $updateTokenInfo['userid'] = $user->getUserid(); - $jwtData = $jwt->createJwtData( + $jwtData = $jwtWrapper->createJwtData( $updateTokenInfo, $expires ); - $token = $jwt->generateToken($jwtData); + $token = $jwtWrapper->generateToken($jwtData); $user->set('TOKEN_HASH', sha1($token)); $this->save($user); @@ -360,15 +357,15 @@ public function createAuthToken( * Check if the Auth Token is valid * * @param string $login - * @param string $uri - * @param string $secret + * @param JwtWrapper $jwtWrapper * @param string $token * @return array - * @throws \ByJG\Authenticate\Exception\NotAuthenticatedException - * @throws \ByJG\Authenticate\Exception\UserNotFoundException + * @throws NotAuthenticatedException + * @throws UserNotFoundException * @throws \ByJG\Serializer\Exception\InvalidArgumentException + * @throws \ByJG\Util\JwtWrapperException */ - public function isValidToken($login, $uri, $secret, $token) + public function isValidToken($login, $jwtWrapper, $token) { $user = $this->getByLoginField($login); @@ -380,8 +377,7 @@ public function isValidToken($login, $uri, $secret, $token) throw new NotAuthenticatedException('Token does not match'); } - $jwt = new JwtWrapper($uri, $secret); - $data = $jwt->extractData($token); + $data = $jwtWrapper->extractData($token); $this->save($user); diff --git a/src/UsersDBDataset.php b/src/UsersDBDataset.php index d67f842..34c26ea 100644 --- a/src/UsersDBDataset.php +++ b/src/UsersDBDataset.php @@ -3,12 +3,12 @@ namespace ByJG\Authenticate; use ByJG\AnyDataset\Core\IteratorFilter; -use ByJG\AnyDataset\Db\IteratorFilterSqlFormatter; use ByJG\AnyDataset\Db\Factory; -use ByJG\Authenticate\Definition\UserPropertiesDefinition; +use ByJG\AnyDataset\Db\IteratorFilterSqlFormatter; use ByJG\Authenticate\Definition\UserDefinition; -use ByJG\Authenticate\Model\UserPropertiesModel; +use ByJG\Authenticate\Definition\UserPropertiesDefinition; use ByJG\Authenticate\Model\UserModel; +use ByJG\Authenticate\Model\UserPropertiesModel; use ByJG\MicroOrm\Mapper; use ByJG\MicroOrm\Query; use ByJG\MicroOrm\Repository; diff --git a/src/UsersMoodleDataset.php b/src/UsersMoodleDataset.php index 23f1ac0..b72b4de 100644 --- a/src/UsersMoodleDataset.php +++ b/src/UsersMoodleDataset.php @@ -7,11 +7,11 @@ */ define('AUTH_PASSWORD_NOT_CACHED', 'not cached'); // String used in password field when password is not stored. -use ByJG\Authenticate\Definition\UserPropertiesDefinition; use ByJG\Authenticate\Definition\UserDefinition; +use ByJG\Authenticate\Definition\UserPropertiesDefinition; use ByJG\Authenticate\Exception\NotImplementedException; -use ByJG\Authenticate\Model\UserPropertiesModel; use ByJG\Authenticate\Model\UserModel; +use ByJG\Authenticate\Model\UserPropertiesModel; use ErrorException; class UsersMoodleDataset extends UsersDBDataset diff --git a/tests/UsersAnyDataset2ByEmailTest.php b/tests/UsersAnyDataset2ByEmailTest.php index e7f4499..02df51a 100644 --- a/tests/UsersAnyDataset2ByEmailTest.php +++ b/tests/UsersAnyDataset2ByEmailTest.php @@ -2,7 +2,6 @@ namespace ByJG\Authenticate; -use ByJG\Authenticate\Definition\UserPropertiesDefinition; use ByJG\Authenticate\Definition\UserDefinition; require_once 'UsersAnyDataset2ByUsernameTest.php'; diff --git a/tests/UsersAnyDataset2ByUsernameTest.php b/tests/UsersAnyDataset2ByUsernameTest.php index 570fe4f..f584f3f 100644 --- a/tests/UsersAnyDataset2ByUsernameTest.php +++ b/tests/UsersAnyDataset2ByUsernameTest.php @@ -2,8 +2,8 @@ namespace ByJG\Authenticate; -use ByJG\Authenticate\Definition\UserPropertiesDefinition; use ByJG\Authenticate\Definition\UserDefinition; +use ByJG\Authenticate\Definition\UserPropertiesDefinition; use ByJG\Authenticate\Model\UserModel; require_once 'UsersAnyDatasetByUsernameTest.php'; diff --git a/tests/UsersAnyDatasetByEmailTest.php b/tests/UsersAnyDatasetByEmailTest.php index 9dd8c13..283a847 100644 --- a/tests/UsersAnyDatasetByEmailTest.php +++ b/tests/UsersAnyDatasetByEmailTest.php @@ -3,7 +3,6 @@ namespace ByJG\Authenticate; use ByJG\Authenticate\Definition\UserDefinition; -use ByJG\Authenticate\Definition\UserPropertiesDefinition; require_once "UsersAnyDatasetByUsernameTest.php"; diff --git a/tests/UsersAnyDatasetByUsernameTest.php b/tests/UsersAnyDatasetByUsernameTest.php index 86e4abe..4deb707 100644 --- a/tests/UsersAnyDatasetByUsernameTest.php +++ b/tests/UsersAnyDatasetByUsernameTest.php @@ -5,6 +5,8 @@ use ByJG\Authenticate\Definition\UserDefinition; use ByJG\Authenticate\Definition\UserPropertiesDefinition; use ByJG\Authenticate\Model\UserModel; +use ByJG\Util\JwtKeySecret; +use ByJG\Util\JwtWrapper; use PHPUnit\Framework\TestCase; class UsersAnyDatasetByUsernameTest extends TestCase @@ -211,11 +213,12 @@ protected function expectedToken($tokenData, $login, $userId) { $loginCreated = $this->__chooseValue('user2', 'user2@gmail.com'); + $jwtWrapper = new JwtWrapper('api.test.com', new JwtKeySecret('12345678', false)); + $token = $this->object->createAuthToken( $loginCreated, 'pwd2', - 'api.test.com', - '1234567', + $jwtWrapper, 1200, ['userData'=>'userValue'], ['tokenData'=>$tokenData] @@ -233,7 +236,7 @@ protected function expectedToken($tokenData, $login, $userId) 'user' => $user, 'data' => $dataFromToken ], - $this->object->isValidToken($loginCreated, 'api.test.com', '1234567', $token) + $this->object->isValidToken($loginCreated, $jwtWrapper, $token) ); } @@ -252,17 +255,17 @@ public function testValidateTokenWithAnotherUser() $login = $this->__chooseValue('user2', 'user2@gmail.com'); $loginToFail = $this->__chooseValue('user1', 'user1@gmail.com'); + $jwtWrapper = new JwtWrapper('api.test.com', new JwtKeySecret('1234567')); $token = $this->object->createAuthToken( $login, 'pwd2', - 'api.test.com', - '1234567', + $jwtWrapper, 1200, ['userData'=>'userValue'], ['tokenData'=>'tokenValue'] ); - $this->object->isValidToken($loginToFail, 'api.test.com', '1234567', $token); + $this->object->isValidToken($loginToFail, $jwtWrapper, $token); } /** diff --git a/tests/UsersDBDataset2ByUserNameTest.php b/tests/UsersDBDataset2ByUserNameTest.php index cecf4ef..820946d 100644 --- a/tests/UsersDBDataset2ByUserNameTest.php +++ b/tests/UsersDBDataset2ByUserNameTest.php @@ -5,8 +5,8 @@ require_once 'UsersDBDatasetByUsernameTest.php'; use ByJG\AnyDataset\Db\Factory; -use ByJG\Authenticate\Definition\UserPropertiesDefinition; use ByJG\Authenticate\Definition\UserDefinition; +use ByJG\Authenticate\Definition\UserPropertiesDefinition; use ByJG\Authenticate\Model\UserModel; class UsersDBDataset2ByUserNameTest extends UsersDBDatasetByUsernameTest diff --git a/tests/UsersDBDatasetDefinitionTest.php b/tests/UsersDBDatasetDefinitionTest.php index 76d4ef4..96e7bfb 100644 --- a/tests/UsersDBDatasetDefinitionTest.php +++ b/tests/UsersDBDatasetDefinitionTest.php @@ -5,8 +5,8 @@ require_once 'UsersDBDatasetByUsernameTest.php'; use ByJG\AnyDataset\Db\Factory; -use ByJG\Authenticate\Definition\UserPropertiesDefinition; use ByJG\Authenticate\Definition\UserDefinition; +use ByJG\Authenticate\Definition\UserPropertiesDefinition; use ByJG\Authenticate\Model\UserModel; class MyUserModel extends UserModel