|
2 | 2 | namespace Trois\Utils\Auth; |
3 | 3 |
|
4 | 4 | use Firebase\JWT\JWT; |
| 5 | +use Firebase\JWT\Key; |
5 | 6 | use Firebase\JWT\ExpiredException; |
6 | 7 | use Firebase\JWT\SignatureInvalidException; |
7 | 8 | use Cake\Controller\ComponentRegistry; |
@@ -82,7 +83,7 @@ protected function _decode($token) |
82 | 83 | { |
83 | 84 | $config = $this->_config; |
84 | 85 | try { |
85 | | - $payload = JWT::decode($token, Security::salt(), $this->getConfig('token.allowedAlgs')); |
| 86 | + $payload = JWT::decode($token, new Key(Security::salt(), $this->getConfig('token.allowedAlgs'))); |
86 | 87 | return $payload; |
87 | 88 | } catch (ExpiredException $e) { |
88 | 89 | $this->_registry->getController()->Flash->error($e->getMessage()); |
@@ -125,7 +126,7 @@ public function authenticate(ServerRequest $request, Response $response) |
125 | 126 |
|
126 | 127 | // create code + token |
127 | 128 | $this->genCode(); |
128 | | - $this->token = JWT::encode(['username' => $user[$this->getConfig('fields.username')],'code' => $hasher->hash($this->code),'exp' => time() + $this->getConfig('token.duration')], Security::salt()); |
| 129 | + $this->token = JWT::encode(['username' => $user[$this->getConfig('fields.username')],'code' => $hasher->hash($this->code),'exp' => time() + $this->getConfig('token.duration')], Security::salt(), 'HS256'); |
129 | 130 |
|
130 | 131 | // transmit |
131 | 132 | $transmitted = $this->_transmit($this->code, $user, $request, $response); |
@@ -168,7 +169,7 @@ public function authenticate(ServerRequest $request, Response $response) |
168 | 169 | if (!$hasher->check($password, $payload->code)) return false; |
169 | 170 |
|
170 | 171 | // set Bearer token for BearerTokenAuth |
171 | | - $this->token = JWT::encode(['sub' => $user[$this->getConfig('token.sub')],'exp' => time() + $this->getConfig('token.duration')], Security::salt()); |
| 172 | + $this->token = JWT::encode(['sub' => $user[$this->getConfig('token.sub')],'exp' => time() + $this->getConfig('token.duration')], Security::salt(), 'HS256'); |
172 | 173 |
|
173 | 174 | // if no cookie then pass token as an argument |
174 | 175 | if($this->_registry->getController()->Auth->getConfig('storage') != 'Session') |
|
0 commit comments