Adding $local callback endpoint

This commit is contained in:
Fabian Stamm 2019-10-12 18:29:00 +02:00
parent 11f460406b
commit 1cb0873ce8
2 changed files with 13 additions and 1 deletions

View File

@ -12,6 +12,8 @@ import { ObjectID } from "bson";
const AuthRoute = Stacker(GetUserMiddleware(true), async (req: Request, res: Response) => {
let { response_type, client_id, redirect_uri, scope, state, nored } = req.query;
const sendError = (type) => {
if (redirect_uri === "$local")
redirect_uri = "/code";
res.redirect(redirect_uri += `?error=${type}&state=${state}`);
}
/**
@ -63,7 +65,9 @@ const AuthRoute = Stacker(GetUserMiddleware(true), async (req: Request, res: Res
});
await ClientCode.save(code);
let ruri = client.redirect_url + `?code=${code.code}&state=${state}`;
let redir = client.redirect_url === "$local" ? "/code" : client.redirect_url;
let ruri = redir + `?code=${code.code}&state=${state}`;
if (nored === "true") {
res.json({
redirect_uri: ruri

View File

@ -34,6 +34,14 @@ ViewRouter.get("/login", (req, res) => {
res.send(GetLoginPage(req.__))
})
ViewRouter.get("/code", (req, res) => {
res.setHeader("Cache-Control", "no-cache");
if (req.query.error)
res.send("Some error occured: " + req.query.error);
else
res.send(`Your code is: ${req.query.code}`);
})
ViewRouter.get("/admin", GetUserMiddleware(false, true), (req: Request, res, next) => {
if (!req.isAdmin) res.sendStatus(HttpStatusCode.FORBIDDEN)
else next()