Adding $local callback endpoint
This commit is contained in:
parent
11f460406b
commit
1cb0873ce8
@ -12,6 +12,8 @@ import { ObjectID } from "bson";
|
|||||||
const AuthRoute = Stacker(GetUserMiddleware(true), async (req: Request, res: Response) => {
|
const AuthRoute = Stacker(GetUserMiddleware(true), async (req: Request, res: Response) => {
|
||||||
let { response_type, client_id, redirect_uri, scope, state, nored } = req.query;
|
let { response_type, client_id, redirect_uri, scope, state, nored } = req.query;
|
||||||
const sendError = (type) => {
|
const sendError = (type) => {
|
||||||
|
if (redirect_uri === "$local")
|
||||||
|
redirect_uri = "/code";
|
||||||
res.redirect(redirect_uri += `?error=${type}&state=${state}`);
|
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);
|
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") {
|
if (nored === "true") {
|
||||||
res.json({
|
res.json({
|
||||||
redirect_uri: ruri
|
redirect_uri: ruri
|
||||||
|
@ -34,6 +34,14 @@ ViewRouter.get("/login", (req, res) => {
|
|||||||
res.send(GetLoginPage(req.__))
|
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) => {
|
ViewRouter.get("/admin", GetUserMiddleware(false, true), (req: Request, res, next) => {
|
||||||
if (!req.isAdmin) res.sendStatus(HttpStatusCode.FORBIDDEN)
|
if (!req.isAdmin) res.sendStatus(HttpStatusCode.FORBIDDEN)
|
||||||
else next()
|
else next()
|
||||||
|
Loading…
Reference in New Issue
Block a user