Implementing basic auth_grant
This commit is contained in:
@ -53,56 +53,62 @@ ViewRouter.get(
|
||||
}
|
||||
);
|
||||
|
||||
ViewRouter.get(
|
||||
"/auth",
|
||||
Stacker(GetUserMiddleware(false, true), async (req, res) => {
|
||||
let {
|
||||
scope,
|
||||
redirect_uri,
|
||||
state,
|
||||
client_id
|
||||
}: { [key: string]: string } = req.query;
|
||||
const sendError = type => {
|
||||
res.redirect((redirect_uri += `?error=${type}&state=${state}`));
|
||||
};
|
||||
let client = await Client.findOne({ client_id: client_id });
|
||||
if (!client) {
|
||||
return sendError("unauthorized_client");
|
||||
}
|
||||
|
||||
let permissions: IPermission[] = [];
|
||||
let proms: PromiseLike<void>[] = [];
|
||||
if (scope) {
|
||||
for (let perm of scope.split(";").filter(e => e !== "read_user")) {
|
||||
proms.push(
|
||||
Permission.findById(perm).then(p => {
|
||||
if (!p) return Promise.reject(new Error());
|
||||
permissions.push(p);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
let err = false;
|
||||
await Promise.all(proms).catch(e => {
|
||||
err = true;
|
||||
});
|
||||
Logging.debug(err);
|
||||
if (err) {
|
||||
return sendError("invalid_scope");
|
||||
}
|
||||
let scopes = await Promise.all(
|
||||
permissions.map(async perm => {
|
||||
let client = await Client.findById(perm.client);
|
||||
return {
|
||||
name: perm.name,
|
||||
description: perm.description,
|
||||
logo: client.logo
|
||||
};
|
||||
})
|
||||
);
|
||||
res.send(GetAuthPage(req.__, client.name, scopes));
|
||||
})
|
||||
);
|
||||
import GetAuthRoute from "../api/oauth/auth";
|
||||
|
||||
ViewRouter.get("/auth", GetAuthRoute(true))
|
||||
|
||||
// ViewRouter.get(
|
||||
// "/auth",
|
||||
// Stacker(GetUserMiddleware(false, true), async (req, res) => {
|
||||
// let {
|
||||
// scope,
|
||||
// redirect_uri,
|
||||
// state,
|
||||
// client_id
|
||||
// }: { [key: string]: string } = req.query;
|
||||
// const sendError = type => {
|
||||
// res.redirect((redirect_uri += `?error=${type}&state=${state}`));
|
||||
// };
|
||||
|
||||
// let client = await Client.findOne({ client_id: client_id });
|
||||
// if (!client) {
|
||||
// return sendError("unauthorized_client");
|
||||
// }
|
||||
|
||||
// let permissions: IPermission[] = [];
|
||||
// let proms: PromiseLike<void>[] = [];
|
||||
// if (scope) {
|
||||
// for (let perm of scope.split(";").filter(e => e !== "read_user")) {
|
||||
// proms.push(
|
||||
// Permission.findById(perm).then(p => {
|
||||
// if (!p) return Promise.reject(new Error());
|
||||
// permissions.push(p);
|
||||
// })
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// let err = false;
|
||||
// await Promise.all(proms).catch(e => {
|
||||
// err = true;
|
||||
// });
|
||||
// Logging.debug(err);
|
||||
// if (err) {
|
||||
// return sendError("invalid_scope");
|
||||
// }
|
||||
// let scopes = await Promise.all(
|
||||
// permissions.map(async perm => {
|
||||
// let client = await Client.findById(perm.client);
|
||||
// return {
|
||||
// name: perm.name,
|
||||
// description: perm.description,
|
||||
// logo: client.logo
|
||||
// };
|
||||
// })
|
||||
// );
|
||||
// res.send(GetAuthPage(req.__, client.name, scopes));
|
||||
// })
|
||||
// );
|
||||
|
||||
if (config.core.dev) {
|
||||
const logo =
|
||||
|
Reference in New Issue
Block a user