摘要:基础环境安装在官方应用商店下载解压并拷贝至目录打开并在应用中启用配置使用管理员账号打开找到设置,选择并添加信息,如下设置只使用登录,取消系统登录编辑添加以下配置使用注销使用中发现点击登出后,只是注销了本身的,并没有注销的,因此会登出失败打开
基础环境
Nextcloud 15.0.5
oauth2
安装 sociallogin在官方app应用商店下载 sociallogin
解压并拷贝 sociallogin 至 app 目录
打开 Nextcloud 并在 应用中启用
配置oauth2使用管理员账号打开 Nextcloud 找到 sociallogin设置,选择 Custom OAuth2 并添加oauth2信息,如下
设置只使用oauth2登录,取消系统登录
编辑 /var/www/html/config/config.php 添加以下配置:
"social_login_auto_redirect" => true使用Oauth2注销 Nextcloud
使用中发现点击登出后,Nextcloud只是注销了本身的session,并没有注销oauth2的session,因此会登出失败.
打开 core/Controller/LoginController.php 找到 logout 方法,修改 $response 值如下:
$response = new RedirectResponse("http://10.0.4.3/logout?redirect_uri=http://10.0.4.33:8088");
http://10.0.4.3/logout 为oauth2认证系统登出地址
使用用户信息创建组在使用oauth2登录成功后,为了与原有Nextcloud用户区分,Nextcloud会在数据库中创建一个用户名为 oauth2 Internal name + 登录名称的用户,这样使用起来及其不方便,我们可以通过修改以下代码,保证用户名正常不带前缀:
根据返回用户信息中其他信息创建组
sociallogin/lib/Controller/LoginController.php
private function login($uid, Profile $profile)
{
$user = $this->userManager->get($uid);
if (null === $user) {
$connectedUid = $this->socialConnect->findUID($uid);
$user = $this->userManager->get($connectedUid);
}
if ($this->userSession->isLoggedIn()) {
if (!$this->config->getAppValue($this->appName, "allow_login_connect")) {
throw new LoginException($this->l->t("Social login connect is disabled"));
}
if (null !== $user) {
throw new LoginException($this->l->t("This account already connected"));
}
$currentUid = $this->userSession->getUser()->getUID();
$this->socialConnect->connectLogin($currentUid, $uid);
return new RedirectResponse($this->urlGenerator->linkToRoute("settings.PersonalSettings.index", ["section" => "additional"]));
}
if (null === $user) {
if ($this->config->getAppValue($this->appName, "disable_registration")) {
throw new LoginException($this->l->t("Auto creating new users is disabled"));
}
if (
$profile->email && $this->config->getAppValue($this->appName, "prevent_create_email_exists")
&& count($this->userManager->getByEmail($profile->email)) !== 0
) {
throw new LoginException($this->l->t("Email already registered"));
}
$password = substr(base64_encode(random_bytes(64)), 0, 30);
$user = $this->userManager->createUser($uid, $password);
$user->setDisplayName($profile->displayName ?: $profile->identifier);
$user->setEMailAddress((string)$profile->email);
$newUserGroup = $this->config->getAppValue($this->appName, "new_user_group");
if ($newUserGroup) {
try {
$group = $this->groupManager->get($newUserGroup);
$group->addUser($user);
} catch (Exception $e) {
}
}
if ($profile->photoURL) {
$curl = new Curl();
try {
$photo = $curl->request($profile->photoURL);
$avatar = $this->avatarManager->getAvatar($uid);
$avatar->set($photo);
} catch (Exception $e) {
}
}
$this->config->setUserValue($uid, $this->appName, "disable_password_confirmation", 1);
if ($profile->data["departmentName"] !== null) {
$existGroup = $this->groupManager->get($profile->data["departmentName"]);
if ($existGroup === null) {
$newGroup = $this->groupManager->createGroup($profile->data["departmentName"]);
$newGroup->addUser($user);
} else {
$existGroup->addUser($user);
}
}
}
$this->userSession->completeLogin($user, ["loginName" => $user->getUID(), "password" => null]);
$this->userSession->createSessionToken($this->request, $user->getUID(), $user->getUID());
if ($redirectUrl = $this->session->get("login_redirect_url")) {
return new RedirectResponse($redirectUrl);
}
$this->session->set("last-password-confirm", time());
return new RedirectResponse($this->urlGenerator->getAbsoluteURL("/"));
}
sociallogin/lib/Provider/CustomOAuth2.php
public function getUserProfile()
{
$profileFields = array_filter(
array_map("trim", explode(",", $this->config->get("profile_fields"))),
function ($val) {
return !empty($val);
}
);
$profileUrl = $this->config->get("endpoints")->get("profile_url");
if (count($profileFields) > 0) {
$profileUrl .= (strpos($profileUrl, "?") !== false ? "&" : "?") . "fields=" . implode(",", $profileFields);
}
$response = $this->apiRequest($profileUrl);
if (!isset($response->identifier) && isset($response->id)) {
$response->identifier = $response->id;
}
if (!isset($response->identifier) && isset($response->data->id)) {
$response->identifier = $response->data->id;
}
if (!isset($response->identifier) && isset($response->user_id)) {
$response->identifier = $response->user_id;
}
$data = new DataCollection($response);
if (!$data->exists("identifier")) {
throw new UnexpectedApiResponseException("Provider API returned an unexpected response.");
}
$userProfile = new UserProfile();
foreach ($data->toArray() as $key => $value) {
if (property_exists($userProfile, $key)) {
$userProfile->$key = $value;
}
}
if (!empty($userProfile->email)) {
$userProfile->emailVerified = $userProfile->email;
}
$attributes = new DataCollection($data->get("attributes"));
$userProfile->data = [
"organizationName" => $attributes->get("organizationName"),
"departmentName" => $attributes->get("departmentName"),
];
if ($attributes->get("name") !== null) {
$userProfile->displayName = $attributes->get("name");
}
return $userProfile;
}
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/31153.html
摘要:它的客户端覆盖了等各种平台,也提供了网页端以及接口,所以你几乎可以在各种设备上方便地访问你的云盘。【简介】 1.Azure Virtual machines是Azure 提供的多种可缩放按需分配计算资源之一,Nextcloud是一款开源免费的私有云存储网盘项目,可以让你快速便捷地搭建一套属于自己或团队的云同步网盘,从而实现跨平台跨设备文件同步、共享、版本控制、团队协作等功能。它的客...
摘要:总的来说,适用于个人搭建家庭网盘,也适合大家公司内部私有云网盘。支持显示消息状态指示器举手功能群组对话说明可折叠的视频栏全屏屏幕共享。。参与维护万的开源技术资源库,包括等。 ...
搭建个人云存储一般会想到ownCloud,堪称是自建云存储服务的经典。而Nextcloud是ownCloud原开发团队打造的号称是下一代存储。初一看觉得口气不小,刚推出来就重新定义了Cloud,真正试用过后就由衷地赞同这个Nextcloud:它是个人云存储服务的绝佳选择。 与ownCloud相比,Nextcloud的功能丝毫没有减弱,甚至由于可以安装云存储服务应用,自制性更强,也更符合用户的...
一、Nextcloud简介Nextcloud是一款开源免费的私有云存储网盘项目,可以让你快速便捷地搭建一套属于自己或团队的云同步网盘,从而实现跨平台跨设备文件同步、共享、版本控制、团队协作等功能。它的客户端覆盖了Windows、Mac、Android、iOS、Linux 等各种平台,也提供了网页端以及 WebDAV接口,所以你几乎可以在各种设备上方便地访问你的云盘。官网地址:https://nex...
阅读 5431·2021-11-15 11:39
阅读 2917·2021-11-11 16:55
阅读 2392·2021-10-25 09:44
阅读 3716·2021-09-22 16:02
阅读 2671·2019-08-30 15:55
阅读 3260·2019-08-30 13:46
阅读 2956·2019-08-30 13:15
阅读 2155·2019-08-30 11:12