外部检测用户自己的云会话



我有两个网站在同一台服务器上运行,第一个是owncloud服务器,第二个是从头开始构建的网站。第二个站点仅供当前登录到自己的云帐户的用户访问,但我正在努力让公共库为我工作。到目前为止,我所拥有的。

<?php
require_once '/var/www/owncloud9/html/lib/base.php';
require_once '/var/www/owncloud9/html/lib/public/user.php';
if ( OCPUser::isLoggedIn() )
echo( "Hi ".OCPUser::getDisplayName()."n" );
else
echo( "You are not logged in.n");
?>

结果始终是"您未登录",即使情况并非如此。如何让第二个站点检测用户自己的云会话?

您必须添加一些注释,例如在 https://github.com/pbek/qownnotesapi/blob/develop/controller/noteapicontroller.php 中。

/**
* Returns information about the ownCloud server
*
* @NoAdminRequired
* @NoCSRFRequired
* @CORS
*
* @return string
*/
public function getAppInfo() {
$appManager = OC::$server->getAppManager();
$versionsAppEnabled = $appManager->isEnabledForUser('files_versions');
$trashAppEnabled = $appManager->isEnabledForUser('files_trashbin');
$notesPathExists = false;
$notesPath = $this->request->getParam( "notes_path", "" );
// check if notes path exists
if ($notesPath !== "")
{
$notesPath = "/files" . (string)$notesPath;
$view = new OCFilesView('/' . $this->user);
$notesPathExists = $view->is_dir($notesPath);
}
return [
"versions_app" => $versionsAppEnabled,
"trash_app" => $trashAppEnabled,
"versioning" => true,
"app_version" => OC::$server->getConfig()->getAppValue('qownnotesapi', 'installed_version'),
"server_version" => OC::$server->getSystemConfig()->getValue('version'),
"notes_path_exists" => $notesPathExists,
];
}

@NoAdminRequired@NoCSRFRequired上面的注释中,该方法将关闭安全检查。 (见:https://doc.owncloud.org/server/9.0/developer_manual/app/tutorial.html)

如果您现在使用简单的身份验证提出请求,它应该可以工作。 示例:https://user:password@your-server/path/to/your/controller

例如,我在OwnCloudService::checkAppInfoat https://github.com/pbek/QOwnNotes/blob/develop/src/services/owncloudservice.cpp#L322

最新更新