moved oauth controller endpoints to auth

This commit is contained in:
Sheen Capadngan
2023-05-24 23:44:30 +08:00
parent 93cf7cde2d
commit fac4968193
11 changed files with 25 additions and 37 deletions
@@ -267,3 +267,7 @@ export const getNewToken = async (req: Request, res: Response) => {
}); });
} }
}; };
export const handleAuthProviderCallback = (req: Request, res: Response) => {
res.redirect(`/login/provider/success?token=${encodeURIComponent(req.providerAuthToken)}`);
}
-2
View File
@@ -5,7 +5,6 @@ import * as integrationController from './integrationController';
import * as keyController from './keyController'; import * as keyController from './keyController';
import * as membershipController from './membershipController'; import * as membershipController from './membershipController';
import * as membershipOrgController from './membershipOrgController'; import * as membershipOrgController from './membershipOrgController';
import * as oauthController from './oauthController';
import * as organizationController from './organizationController'; import * as organizationController from './organizationController';
import * as passwordController from './passwordController'; import * as passwordController from './passwordController';
import * as secretController from './secretController'; import * as secretController from './secretController';
@@ -24,7 +23,6 @@ export {
keyController, keyController,
membershipController, membershipController,
membershipOrgController, membershipOrgController,
oauthController,
organizationController, organizationController,
passwordController, passwordController,
secretController, secretController,
@@ -1,5 +0,0 @@
import { Request, Response } from 'express';
export const handleAuthProviderCallback = (req: Request, res: Response) => {
res.redirect(`/login/provider/success?token=${encodeURIComponent(req.providerAuthToken)}`);
}
-2
View File
@@ -39,7 +39,6 @@ import {
membership as v1MembershipRouter, membership as v1MembershipRouter,
key as v1KeyRouter, key as v1KeyRouter,
inviteOrg as v1InviteOrgRouter, inviteOrg as v1InviteOrgRouter,
oauth as v1OAuth,
user as v1UserRouter, user as v1UserRouter,
userAction as v1UserActionRouter, userAction as v1UserActionRouter,
secret as v1SecretRouter, secret as v1SecretRouter,
@@ -135,7 +134,6 @@ const main = async () => {
// v1 routes (default) // v1 routes (default)
app.use("/api/v1/signup", v1SignupRouter); app.use("/api/v1/signup", v1SignupRouter);
app.use("/api/v1/auth", v1AuthRouter); app.use("/api/v1/auth", v1AuthRouter);
app.use("/api/v1/oauth", v1OAuth);
app.use("/api/v1/bot", v1BotRouter); app.use("/api/v1/bot", v1BotRouter);
app.use("/api/v1/user", v1UserRouter); app.use("/api/v1/user", v1UserRouter);
app.use("/api/v1/user-action", v1UserActionRouter); app.use("/api/v1/user-action", v1UserActionRouter);
+17
View File
@@ -1,6 +1,7 @@
import express from 'express'; import express from 'express';
const router = express.Router(); const router = express.Router();
import { body } from 'express-validator'; import { body } from 'express-validator';
import passport from 'passport';
import { requireAuth, validateRequest } from '../../middleware'; import { requireAuth, validateRequest } from '../../middleware';
import { authController } from '../../controllers/v1'; import { authController } from '../../controllers/v1';
import { authLimiter } from '../../helpers/rateLimiter'; import { authLimiter } from '../../helpers/rateLimiter';
@@ -44,4 +45,20 @@ router.post(
); );
router.get(
'/redirect/google',
authLimiter,
passport.authenticate('google', {
scope: ['profile', 'email'],
session: false,
}),
)
router.get(
'/callback/google',
passport.authenticate('google', { failureRedirect: '/login/provider/error', session: false }),
authController.handleAuthProviderCallback,
)
export default router; export default router;
-2
View File
@@ -16,7 +16,6 @@ import stripe from './stripe';
import integration from './integration'; import integration from './integration';
import integrationAuth from './integrationAuth'; import integrationAuth from './integrationAuth';
import secretsFolder from './secretsFolder'; import secretsFolder from './secretsFolder';
import oauth from './oauth';
export { export {
signup, signup,
@@ -30,7 +29,6 @@ export {
membership, membership,
key, key,
inviteOrg, inviteOrg,
oauth,
secret, secret,
serviceToken, serviceToken,
password, password,
-22
View File
@@ -1,22 +0,0 @@
import express from 'express';
const router = express.Router();
import passport from 'passport';
import { oauthController } from '../../controllers/v1';
import { authLimiter } from '../../helpers/rateLimiter';
router.get(
'/redirect/google',
authLimiter,
passport.authenticate('google', {
scope: ['profile', 'email'],
session: false,
}),
)
router.get(
'/callback/google',
passport.authenticate('google', { failureRedirect: '/login/provider/error', session: false }),
oauthController.handleAuthProviderCallback,
)
export default router;
+1 -1
View File
@@ -68,7 +68,7 @@ const initializePassport = async () => {
passReqToCallback: true, passReqToCallback: true,
clientID: googleClientId, clientID: googleClientId,
clientSecret: googleClientSecret, clientSecret: googleClientSecret,
callbackURL: '/api/v1/oauth/callback/google', callbackURL: '/api/v1/auth/callback/google',
scope: ['profile', ' email'], scope: ['profile', ' email'],
}, async ( }, async (
req: express.Request, req: express.Request,
+1 -1
View File
@@ -6,7 +6,7 @@ To enable Google Auth for your Infisical project, you first need to set up a Goo
Follow Google's Setting up OAuth 2.0 documentation [here](https://support.google.com/googleapi/answer/6158849). After the setup, copy the Client ID and Client secret. You will need them below. Follow Google's Setting up OAuth 2.0 documentation [here](https://support.google.com/googleapi/answer/6158849). After the setup, copy the Client ID and Client secret. You will need them below.
## Configure Redirect URI ## Configure Redirect URI
Add the following URI to the Authorized redirect URIs section in the OAuth Client credentials page - `BASE_URL/api/v1/oauth/callback/google`. Replace BASE_URL with the URL of your hosted Infisical instance. Add the following URI to the Authorized redirect URIs section in the OAuth Client credentials page - `BASE_URL/api/v1/auth/callback/google`. Replace BASE_URL with the URL of your hosted Infisical instance.
![google redirect](../../images/authentication-google-redirect.png) ![google redirect](../../images/authentication-google-redirect.png)
## General Configuration ## General Configuration
@@ -20,7 +20,7 @@ export default function InitialLoginStep({
colorSchema="primary" colorSchema="primary"
variant="solid" variant="solid"
onClick={() => { onClick={() => {
window.open('/api/v1/oauth/redirect/google') window.open('/api/v1/auth/redirect/google')
}} }}
leftIcon={<FontAwesomeIcon icon={faGoogle} className="mr-1" />} leftIcon={<FontAwesomeIcon icon={faGoogle} className="mr-1" />}
className="h-14 w-full mx-0" className="h-14 w-full mx-0"
@@ -19,7 +19,7 @@ export default function InitialSignupStep({
colorSchema="primary" colorSchema="primary"
variant="solid" variant="solid"
onClick={() => { onClick={() => {
window.open('/api/v1/oauth/redirect/google') window.open('/api/v1/auth/redirect/google')
}} }}
leftIcon={<FontAwesomeIcon icon={faGoogle} className="mr-1" />} leftIcon={<FontAwesomeIcon icon={faGoogle} className="mr-1" />}
className="h-14 w-full mx-0" className="h-14 w-full mx-0"