/** @test */ public function it_should_invalidate_a_token() { $claims = [new Subject(1), new Issuer('http://example.com'), new Expiration(123 + 3600), new NotBefore(123), new IssuedAt(123), new JwtId('foo')]; $payload = new Payload($claims, $this->validator); $token = new Token('foo.bar.baz'); $this->jwt->shouldReceive('decode')->once()->with('foo.bar.baz')->andReturn($payload->toArray()); $this->factory->shouldReceive('setRefreshFlow->make')->with($payload->toArray())->andReturn($payload); $this->blacklist->shouldReceive('has')->with($payload)->andReturn(false); $this->blacklist->shouldReceive('add')->with($payload)->andReturn(true); $this->manager->invalidate($token); }
/** * Get the unique key held within the blacklist * * @param Payload $payload * * @return mixed */ public function getKey(Payload $payload) { return $payload->get($this->key); }
/** * @param Payload $payload * @param string $token * * @return bool */ protected static function setTokenMap($payload, $token) { $map = ['user_id' => $payload->get('user_id'), 'iat' => $payload->get('iat'), 'exp' => $payload->get('exp'), 'token' => $token]; return \DB::table('token_map')->insert($map); }
/** * Encode a Payload and return the Token. * * @param \Tymon\JWTAuth\Payload $payload * * @return \Tymon\JWTAuth\Token */ public function encode(Payload $payload) { $token = $this->provider->encode($payload->get()); return new Token($token); }
public function testRefreshExpiredToken() { $user = $this->createUser(); $claims = [new UserClaim($user), new Subject(1), new Issuer('http://foo.bar'), new Expiration(123 - 3600), new NotBefore(123), new IssuedAt(123), new JwtId('foo')]; $validator = Mockery::mock('Tymon\\JWTAuth\\Validators\\PayloadValidator'); $validator->shouldReceive('setRefreshFlow->check'); $payload = new Payload($claims, $validator, true); $cfg = $this->app->config->get('jwt'); $adapter = new App\Extensions\JWTAuth\NamshiAdapter($cfg['secret'], $cfg['algo']); $token = $adapter->encode($payload->get()); $this->callRefreshToken($token); $body = json_decode($this->response->getContent()); $this->assertResponseStatus(401); $this->assertContains('expired', $body->message); }