mirror of
https://github.com/YunoHost-Apps/outline_ynh.git
synced 2024-09-03 19:56:12 +02:00
69 lines
2 KiB
Diff
69 lines
2 KiB
Diff
diff --git a/server/routes/auth/providers/req.ts b/server/routes/auth/providers/req.ts
|
|
index e69de29b..22beba6e 100644
|
|
--- a/server/routes/auth/providers/req.ts
|
|
+++ b/server/routes/auth/providers/req.ts
|
|
@@ -0,0 +1,64 @@
|
|
+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 { getAllowedDomains } from "@server/utils/authentication";
|
|
+import { StateStore } from "@server/utils/passport";
|
|
+
|
|
+const router = new Router();
|
|
+const providerName = "req";
|
|
+const allowedDomains = getAllowedDomains();
|
|
+
|
|
+export const config = {
|
|
+ name: "Visitor",
|
|
+ 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;
|