keycloak-demo/routes/api/index.js

59 lines
1.3 KiB
JavaScript
Raw Normal View History

2021-08-31 10:24:42 +00:00
const Router = require('@koa/router');
2021-09-01 07:20:53 +00:00
const joi = require('joi');
2021-08-31 10:24:42 +00:00
const commonCtrl = require('src/controllers/common/index.js');
2021-09-01 07:20:53 +00:00
const accCtrl = require('src/controllers/account/index.js');
2021-08-31 10:24:42 +00:00
const r = new Router({ prefix: '/api' });
module.exports = r;
// set api handler middleware
2021-09-01 07:20:53 +00:00
r.use(commonCtrl.apiHandler());
/**
* get account info
* @swagger
* @route GET /api/login
* @group account - account apis
* @param {string} back_url.query.required - back to url
* @returns {RespDefault.model} default -
*/
r.get(
'/login',
commonCtrl.validate({
query: {
back_url: joi.string().required(),
},
}),
accCtrl.loginSSO()
);
/**
* account refresh token
* @swagger
* @route POST /api/refresh
* @group account - account apis
* @security JWT
* @returns {RespDefault.model} default -
*/
r.post('/refresh', commonCtrl.authorization(true), accCtrl.logout());
/**
* account logout
* @swagger
* @route POST /api/logout
* @group account - account apis
* @security JWT
* @returns {RespDefault.model} default -
*/
r.post('/logout', commonCtrl.authorization(false), accCtrl.logout());
2021-08-31 10:24:42 +00:00
2021-09-01 07:20:53 +00:00
/**
* account get info
* @swagger
* @route GET /api/userinfo
* @group account - account apis
* @security JWT
* @returns {RespDefault.model} default -
*/
r.get('/userinfo', commonCtrl.authorization(false), accCtrl.getInfo());