Give JWT on register
This commit is contained in:
parent
2516cfce14
commit
81bc082145
3 changed files with 18 additions and 4 deletions
|
@ -7,7 +7,9 @@ $config = [
|
|||
'dsn' => null,
|
||||
'username' => null,
|
||||
'password' => null
|
||||
]
|
||||
],
|
||||
'secret_key' => 'AqeZFu4MWMZ=P2H_SMgS%%7y9aas52%$^eQSQ%HQbYqU(fDo',
|
||||
'jwt_lifetime' => 86400 * 365 * 5, // five years should be enough for now...
|
||||
];
|
||||
|
||||
return $config;
|
|
@ -8,6 +8,8 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||
use Gedmo\Mapping\Annotation as Gedmo;
|
||||
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Silex\Component\Security\Core\Encoder\JWTEncoder;
|
||||
use EmotionHero\Application;
|
||||
|
||||
/**
|
||||
* Users
|
||||
|
@ -139,4 +141,14 @@ class User implements UserInterface
|
|||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @JMS\VirtualProperty
|
||||
* @return String
|
||||
*/
|
||||
public function getJwt() {
|
||||
$c =Application::getInstance()->getConfig();
|
||||
$encoder = new JWTEncoder($c['secret_key'], $c['jwt_lifetime'], null);
|
||||
return $encoder->encode(['id' => $this->getUsername()]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,11 @@ $app = new Silex\Application([
|
|||
|
||||
define('USER_ID_FIELD', 'id');
|
||||
|
||||
$get_secret_key = function($payload){return 'AqeZFu4MWMZ=P2H_SMgS%%7'.$payload['uid'].'y9aas52%$^eQSQ%HQbYqU(fDo';};
|
||||
|
||||
|
||||
$app['security.jwt'] = [
|
||||
'secret_key' => 'Very_secret_key',
|
||||
'life_time' => 86400 * 365,
|
||||
'secret_key' => $eh->getConfig()['secret_key'],
|
||||
'life_time' => $eh->getConfig()['jwt_lifetime'],
|
||||
'options' => [
|
||||
'username_claim' => USER_ID_FIELD, // default name, option specifying claim containing username
|
||||
'header_name' => 'X-Access-Token', // default null, option for usage normal oauth2 header
|
||||
|
|
Loading…
Reference in a new issue