/**
  * @return TokenGrantTypeProcessorInterface
  */
 private function findProcessor($grantType)
 {
     if (f\contains($this->processors, $grantType)) {
         return f\get($this->processors, $grantType);
     }
     throw new UnsupportedGrantTypeOAuthErrorException();
 }
Пример #2
0
/**
 * f\contains_in($coll, $in)
 *
 * Returns whether a nested structure exists or not.
 *
 * f\contains_in(array('a' => array('a1' => 1)), array('a'));
 * => true
 *
 * f\contains_in(array('a' => array('a1' => 1)), array('a', 'a1));
 * => true
 *
 * f\contains_in(array('a' => array('a1' => 1)), array('a', 'a2));
 * => false
 *
 * f\contains_in(array('a' => array('a1' => 1)), array('b'));
 * => false
 *
 * f\contains_in(array('a' => array('a1' => 1)), array('b', 'b1'));
 * => false
 *
 * // returns false with an empty in
 * f\contains_in(array('a' => 1), array());
 * => false
 *
 * // supports infinite nesting
 * f\contains_in(array('a', 'a1', 'a1I', 'a1IA'), array('a', 'a1', 'a1I', 'a1IA'));
 * => true
 */
function contains_in($coll, $in)
{
    $arrayIn = f\_coll_in($coll, $in);
    if ($arrayIn === false) {
        return false;
    }
    return f\contains($arrayIn, f\last($in));
}
 public function load(array $configs, ContainerBuilder $container)
 {
     $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/Resources'));
     $loader->load('services.xml');
     $configuration = $this->getConfiguration($configs, $container);
     $config = $this->processConfiguration($configuration, $configs);
     $container->setParameter('akamon.oauth2_server.token_lifetime', $config['token_lifetime']);
     $container->setParameter('akamon.oauth2_server.scopes', $config['scopes']);
     $this->loadRepositories($config['repositories'], $container);
     if (f\contains($config, 'token_grant_type_processors')) {
         $this->loadTokenGrantTypeProcessors($config['token_grant_type_processors'], $container);
     }
 }
Пример #4
0
function _coll_depth($array, $depth)
{
    $first = f\first($depth);
    if (f\contains($array, $first)) {
        $arrayIn = f\to_array(f\get($array, $first));
        $inRest = f\rest($depth);
        if (count($inRest)) {
            return f\_coll_depth($arrayIn, $inRest);
        }
        return $arrayIn;
    }
    return false;
}
 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')));
 }
Пример #6
0
/**
 * f\validate_coll($coll, $paramRules)
 *
 * Returns the validation errors when validating coll with param rules.
 *
 * // validating existence
 * f\validate_coll(array(), array('a' => f\required(), 'b' => f\optional()));
 * => array('a' => 'required')
 *
 * // multiple errors
 * f\validate_coll(array(), array('a' => f\required(), 'b' => f\required()));
 * => array('a' => 'required', 'b' => 'required')
 *
 * // validator fn
 * f\validate_coll(array('a' => 1.0), array('a' => f\required('v' => 'is_int')));
 * => array('a' => 'invalid')
 *
 * // without errors
 * f\validate_coll(array('a' => 1), array('a' => f\required('v' => 'is_int')));
 * => array()
 */
function validate_coll($coll, $paramRules)
{
    $validate = function ($paramRule, $key) use($coll) {
        if (f\not($paramRule instanceof param_rule)) {
            throw new \InvalidArgumentException('Param rules must be created with felpado\\required and felpado\\optional.');
        }
        if (f\contains($coll, $key)) {
            if ($paramRule->getValidator()) {
                $value = f\get($coll, $key);
                if (f\not(is_null($value) && $paramRule instanceof optional)) {
                    $isValid = f\validate($value, $paramRule->getValidator());
                    if (f\not($isValid)) {
                        return 'invalid';
                    }
                }
            }
        } elseif ($paramRule instanceof required) {
            return 'required';
        }
        return null;
    };
    return f\filter_indexed('felpado\\identity', f\map($validate, $paramRules));
}
Пример #7
0
 public function testNotExists()
 {
     $coll = array(1 => 'one', 2 => 'two');
     $this->assertFalse(f\contains($coll, 3));
     $this->assertFalse(f\contains($coll, 4));
 }
Пример #8
0
 public function addTokenGrantTypeProcessor($name, TokenGrantTypeProcessorInterface $processor)
 {
     if (f\contains($this->tokenGrantTypeProcessors, $name)) {
         throw new \InvalidArgumentException(sprintf('The token grant type processor "%s" already exists.', $name));
     }
     $this->tokenGrantTypeProcessors[$name] = $processor;
 }
 private function hasNoUserCredentialsInInputData($inputData)
 {
     return f\not(f\contains($inputData, 'username')) || f\not(f\contains($inputData, 'password'));
 }
Пример #10
0
 public function find($id)
 {
     $all = $this->allFromFile();
     return f\contains($all, $id) ? new Client(f\get($all, $id)) : null;
 }