Removed older 2fa/oauth code in favour

of reworking
pull/4/head
AdamSBlack 2022-04-30 16:11:09 +01:00
parent 6f0b627a61
commit 0679c44b08
No known key found for this signature in database
GPG Key ID: E66E51A97D150E28
4 changed files with 0 additions and 121 deletions

View File

@ -1,70 +0,0 @@
import jsonwebtoken from 'jsonwebtoken';
import { AuthorizationCode } from 'simple-oauth2';
import log4js from 'log4js';
import { AUTH_OAUTH_ERR_GOOGLE, AUTH_OAUTH_ERR_GOOGLE_FAILED_TOKEN_FETCH } from '../../../consistency/terms';
const logger = log4js.getLogger();
const keys = {
web: {
client_id: '816666184056-n2cpdtsf2v9iiv81ro80cckl5f4oi4p8.apps.googleusercontent.com', project_id: 'glassy-tube-338505', auth_uri: 'https://accounts.google.com/o/oauth2/auth', token_uri: 'https://oauth2.googleapis.com/token', auth_provider_x509_cert_url: 'https://www.googleapis.com/oauth2/v1/certs', client_secret: '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', redirect_uris: ['http://localhost/authentication/oauth/callback'], javascript_origins: ['http://localhost'],
},
};
const config = {
client: {
id: keys.web.client_id,
secret: keys.web.client_secret,
},
auth: {
// token server
tokenHost: 'https://oauth2.googleapis.com',
tokenPath: '/token',
// authorization server
authorizeHost: 'https://accounts.google.com',
authorizePath: '/o/oauth2/v2/auth',
},
};
export async function getToken(code, scope) {
const client = new AuthorizationCode(config);
const tokenParams = {
code,
redirect_uri: 'http://localhost/authentication/oauth/callback',
scope,
};
let accessToken;
try {
accessToken = await client.getToken(tokenParams);
} catch (error) {
logger.warn(AUTH_OAUTH_ERR_GOOGLE, AUTH_OAUTH_ERR_GOOGLE_FAILED_TOKEN_FETCH, error);
return { error: true, ...AUTH_OAUTH_ERR_GOOGLE_FAILED_TOKEN_FETCH };
}
logger.info(`accessToken: ${accessToken}`);
const id = jsonwebtoken.decode(accessToken.token.id_token);
logger.info(`jsonwebtoken.${id}`);
return id;
}
export async function getURL() {
const client = new AuthorizationCode(config);
return client.authorizeURL({
redirect_uri: 'http://localhost/authentication/oauth/callback',
scope: 'https://www.googleapis.com/auth/userinfo.email',
state: 'ada',
});
}
export default {
getToken,
getURL,
};

View File

@ -1 +0,0 @@
// empty

View File

@ -1,39 +0,0 @@
import express from 'express';
import log4js from 'log4js';
import { getURL, getToken } from '../../../controllers/authentication/oauth/google';
import { requireAuthenticated } from '../../../middlewares/authentication';
const router = express.Router();
const logger = log4js.getLogger();
router.get('/authentication/oauth/callback', async (req, res) => {
logger.info(req.query);
res.json(await getToken(req.query.code, req.query.scope));
});
router.get('/authentication/oauth/:provider', async (req, res) => {
const { provider } = req.params;
logger.info('provider', provider);
let url;
switch (provider) {
case 'google':
url = await getURL();
break;
default:
url = false;
break;
}
if (url) {
res.redirect(url);
} else {
res.json({ error: true, msg: 'Invalid provider' });
}
});
router.get('/authentication/oauth/pair/:provider', requireAuthenticated, async (req, res) => {
res.status(200);
});
export default router;

View File

@ -1,11 +0,0 @@
import express from 'express';
import { requireAuthenticated } from '../../../middlewares/authentication';
const router = express.Router();
router.get('/authentication/twofactor/enrol', requireAuthenticated, async () => {
// TODO: implementation
});
export default router;