diff --git a/src/server/controllers/authentication/oauth/google.js b/src/server/controllers/authentication/oauth/google.js deleted file mode 100644 index f301ba7..0000000 --- a/src/server/controllers/authentication/oauth/google.js +++ /dev/null @@ -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, -}; diff --git a/src/server/controllers/authentication/oauth/index.js b/src/server/controllers/authentication/oauth/index.js deleted file mode 100644 index 8b1a393..0000000 --- a/src/server/controllers/authentication/oauth/index.js +++ /dev/null @@ -1 +0,0 @@ -// empty diff --git a/src/server/router/api/auth/oauth.js b/src/server/router/api/auth/oauth.js deleted file mode 100644 index d7e1bbd..0000000 --- a/src/server/router/api/auth/oauth.js +++ /dev/null @@ -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; diff --git a/src/server/router/api/auth/twofactor.js b/src/server/router/api/auth/twofactor.js deleted file mode 100644 index 99d531f..0000000 --- a/src/server/router/api/auth/twofactor.js +++ /dev/null @@ -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;