在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:Donny2333/koa2-sso开源软件地址:https://github.com/Donny2333/koa2-sso开源编程语言:JavaScript 100.0%开源软件介绍:Koa CAS AuthenticationThis is a CAS authentication library designed to be used with an Koa server. It provides two middleware functions for controlling access to routes:
It also provides two route endpoint functions:
Installation
Setupimport Cas from 'koa2-cas'
const cas = new Cas({
cas_url: 'https://my-cas-host.com/cas',
service_url: 'https://my-service-host.com',
cas_version: '3.0',
renew: false,
is_dev_mode: false,
dev_mode_user: '',
dev_mode_info: {},
session_name: 'cas_user',
session_info: 'cas_userinfo',
destroy_session: false
}) Options
Usageconst Koa = require('koa')
const Router = require('koa-router')
const Session = require('koa-session')
const Cas = require('koa2-cas')
// Set up an Koa session, which is required for CASAuthentication.
app.keys = ['some secret hurr']
app.use(Session(app))
// Create a new instance of CASAuthentication.
const cas = new Cas({
cas_url: 'https://my-cas-host.com/cas',
service_url: 'https://my-service-host.com'
})
const router = Router()
// Unauthenticated clients will be redirected to the CAS login and then back to
// this route once authenticated.
router.get('/app', cas.bounce, ctx => {
ctx.body = '<html><body>Hello!</body></html>'
})
// Unauthenticated clients will receive a 401 Unauthorized response instead of
// the JSON data.
router.get('/api', cas.block, ctx => {
ctx.body = { success: true }
})
// An example of accessing the CAS user session variable. This could be used to
// retrieve your own local user records based on authenticated CAS username.
router.get('/api/user', cas.block, ctx => {
ctx.body = {
cas_user: ctx.session[cas.session_name]
}
})
// Unauthenticated clients will be redirected to the CAS login and then to the
// provided "redirectTo" query parameter once authenticated.
router.get('/authenticate', cas.bounce_redirect)
// This route will de-authenticate the client with the Koa server and then
// redirect the client to the CAS logout page.
router.get('/logout', cas.logout)
app.use(router.routes())
app.listen(3000, _ => {
console.log('listening on port 3000')
}) |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论