Skip to content

Commit

Permalink
Updating code to new JwtWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
byjg committed Jan 3, 2019
1 parent 24564fb commit 79b840c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,5 @@ We store a cookie named AUTH_BEARER_<context name> with the session name. The PH
PHP create it by default but we do not use it;


----
[Open source ByJG](http://opensource.byjg.com)
7 changes: 3 additions & 4 deletions src/JwtSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ public function read($session_id)
if (isset($_COOKIE[self::COOKIE_PREFIX . $this->sessionConfig->getSessionContext()])) {
$jwt = new JwtWrapper(
$this->sessionConfig->getServerName(),
$this->sessionConfig->getSecretKey(),
$this->sessionConfig->getPublicKey()
$this->sessionConfig->getKey()
);
$data = $jwt->extractData($_COOKIE[self::COOKIE_PREFIX . $this->sessionConfig->getSessionContext()]);

Expand Down Expand Up @@ -181,14 +180,14 @@ public function read($session_id)
* The return value (usually TRUE on success, FALSE on failure).
* Note this value is returned internally to PHP for processing.
* </p>
* @throws \ByJG\Util\JwtWrapperException
* @since 5.4.0
*/
public function write($session_id, $session_data)
{
$jwt = new JwtWrapper(
$this->sessionConfig->getServerName(),
$this->sessionConfig->getSecretKey(),
$this->sessionConfig->getPublicKey()
$this->sessionConfig->getKey()
);
$data = $jwt->createJwtData($session_data, $this->sessionConfig->getTimeoutMinutes() * 60);
$token = $jwt->generateToken($data);
Expand Down
27 changes: 10 additions & 17 deletions src/SessionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace ByJG\Session;

use ByJG\Util\JwtKeyInterface;
use ByJG\Util\JwtKeySecret;
use ByJG\Util\JwtRsaKey;

class SessionConfig
{
protected $serverName;
Expand All @@ -10,8 +14,7 @@ class SessionConfig
protected $timeoutMinutes = 20;
protected $cookieDomain = null;
protected $cookiePath = '/';
protected $secretKey = null;
protected $publicKey = null;
protected $jwtKey = null;
protected $replaceSessionHandler = null;

/**
Expand Down Expand Up @@ -45,14 +48,12 @@ public function withCookie($domain, $path = "/") {
}

public function withSecret($secret) {
$this->secretKey = $secret;
$this->publicKey = null;
$this->jwtKey = new JwtKeySecret($secret);
return $this;
}

public function withRsaSecret($private, $public) {
$this->secretKey = $private;
$this->publicKey = $public;
$this->jwtKey = new JwtRsaKey($private, $public);
return $this;
}

Expand Down Expand Up @@ -102,19 +103,11 @@ public function getCookiePath()
}

/**
* @return null
*/
public function getSecretKey()
{
return $this->secretKey;
}

/**
* @return null
* @return JwtKeyInterface
*/
public function getPublicKey()
public function getKey()
{
return $this->publicKey;
return $this->jwtKey;
}

public function isReplaceSession() {
Expand Down

0 comments on commit 79b840c

Please sign in to comment.