89 lines
2.5 KiB
JavaScript
89 lines
2.5 KiB
JavaScript
const Router = require("@koa/router")
|
|
const authController = require("../../controllers/global/auth")
|
|
const { joiValidator } = require("@budibase/backend-core/auth")
|
|
const Joi = require("joi")
|
|
|
|
const router = new Router()
|
|
|
|
function buildAuthValidation() {
|
|
// prettier-ignore
|
|
return joiValidator.body(Joi.object({
|
|
username: Joi.string().required(),
|
|
password: Joi.string().required(),
|
|
}).required().unknown(false))
|
|
}
|
|
|
|
function buildResetValidation() {
|
|
// prettier-ignore
|
|
return joiValidator.body(Joi.object({
|
|
email: Joi.string().required(),
|
|
}).required().unknown(false))
|
|
}
|
|
|
|
function buildResetUpdateValidation() {
|
|
// prettier-ignore
|
|
return joiValidator.body(Joi.object({
|
|
resetCode: Joi.string().required(),
|
|
password: Joi.string().required(),
|
|
}).required().unknown(false))
|
|
}
|
|
|
|
router
|
|
// PASSWORD
|
|
.post(
|
|
"/api/global/auth/:tenantId/login",
|
|
buildAuthValidation(),
|
|
authController.authenticate
|
|
)
|
|
.post("/api/global/auth/logout", authController.logout)
|
|
.post(
|
|
"/api/global/auth/:tenantId/reset",
|
|
buildResetValidation(),
|
|
authController.reset
|
|
)
|
|
.post(
|
|
"/api/global/auth/:tenantId/reset/update",
|
|
buildResetUpdateValidation(),
|
|
authController.resetUpdate
|
|
)
|
|
// INIT
|
|
.post("/api/global/auth/init", authController.setInitInfo)
|
|
.get("/api/global/auth/init", authController.getInitInfo)
|
|
|
|
// DATASOURCE - MULTI TENANT
|
|
.get(
|
|
"/api/global/auth/:tenantId/datasource/:provider",
|
|
authController.datasourcePreAuth
|
|
)
|
|
.get(
|
|
"/api/global/auth/:tenantId/datasource/:provider/callback",
|
|
authController.datasourceAuth
|
|
)
|
|
|
|
// DATASOURCE - SINGLE TENANT - DEPRECATED
|
|
.get(
|
|
"/api/global/auth/datasource/:provider/callback",
|
|
authController.datasourceAuth
|
|
)
|
|
|
|
// GOOGLE - MULTI TENANT
|
|
.get("/api/global/auth/:tenantId/google", authController.googlePreAuth)
|
|
.get("/api/global/auth/:tenantId/google/callback", authController.googleAuth)
|
|
|
|
// GOOGLE - SINGLE TENANT - DEPRECATED
|
|
.get("/api/global/auth/google/callback", authController.googleAuth)
|
|
.get("/api/admin/auth/google/callback", authController.googleAuth)
|
|
|
|
// OIDC - MULTI TENANT
|
|
.get(
|
|
"/api/global/auth/:tenantId/oidc/configs/:configId",
|
|
authController.oidcPreAuth
|
|
)
|
|
.get("/api/global/auth/:tenantId/oidc/callback", authController.oidcAuth)
|
|
|
|
// OIDC - SINGLE TENANT - DEPRECATED
|
|
.get("/api/global/auth/oidc/callback", authController.oidcAuth)
|
|
.get("/api/admin/auth/oidc/callback", authController.oidcAuth)
|
|
|
|
module.exports = router
|