Skip to content

Commit 79b840c

Browse files
committed
Updating code to new JwtWrapper
1 parent 24564fb commit 79b840c

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,5 @@ We store a cookie named AUTH_BEARER_<context name> with the session name. The PH
160160
PHP create it by default but we do not use it;
161161

162162

163+
----
164+
[Open source ByJG](http://opensource.byjg.com)

src/JwtSession.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ public function read($session_id)
148148
if (isset($_COOKIE[self::COOKIE_PREFIX . $this->sessionConfig->getSessionContext()])) {
149149
$jwt = new JwtWrapper(
150150
$this->sessionConfig->getServerName(),
151-
$this->sessionConfig->getSecretKey(),
152-
$this->sessionConfig->getPublicKey()
151+
$this->sessionConfig->getKey()
153152
);
154153
$data = $jwt->extractData($_COOKIE[self::COOKIE_PREFIX . $this->sessionConfig->getSessionContext()]);
155154

@@ -181,14 +180,14 @@ public function read($session_id)
181180
* The return value (usually TRUE on success, FALSE on failure).
182181
* Note this value is returned internally to PHP for processing.
183182
* </p>
183+
* @throws \ByJG\Util\JwtWrapperException
184184
* @since 5.4.0
185185
*/
186186
public function write($session_id, $session_data)
187187
{
188188
$jwt = new JwtWrapper(
189189
$this->sessionConfig->getServerName(),
190-
$this->sessionConfig->getSecretKey(),
191-
$this->sessionConfig->getPublicKey()
190+
$this->sessionConfig->getKey()
192191
);
193192
$data = $jwt->createJwtData($session_data, $this->sessionConfig->getTimeoutMinutes() * 60);
194193
$token = $jwt->generateToken($data);

src/SessionConfig.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
namespace ByJG\Session;
44

5+
use ByJG\Util\JwtKeyInterface;
6+
use ByJG\Util\JwtKeySecret;
7+
use ByJG\Util\JwtRsaKey;
8+
59
class SessionConfig
610
{
711
protected $serverName;
@@ -10,8 +14,7 @@ class SessionConfig
1014
protected $timeoutMinutes = 20;
1115
protected $cookieDomain = null;
1216
protected $cookiePath = '/';
13-
protected $secretKey = null;
14-
protected $publicKey = null;
17+
protected $jwtKey = null;
1518
protected $replaceSessionHandler = null;
1619

1720
/**
@@ -45,14 +48,12 @@ public function withCookie($domain, $path = "/") {
4548
}
4649

4750
public function withSecret($secret) {
48-
$this->secretKey = $secret;
49-
$this->publicKey = null;
51+
$this->jwtKey = new JwtKeySecret($secret);
5052
return $this;
5153
}
5254

5355
public function withRsaSecret($private, $public) {
54-
$this->secretKey = $private;
55-
$this->publicKey = $public;
56+
$this->jwtKey = new JwtRsaKey($private, $public);
5657
return $this;
5758
}
5859

@@ -102,19 +103,11 @@ public function getCookiePath()
102103
}
103104

104105
/**
105-
* @return null
106-
*/
107-
public function getSecretKey()
108-
{
109-
return $this->secretKey;
110-
}
111-
112-
/**
113-
* @return null
106+
* @return JwtKeyInterface
114107
*/
115-
public function getPublicKey()
108+
public function getKey()
116109
{
117-
return $this->publicKey;
110+
return $this->jwtKey;
118111
}
119112

120113
public function isReplaceSession() {

0 commit comments

Comments
 (0)