addition of new dashboard
This commit is contained in:
46
backend/modules/auth/github.js
Normal file
46
backend/modules/auth/github.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import GitHubStrategy from "passport-github";
|
||||
import { checkUser } from "../../http/auth.js";
|
||||
import { getConfig } from "../../common/config.js";
|
||||
|
||||
const key = 'github';
|
||||
|
||||
export function getModuleConfig() {
|
||||
const config = getConfig();
|
||||
return {
|
||||
title: 'GitHub',
|
||||
icon: 'code',
|
||||
clientID: process.env.GITHUB_CLIENT_ID,
|
||||
clientSecret: process.env.GITHUB_CLIENT_SECRET,
|
||||
callbackURL: `${config.publicCallbackUrl}/callback/${key}`,
|
||||
}
|
||||
}
|
||||
|
||||
export async function initModule(app, passport) {
|
||||
const config = getConfig();
|
||||
|
||||
passport.use(new GitHubStrategy(
|
||||
config.authModules[key],
|
||||
function (accessToken, refreshToken, profile, cb) {
|
||||
(async () => {
|
||||
try {
|
||||
const user = await checkUser(key, 'https://github.com', profile.id, profile.username);
|
||||
return cb(null, user);
|
||||
} catch (e) {
|
||||
if (config.debug)
|
||||
console.error(e);
|
||||
return cb(null, null);
|
||||
}
|
||||
})();
|
||||
}
|
||||
));
|
||||
app.get(`/login/${key}`, passport.authenticate('github'));
|
||||
app.get(`/callback/${key}`,
|
||||
passport.authenticate('github', {
|
||||
failureRedirect: '/',
|
||||
failureMessage: true
|
||||
}),
|
||||
function (req, res) {
|
||||
res.redirect('/home');
|
||||
}
|
||||
);
|
||||
}
|
||||
46
backend/modules/auth/google.js
Normal file
46
backend/modules/auth/google.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import GoogleStrategy from "passport-google-oauth20";
|
||||
import { checkUser } from "../../http/auth.js";
|
||||
import { getConfig } from "../../common/config.js";
|
||||
|
||||
const key = 'google';
|
||||
|
||||
export function getModuleConfig() {
|
||||
const config = getConfig();
|
||||
return {
|
||||
title: 'Google',
|
||||
icon: 'language',
|
||||
clientID: process.env.GOOGLE_CLIENT_ID,
|
||||
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
||||
callbackURL: `${config.publicCallbackUrl}/callback/${key}`,
|
||||
}
|
||||
}
|
||||
|
||||
export async function initModule(app, passport) {
|
||||
const config = getConfig();
|
||||
passport.use(new GoogleStrategy.Strategy(
|
||||
config.authModules[key],
|
||||
function (accessToken, refreshToken, profile, cb) {
|
||||
(async () => {
|
||||
try {
|
||||
const photo = profile.photos?.length > 0 ? profile.photos[0].value : null;
|
||||
const user = await checkUser(key, 'https://google.com', profile.id, profile.displayName, photo);
|
||||
return cb(null, user);
|
||||
} catch (e) {
|
||||
if (config.debug)
|
||||
console.error(e);
|
||||
return cb(null, null);
|
||||
}
|
||||
})();
|
||||
}
|
||||
));
|
||||
app.get(`/login/${key}`, passport.authenticate('google', { scope: ['profile'] }));
|
||||
app.get(`/callback/${key}`,
|
||||
passport.authenticate('google', {
|
||||
failureRedirect: '/',
|
||||
failureMessage: true
|
||||
}),
|
||||
function (req, res) {
|
||||
res.redirect('/home');
|
||||
}
|
||||
);
|
||||
}
|
||||
52
backend/modules/auth/oidc.js
Normal file
52
backend/modules/auth/oidc.js
Normal file
@@ -0,0 +1,52 @@
|
||||
import OpenIDConnectStrategy from "passport-openidconnect";
|
||||
import { checkUser } from "../../http/auth.js";
|
||||
import { getConfig } from "../../common/config.js";
|
||||
|
||||
const key = 'oidc';
|
||||
|
||||
export function getModuleConfig() {
|
||||
const config = getConfig();
|
||||
return {
|
||||
title: 'FedID',
|
||||
icon: 'login',
|
||||
issuer: process.env.OIDC_ISSUER,
|
||||
authorizationURL: process.env.OIDC_AUTHORIZATION_URL,
|
||||
tokenURL: process.env.OIDC_TOKEN_URL,
|
||||
userInfoURL: process.env.OIDC_USERINFO_URL,
|
||||
logoutURL: process.env.OIDC_LOGOUT_URL,
|
||||
clientID: process.env.OIDC_CLIENT_ID,
|
||||
clientSecret: process.env.OIDC_CLIENT_SECRET,
|
||||
callbackURL: `${config.publicCallbackUrl}/callback/${key}`,
|
||||
}
|
||||
}
|
||||
|
||||
export async function initModule(app, passport) {
|
||||
const config = getConfig();
|
||||
|
||||
passport.use(new OpenIDConnectStrategy(
|
||||
config.authModules[key],
|
||||
function verify(issuer, profile, cb) {
|
||||
(async () => {
|
||||
try {
|
||||
const user = await checkUser(key, issuer, profile.id, profile.username);
|
||||
return cb(null, user);
|
||||
} catch (e) {
|
||||
if (config.debug)
|
||||
console.error(e);
|
||||
return cb(null, null);
|
||||
}
|
||||
})();
|
||||
}
|
||||
));
|
||||
app.get(`/login/${key}`,passport.authenticate('openidconnect'));
|
||||
app.get(`/callback/${key}`,
|
||||
passport.authenticate('openidconnect', {
|
||||
failureRedirect: '/',
|
||||
failureMessage: true
|
||||
}),
|
||||
function (req, res) {
|
||||
req.session.authStrategy = 'oidc';
|
||||
res.redirect('/home');
|
||||
}
|
||||
);
|
||||
}
|
||||
18
backend/modules/auth/single.js
Normal file
18
backend/modules/auth/single.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import { checkUser } from "../../http/auth.js";
|
||||
import { getConfig } from "../../common/config.js";
|
||||
|
||||
const key = 'single';
|
||||
|
||||
export function getModuleConfig() {
|
||||
const config = getConfig();
|
||||
return {
|
||||
core: process.env.SINGLE_API_KEY_CORE,
|
||||
archive: process.env.SINGLE_API_KEY_ARCHIVE,
|
||||
}
|
||||
}
|
||||
|
||||
export async function initModule(app, passport) {
|
||||
if (process.env.SINGLE_API_KEY_CORE && process.env.SINGLE_API_KEY_ARCHIVE) {
|
||||
await checkUser(key, 'https://single', 'single', 'single');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user