From e26b40f3899efe1dccd1ad218f52b99decce198d Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Tue, 7 Jan 2020 15:44:06 +0100 Subject: [PATCH] add nextcloud auth --- package.json | 1 + .../nextcloud/authentication.js | 36 +++++++++++++++++++ .../authentication/nextcloud/definition.yml | 25 +++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 server/modules/authentication/nextcloud/authentication.js create mode 100644 server/modules/authentication/nextcloud/definition.yml diff --git a/package.json b/package.json index c4ce2a63..b78ef485 100644 --- a/package.json +++ b/package.json @@ -137,6 +137,7 @@ "passport-ldapauth": "2.1.4", "passport-local": "1.0.0", "passport-microsoft": "0.0.5", + "passport-nextcloud": "0.1.1", "passport-oauth2": "1.5.0", "passport-okta-oauth": "0.0.1", "passport-openidconnect": "0.0.2", diff --git a/server/modules/authentication/nextcloud/authentication.js b/server/modules/authentication/nextcloud/authentication.js new file mode 100644 index 00000000..0b58a78d --- /dev/null +++ b/server/modules/authentication/nextcloud/authentication.js @@ -0,0 +1,36 @@ +/* global WIKI */ + +// ------------------------------------ +// Nextcloud Account +// ------------------------------------ + +const NextcloudStrategy = require('passport-nextcloud').Strategy +const _ = require('lodash') + +module.exports = { + init (passport, conf) { + passport.use('nextcloud', + new NextcloudStrategy({ + clientID: conf.clientId, + clientSecret: conf.clientSecret, + callbackURL: conf.callbackURL, + baseURL: conf.baseUrl, + scope: ['read_user'] + }, async (accessToken, refreshToken, profile, cb) => { + try { + const user = await WIKI.models.users.processProfile({ + profile: { + ...profile, + // not available from nextcloud so far + picture: '' + }, + providerKey: 'nextcloud' + }) + cb(null, user) + } catch (err) { + cb(err, null) + } + } + )) + } +} diff --git a/server/modules/authentication/nextcloud/definition.yml b/server/modules/authentication/nextcloud/definition.yml new file mode 100644 index 00000000..30a136ed --- /dev/null +++ b/server/modules/authentication/nextcloud/definition.yml @@ -0,0 +1,25 @@ +key: nextcloud +title: Nextcloud +description: Nextcloud is a suite of client-server software for creating and using file hosting services. +author: requarks.io +logo: https://static.requarks.io/logo/nextcloud.svg +color: blue darken-1 +website: https://nextcloud.com +isAvailable: true +useForm: false +props: + clientId: + type: String + title: Client ID + hint: Application Client ID + order: 1 + clientSecret: + type: String + title: Client Secret + hint: Application Client Secret + order: 2 + baseUrl: + type: String + title: Base URL + hint: Define the base URL (e.g. https://nextcloud.example.com). + order: 3 -- 2.18.1