/** * @param $request * @return array * @throws \Exception */ public function read($request) { $token = $this->getAuthorizationHeader($request); $this->jws = $this->jws->callLoad($token); $algo = $this->algoFactory->make(); if (!$this->jws->verify($algo->getKeyForVerifying(), $this->algoritihim)) { throw new \Exception('JWT algoritihim used for signing does not match algoritihim used for verifying'); } if ($this->jws->isExpired($algo->getKeyForVerifying(), $this->algoritihim)) { throw new \Exception('JWT has expired'); } return $this->jws->getPayload(); }
/** * @test * @group jwtnew * @expectedException \Exception */ public function readShouldThrowExceptionWhenValidationOfJWTReturnsFalse() { $this->request->shouldReceive('header')->once()->with('Authorization')->andReturn('Bearer abcd1234'); $this->jwsProxy->shouldReceive('callLoad')->once()->andReturn($this->jwsProxy); $algo = Mockery::mock('Bendbennett\\JWT\\Algorithms\\AsymmetricAlgorithm'); $algo->shouldReceive('getKeyForVerifying')->twice(); $this->algoFactory->shouldReceive('make')->once()->andReturn($algo); $this->jwsProxy->shouldReceive('verify')->once()->andReturn(true); $this->jwsProxy->shouldReceive('isExpired')->once()->andReturn('false'); $jwt = new JWT($this->jwsProxy, $this->algoFactory, $this->payload, 'algoDefinedInConfig', $this->jti); $jwt->read($this->request); }