Skip to content

Commit

Permalink
Merge 6b44572 into efdb97f
Browse files Browse the repository at this point in the history
  • Loading branch information
byjg committed Jan 4, 2019
2 parents efdb97f + 6b44572 commit f55df57
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 48 deletions.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -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
Expand All @@ -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)
19 changes: 16 additions & 3 deletions _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:
Expand Down Expand Up @@ -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

2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -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"
Expand Down
14 changes: 6 additions & 8 deletions src/Interfaces/UsersInterface.php
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -152,8 +152,7 @@ public function removeAllProperties($propertyName, $value = null);
public function createAuthToken(
$login,
$password,
$serverUri,
$secret,
$jwtWrapper,
$expires = 1200,
$updateUserInfo = [],
$updateTokenInfo = []
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/UsersAnyDataset.php
Expand Up @@ -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
{
Expand Down
28 changes: 12 additions & 16 deletions src/UsersBase.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = []
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions src/UsersDBDataset.php
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/UsersMoodleDataset.php
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/UsersAnyDataset2ByEmailTest.php
Expand Up @@ -2,7 +2,6 @@

namespace ByJG\Authenticate;

use ByJG\Authenticate\Definition\UserPropertiesDefinition;
use ByJG\Authenticate\Definition\UserDefinition;

require_once 'UsersAnyDataset2ByUsernameTest.php';
Expand Down
2 changes: 1 addition & 1 deletion tests/UsersAnyDataset2ByUsernameTest.php
Expand Up @@ -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';
Expand Down
1 change: 0 additions & 1 deletion tests/UsersAnyDatasetByEmailTest.php
Expand Up @@ -3,7 +3,6 @@
namespace ByJG\Authenticate;

use ByJG\Authenticate\Definition\UserDefinition;
use ByJG\Authenticate\Definition\UserPropertiesDefinition;

require_once "UsersAnyDatasetByUsernameTest.php";

Expand Down
15 changes: 9 additions & 6 deletions tests/UsersAnyDatasetByUsernameTest.php
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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)
);
}

Expand All @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/UsersDBDataset2ByUserNameTest.php
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/UsersDBDatasetDefinitionTest.php
Expand Up @@ -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
Expand Down

0 comments on commit f55df57

Please sign in to comment.