public function resolve(Context $context)
 {
     if (f\not($context->getScopes()->isEmpty())) {
         return $context;
     }
     $defaultScopes = ScopeCollection::createFromString(f\get($context->getClient(), 'defaultScope'));
     return new Context($context->getClient(), $context->getUserId(), $defaultScopes);
 }
 public function testOk()
 {
     $client = $this->createClient();
     $accessToken = $this->createAccessToken();
     $refreshToken = $this->createRefreshToken(['accessTokenToken' => f\get($accessToken, 'token')]);
     $context = new Context($client, f\get($accessToken, 'userId'), ScopeCollection::createFromString(f\get($accessToken, 'scope')));
     $params = new \stdClass();
     $this->refreshTokenRepository->shouldReceive('find')->with(f\get($refreshToken, 'token'))->once()->andReturn($refreshToken)->ordered();
     $this->accessTokenRepository->shouldReceive('find')->with(f\get($refreshToken, 'accessTokenToken'))->andReturn($accessToken)->ordered();
     $this->refreshTokenRepository->shouldReceive('remove')->with($refreshToken)->once()->ordered();
     $this->accessTokenRepository->shouldReceive('remove')->with($accessToken)->once()->ordered();
     $this->tokenCreator->shouldReceive('create')->with(\Mockery::on(function ($v) use($context) {
         return $v == $context;
     }))->once()->andReturn($params);
     $this->assertSame($params, $this->processor->process($client, ['refresh_token' => f\get($refreshToken, 'token')]));
 }
 private function getContext(Client $client, array $inputData)
 {
     if (f\not(f\contains($inputData, 'refresh_token'))) {
         throw new RefreshTokenNotFoundOAuthErrorException();
     }
     $refreshToken = $this->refreshTokenRepository->find(f\get($inputData, 'refresh_token'));
     if (f\not($refreshToken)) {
         throw new InvalidRefreshTokenOAuthErrorException();
     }
     if ($refreshToken->isExpired()) {
         throw new ExpiredRefreshTokenOAuthErrorException();
     }
     $accessToken = $this->accessTokenRepository->find(f\get($refreshToken, 'accessTokenToken'));
     if (f\not($accessToken)) {
         $this->refreshTokenRepository->remove($refreshToken);
         throw new InvalidRefreshTokenOAuthErrorException();
     }
     $this->refreshTokenRepository->remove($refreshToken);
     $this->accessTokenRepository->remove($accessToken);
     return new Context($client, f\get($accessToken, 'userId'), ScopeCollection::createFromString(f\get($accessToken, 'scope')));
 }
Ejemplo n.º 4
0
 public function getScopes(array $inputData)
 {
     $string = f\get_or($inputData, 'scope', null);
     return ScopeCollection::createFromString($string);
 }
Ejemplo n.º 5
0
 public function testCreateFromString()
 {
     $this->assertEquals(new ScopeCollection([]), ScopeCollection::createFromString(''));
     $this->assertEquals(new ScopeCollection([new Scope('foo')]), ScopeCollection::createFromString('foo'));
     $this->assertEquals(new ScopeCollection([new Scope('foo'), new Scope('bar')]), ScopeCollection::createFromString('foo bar'));
 }