public function testATokenWillNotBeValidIfTheTokenHasExpired() { $expiredTime = time() - 60 * 60 * 24 * 7; $graphSession = $this->createGraphSessionInfo('123', 'foo_machine', true, $expiredTime); $app = new FacebookApp('123', 'foo_secret'); $isValid = AccessToken::validateAccessToken($graphSession, $app, 'foo_machine'); $this->assertFalse($isValid, 'Expected access token to be invalid because it has expired.'); }
public function testATokenWillNotBeValidIfTheTokenHasExpired() { $lastWeek = time() - 60 * 60 * 24 * 7; $dt = new \DateTime(); $dt->setTimestamp($lastWeek); $graphSessionInfoMock = m::mock('Facebook\\GraphNodes\\GraphSessionInfo'); $graphSessionInfoMock->shouldReceive('getProperty')->with('app_id')->once()->andReturn('123'); $graphSessionInfoMock->shouldReceive('getProperty')->with('machine_id')->once()->andReturn('foo_machine'); $graphSessionInfoMock->shouldReceive('getIsValid')->once()->andReturn(true); $graphSessionInfoMock->shouldReceive('getExpiresAt')->twice()->andReturn($dt); $app = new FacebookApp('123', 'foo_secret'); $isValid = AccessToken::validateAccessToken($graphSessionInfoMock, $app, 'foo_machine'); $this->assertFalse($isValid, 'Expected access token to be invalid because it has expired.'); }
/** * validateTokenInfo - Ensures the provided GraphSessionInfo object is valid, * throwing an exception if not. Ensures the appId matches, * that the token is valid and has not expired. * * @param GraphSessionInfo $tokenInfo * @param string|null $appId Application ID to use * @param string|null $machineId * * @throws FacebookSDKException * * @return bool */ public static function validateSessionInfo(GraphSessionInfo $tokenInfo, $appId = null, $machineId = null) { if (AccessToken::validateAccessToken($tokenInfo, $appId, $machineId)) { return true; } // @TODO For v4.1 this should not throw an exception, but just return false. throw new FacebookSDKException('Session has expired, or is not valid for this app.', 601); }