Inheritance: extends fkooman\OAuth\OAuthService
Esempio n. 1
0
    $templateManager->setDefault(array('rootFolder' => $request->getUrl()->getRoot(), 'serverMode' => $serverMode));
    $md = new MetadataStorage($db);
    $approvalStorage = new PdoApprovalStorage($db);
    $authorizationCodeStorage = new PdoAuthorizationCodeStorage($db);
    $accessTokenStorage = new PdoAccessTokenStorage($db);
    if ($initDb) {
        $md->initDatabase();
        $approvalStorage->initDatabase();
        $authorizationCodeStorage->initDatabase();
        $accessTokenStorage->initDatabase();
    }
    $remoteStorage = new RemoteStorage($md, $document);
    $session = new Session('php-remote-storage', array('secure' => 'development' !== $serverMode));
    $userAuth = new FormAuthentication(function ($userId) use($configReader) {
        $userList = $configReader->v('Users');
        if (null === $userList || !array_key_exists($userId, $userList)) {
            return false;
        }
        return $userList[$userId];
    }, $templateManager, $session);
    $apiAuth = new BearerAuthentication(new DbTokenValidator($db), array('realm' => 'remoteStorage'));
    $authenticationPlugin = new AuthenticationPlugin();
    $authenticationPlugin->register($userAuth, 'user');
    $authenticationPlugin->register($apiAuth, 'api');
    $service = new RemoteStorageService($remoteStorage, new ApprovalManagementStorage($db), $templateManager, new RemoteStorageClientStorage(), new RemoteStorageResourceServer(), $approvalStorage, $authorizationCodeStorage, $accessTokenStorage, array('disable_token_endpoint' => true, 'disable_introspect_endpoint' => true, 'route_prefix' => '/_oauth', 'require_state' => false, 'server_mode' => $serverMode));
    $service->getPluginRegistry()->registerDefaultPlugin($authenticationPlugin);
    $service->run($request)->send();
} catch (Exception $e) {
    error_log($e->getMessage());
    die(sprintf('ERROR: %s', $e->getMessage()));
}
Esempio n. 2
0
    $accessTokenStorage = new PdoAccessTokenStorage($db);
    if ($initDb) {
        $md->initDatabase();
        $approvalStorage->initDatabase();
        $authorizationCodeStorage->initDatabase();
        $accessTokenStorage->initDatabase();
    }
    $remoteStorage = new RemoteStorage($md, $document);
    $session = new Session('php-remote-storage', array('secure' => 'development' !== $serverMode));
    $userAuth = new FormAuthentication(function ($userId) use($configReader) {
        $userList = $configReader->v('Users');
        if (null === $userList || !array_key_exists($userId, $userList)) {
            return false;
        }
        return $userList[$userId];
    }, $templateManager, $session);
    $apiAuth = new BearerAuthentication(new DbTokenValidator($db), array('realm' => 'remoteStorage'));
    $authenticationPlugin = new AuthenticationPlugin();
    $authenticationPlugin->register($userAuth, 'user');
    $authenticationPlugin->register($apiAuth, 'api');
    $service = new RemoteStorageService($remoteStorage, new ApprovalManagementStorage($db), $templateManager, new RemoteStorageClientStorage(), new RemoteStorageResourceServer(), $approvalStorage, $authorizationCodeStorage, $accessTokenStorage, array('disable_token_endpoint' => true, 'disable_introspect_endpoint' => true, 'route_prefix' => '/_oauth', 'require_state' => false, 'server_mode' => $serverMode));
    $service->getPluginRegistry()->registerDefaultPlugin($authenticationPlugin);
    $response = $service->run($request);
    if ('development' === $serverMode && !$response->isOkay()) {
        error_log(var_export($response->toArray(), true));
    }
    $response->send();
} catch (Exception $e) {
    error_log($e->getMessage());
    die(sprintf('ERROR: %s', $e->getMessage()));
}