public function __construct(RemoteStorage $remoteStorage, ApprovalManagementStorage $approvalManagementStorage, TemplateManagerInterface $templateManager, ClientStorageInterface $clientStorage, ResourceServerStorageInterface $resourceServerStorage, ApprovalStorageInterface $approvalStorage, AuthorizationCodeStorageInterface $authorizationCodeStorage, AccessTokenStorageInterface $accessTokenStorage, array $options = array(), IO $io = null)
{
$this->remoteStorage = $remoteStorage;
$this->approvalManagementStorage = $approvalManagementStorage;
parent::__construct($templateManager, $clientStorage, $resourceServerStorage, $approvalStorage, $authorizationCodeStorage, $accessTokenStorage, $options, $io);
$this->get('/_account', function (Request $request, UserInfoInterface $userInfo) {
$approvalList = $this->approvalManagementStorage->getApprovalList($userInfo->getUserId());
return $this->templateManager->render('getAccountPage', array('approval_list' => $approvalList, 'host' => $request->getHeader('Host'), 'user_id' => $userInfo->getUserId(), 'disk_usage' => $this->remoteStorage->getFolderSize(new Path('/' . $userInfo->getUserId() . '/')), 'request_url' => $request->getUrl()->toString(), 'show_account_icon' => true));
}, array('fkooman\\Rest\\Plugin\\Authentication\\AuthenticationPlugin' => array('activate' => array('user'))));
$this->delete('/_approvals', function (Request $request, UserInfoInterface $userInfo) {
$deleteApprovalRequest = RequestValidation::validateDeleteApprovalRequest($request);
$approval = new Approval($userInfo->getUserId(), $deleteApprovalRequest['client_id'], $deleteApprovalRequest['response_type'], $deleteApprovalRequest['scope']);
$this->approvalManagementStorage->deleteApproval($approval);
return new RedirectResponse($request->getUrl()->getRootUrl() . '_account', 302);
}, array('fkooman\\Rest\\Plugin\\Authentication\\AuthenticationPlugin' => array('activate' => array('user'))));
$this->get('/.well-known/webfinger', function (Request $request) {
$resource = $request->getUrl()->getQueryParameter('resource');
if (null === $resource) {
throw new BadRequestException('resource parameter missing');
}
if (0 !== strpos($resource, 'acct:')) {
throw new BadRequestException('unsupported resource type');
}
$userAddress = substr($resource, 5);
$atPos = strpos($userAddress, '@');
if (false === $atPos) {
throw new BadRequestException('invalid user address');
}
$user = substr($userAddress, 0, $atPos);
$host = substr($userAddress, $atPos + 1);
//if($host !== $request->getUrl()->getHost()) {
// throw new BadRequestException(sprintf('host of webfinger resource does not match host of request %s', $host));
//}
$webFingerData = array('links' => array(array('href' => sprintf('%s%s', $request->getUrl()->getRootUrl(), $user), 'properties' => array('http://remotestorage.io/spec/version' => 'draft-dejong-remotestorage-05', 'http://remotestorage.io/spec/web-authoring' => null, 'http://tools.ietf.org/html/rfc6749#section-4.2' => sprintf('%s_oauth/authorize?login_hint=%s', $request->getUrl()->getRootUrl(), $user), 'http://tools.ietf.org/html/rfc6750#section-2.3' => null, 'http://tools.ietf.org/html/rfc7233' => 'development' !== $this->options['server_mode'] ? 'GET' : null), 'rel' => 'http://tools.ietf.org/id/draft-dejong-remotestorage'), array('href' => sprintf('%s%s', $request->getUrl()->getRootUrl(), $user), 'properties' => array('http://remotestorage.io/spec/version' => 'draft-dejong-remotestorage-03', 'http://tools.ietf.org/html/rfc2616#section-14.16' => 'development' !== $this->options['server_mode'] ? 'GET' : false, 'http://tools.ietf.org/html/rfc6749#section-4.2' => sprintf('%s_oauth/authorize?login_hint=%s', $request->getUrl()->getRootUrl(), $user), 'http://tools.ietf.org/html/rfc6750#section-2.3' => false), 'rel' => 'remotestorage')));
$response = new Response(200, 'application/jrd+json');
$response->setBody(Json::encode($webFingerData));
return $response;
}, array('fkooman\\Rest\\Plugin\\Authentication\\AuthenticationPlugin' => array('enabled' => false)));
$this->get('/', function (Request $request, UserInfoInterface $userInfo = null) {
return $this->templateManager->render('indexPage', array('user_id' => null !== $userInfo ? $userInfo->getUserId() : null, 'show_account_icon' => true));
}, array('fkooman\\Rest\\Plugin\\Authentication\\AuthenticationPlugin' => array('activate' => array('user'), 'require' => false)));
$this->addRoute(['GET', 'HEAD'], '*', function (Request $request, TokenInfo $tokenInfo = null) {
return $this->getObject($request, $tokenInfo);
}, array('fkooman\\Rest\\Plugin\\Authentication\\AuthenticationPlugin' => array('activate' => array('api'), 'require' => false)));
// put a document
$this->put('*', function (Request $request, TokenInfo $tokenInfo) {
return $this->putDocument($request, $tokenInfo);
}, array('fkooman\\Rest\\Plugin\\Authentication\\AuthenticationPlugin' => array('activate' => array('api')), 'fkooman\\Rest\\Plugin\\ReferrerCheck\\ReferrerCheckPlugin' => array('enabled' => false)));
// delete a document
$this->delete('*', function (Request $request, TokenInfo $tokenInfo) {
return $this->deleteDocument($request, $tokenInfo);
}, array('fkooman\\Rest\\Plugin\\Authentication\\AuthenticationPlugin' => array('activate' => array('api')), 'fkooman\\Rest\\Plugin\\ReferrerCheck\\ReferrerCheckPlugin' => array('enabled' => false)));
// options request
$this->options('*', function (Request $request) {
return $this->optionsRequest($request);
}, array('fkooman\\Rest\\Plugin\\Authentication\\AuthenticationPlugin' => array('enabled' => false)));
}