keycloak-demo/routes/api/index.js
2021-09-01 21:15:26 +08:00

49 lines
1.1 KiB
JavaScript

const Router = require('@koa/router')
const joi = require('joi')
const commonCtrl = require('src/controllers/common/index.js')
const accCtrl = require('src/controllers/account/index.js')
const r = new Router({ prefix: '/api' })
module.exports = r
// set api handler middleware
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 logout
* @swagger
* @route POST /api/logout
* @group account - account apis
* @security JWT
* @returns {RespDefault.model} default -
*/
r.post('/logout', commonCtrl.authorization(), accCtrl.logout())
/**
* account get info
* @swagger
* @route GET /api/userinfo
* @group account - account apis
* @security JWT
* @returns {RespDefault.model} default -
*/
r.get('/userinfo', commonCtrl.authorization(), accCtrl.getInfo())