keycloak-demo/routes/api/index.js

49 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-09-01 12:46:41 +00:00
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')
2021-08-31 10:24:42 +00:00
2021-09-01 12:46:41 +00:00
const r = new Router({ prefix: '/api' })
module.exports = r
2021-08-31 10:24:42 +00:00
// set api handler middleware
2021-09-01 12:46:41 +00:00
r.use(commonCtrl.apiHandler())
2021-09-01 07:20:53 +00:00
/**
* 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 -
*/
2021-09-01 12:46:41 +00:00
r.get(
2021-09-01 07:20:53 +00:00
'/login',
commonCtrl.validate({
query: {
2021-09-01 12:46:41 +00:00
back_url: joi.string().required()
}
2021-09-01 07:20:53 +00:00
}),
accCtrl.loginSSO()
2021-09-01 12:46:41 +00:00
)
2021-09-01 07:20:53 +00:00
/**
* account logout
* @swagger
* @route POST /api/logout
* @group account - account apis
* @security JWT
* @returns {RespDefault.model} default -
*/
2021-09-01 13:15:26 +00:00
r.post('/logout', commonCtrl.authorization(), 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 -
*/
2021-09-01 13:15:26 +00:00
r.get('/userinfo', commonCtrl.authorization(), accCtrl.getInfo())