2022-09-10 18:17:17 +02:00
|
|
|
diff --git a/server/routes/auth/providers/req.ts b/server/routes/auth/providers/req.ts
|
|
|
|
new file mode 100644
|
2022-09-16 17:59:46 +02:00
|
|
|
index 00000000..1c954d24
|
2022-09-10 18:17:17 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/server/routes/auth/providers/req.ts
|
2022-09-10 19:35:52 +02:00
|
|
|
@@ -0,0 +1,62 @@
|
2022-09-10 18:17:17 +02:00
|
|
|
+import passport from "@outlinewiki/koa-passport";
|
|
|
|
+import Router from "koa-router";
|
|
|
|
+import { capitalize } from "lodash";
|
|
|
|
+import { Strategy as ReqStrategy } from "passport-req";
|
|
|
|
+import accountProvisioner from "@server/commands/accountProvisioner";
|
|
|
|
+import env from "@server/env";
|
|
|
|
+import passportMiddleware from "@server/middlewares/passport";
|
|
|
|
+import { StateStore } from "@server/utils/passport";
|
|
|
|
+
|
|
|
|
+const router = new Router();
|
|
|
|
+const providerName = "req";
|
|
|
|
+
|
|
|
|
+export const config = {
|
2022-09-16 17:59:46 +02:00
|
|
|
+ name: "visiteur",
|
2022-09-10 18:17:17 +02:00
|
|
|
+ enabled: true,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+if (true) {
|
|
|
|
+ passport.use(
|
|
|
|
+ new ReqStrategy(
|
|
|
|
+ async function (req,done) {
|
|
|
|
+ try {
|
|
|
|
+ const domain = "domain.tld";
|
|
|
|
+ const subdomain = domain.split(".")[0];
|
|
|
|
+ const teamName = capitalize(subdomain);
|
|
|
|
+ const name = "Visitor";
|
|
|
|
+ const email = "visitor@domain.tld";
|
|
|
|
+ const result = await accountProvisioner({
|
|
|
|
+ ip: req.ip,
|
|
|
|
+ team: {
|
|
|
|
+ name: teamName,
|
|
|
|
+ domain,
|
|
|
|
+ subdomain,
|
|
|
|
+ },
|
|
|
|
+ user: {
|
|
|
|
+ name: name,
|
|
|
|
+ email: email,
|
|
|
|
+ avatarUrl: null,
|
|
|
|
+ },
|
|
|
|
+ authenticationProvider: {
|
|
|
|
+ name: providerName,
|
|
|
|
+ providerId: domain,
|
|
|
|
+ },
|
|
|
|
+ authentication: {
|
|
|
|
+ providerId: "1234",
|
|
|
|
+ accessToken: null,
|
|
|
|
+ refreshToken: null,
|
|
|
|
+ scopes: [],
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ return done(null, result.user, result);
|
|
|
|
+ } catch (err) {
|
|
|
|
+ return done(err, null);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ )
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ router.get("req", passportMiddleware(providerName));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export default router;
|
|
|
|
diff --git a/yarn.lock b/yarn.lock
|
2022-09-10 19:03:42 +02:00
|
|
|
index 0bc83b9b..06e1b385 100644
|
2022-09-10 18:17:17 +02:00
|
|
|
--- a/yarn.lock
|
|
|
|
+++ b/yarn.lock
|
2022-09-10 19:03:42 +02:00
|
|
|
@@ -11790,6 +11790,14 @@ passport-oauth@1.0.x:
|
2022-09-10 18:17:17 +02:00
|
|
|
passport-oauth1 "1.x.x"
|
|
|
|
passport-oauth2 "1.x.x"
|
|
|
|
|
|
|
|
+passport-req@^0.1.1:
|
|
|
|
+ version "0.1.1"
|
2022-09-10 19:03:42 +02:00
|
|
|
+ resolved "https://registry.yarnpkg.com/passport-req/-/passport-req-0.1.1.tgz#451bff1500b3d464a768d42f0762328a21236a18"
|
2022-09-10 18:17:17 +02:00
|
|
|
+ integrity sha1-RRv/FQCz1GSnaNQvB2IyiiEjahg=
|
|
|
|
+ dependencies:
|
|
|
|
+ passport "~0.1.1"
|
|
|
|
+ pkginfo "0.2.x"
|
|
|
|
+
|
|
|
|
passport-slack-oauth2@^1.1.1:
|
|
|
|
version "1.1.1"
|
|
|
|
resolved "https://registry.yarnpkg.com/passport-slack-oauth2/-/passport-slack-oauth2-1.1.1.tgz#d831ffc3f1e968fcc3622e6ecf41643c8d8f9cbc"
|
|
|
|
diff --git a/package.json b/package.json
|
|
|
|
index ff45e246..a5837c23 100644
|
|
|
|
--- a/package.json
|
|
|
|
+++ b/package.json
|
|
|
|
@@ -144,6 +144,7 @@
|
|
|
|
"passport": "^0.6.0",
|
|
|
|
"passport-google-oauth2": "^0.2.0",
|
|
|
|
"passport-oauth2": "^1.6.1",
|
|
|
|
+ "passport-req": "^0.1.1",
|
|
|
|
"passport-slack-oauth2": "^1.1.1",
|
|
|
|
"pg": "^8.5.1",
|
|
|
|
"pg-hstore": "^2.3.4",
|