Adding state perameter to /api/client/user endpoint

This commit is contained in:
Fabian Stamm 2019-03-15 13:43:10 +00:00
parent 2b9eb6e974
commit 67dde954cc
1 changed files with 10 additions and 7 deletions

View File

@ -8,20 +8,23 @@ import { createJWT } from "../../keys";
const ClientRouter = Router(); const ClientRouter = Router();
/** /**
* @api {get} /client/user * @api {get} /client/user
* @apiName ClientUser
*
* @apiGroup client
* @apiPermission user_client Requires ClientID and Authenticated User
*
* @apiParam {String} redirect_uri URL to redirect to on success * @apiParam {String} redirect_uri URL to redirect to on success
* @apiParam {String} state A optional state, that will be included in the JWT and redirect_uri as parameter
*
* @apiName ClientUser
* @apiGroup client
*
* @apiPermission user_client Requires ClientID and Authenticated User
*/ */
ClientRouter.get("/user", Stacker(GetClientAuthMiddleware(false), GetUserMiddleware(true, false), async (req: Request, res: Response) => { ClientRouter.get("/user", Stacker(GetClientAuthMiddleware(false), GetUserMiddleware(true, false), async (req: Request, res: Response) => {
let { redirect_uri, state } = req.query;
let jwt = await createJWT({ let jwt = await createJWT({
client: req.client.client_id, client: req.client.client_id,
uid: req.user.uid, uid: req.user.uid,
username: req.user.username username: req.user.username,
state: state
}, 30); //after 30 seconds this token is invalid }, 30); //after 30 seconds this token is invalid
res.redirect(req.query.redirect_uri + "?jwt=" + jwt) res.redirect(redirect_uri + "?jwt=" + jwt + (state ? `&state=${state}` : ""));
})); }));
export default ClientRouter; export default ClientRouter;