Ejemplo n.º 1
0
 protected function validateValue($name, $value, $type)
 {
     $validator = new XApiValidator();
     $validator->checkTypes($name, $value, $type, 'params');
     if ($validator->getStatus() !== 'passed') {
         throw new Exceptions\Exception(implode(',', $validator->getErrors()));
     }
 }
Ejemplo n.º 2
0
|--------------------------------------------------------------------------
|
| Login in once using key / secret to store statements or retrieve statements.
|
*/
Route::filter('auth.statement', function ($route, $request) {
    $method = Request::server('REQUEST_METHOD');
    if ($method !== "OPTIONS") {
        // Validates authorization header.
        $auth_validator = new XApiValidator();
        $authorization = LockerRequest::header('Authorization');
        if ($authorization !== null && strpos($authorization, 'Basic') === 0) {
            $authorization = gettype($authorization) === 'string' ? substr($authorization, 6) : false;
            $auth_validator->checkTypes('auth', $authorization, 'base64', 'headers');
            if ($auth_validator->getStatus() === 'failed') {
                throw new Exceptions\Validation($auth_validator->getErrors());
            }
        } else {
            if ($authorization !== null && strpos($authorization, 'Bearer') === 0) {
                $bridgedRequest = OAuth2\HttpFoundationBridge\Request::createFromRequest(Request::instance());
                $bridgedResponse = new OAuth2\HttpFoundationBridge\Response();
                if (!App::make('oauth2')->verifyResourceRequest($bridgedRequest, $bridgedResponse)) {
                    throw new Exceptions\Exception('Unauthorized request.', $bridgedResponse->getStatusCode());
                }
            } else {
                if ($authorization === null) {
                    throw new Exceptions\Exception('Unauthorized request.', 401);
                }
            }
        }
        $lrs = Helpers::getLrsFromAuth();