npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

koa-auth-cas

v1.1.1

Published

koa middleware for cas sso

Downloads

1

Readme

CHNAGELOG

v1.1.1

  • added logout redirect support

v1.1.0

  • BETA: added support for single logout

v1.0.0

  • modifications to support CAS 6.0.x

Adopted from Donny2333's implementation of the middleware https://github.com/Donny2333/koa2-sso

tweak for Apereo CAS 6.0.x


Koa CAS Authentication

This is a CAS authentication library designed to be used with an Koa server.

It provides two middleware functions for controlling access to routes:

  • bounce: Redirects an unauthenticated client to the CAS login page and then back to the requested page.
  • block: Completely denies access to an unauthenticated client and returns a 401 response.

It also provides two route endpoint functions:

  • bounce_redirect: Acts just like bounce but once the client is authenticated they will be redirected to the provided returnTo query parameter.
  • logout: De-authenticates the client with the Koa server and then redirects them to the CAS logout page.

Installation

npm install koa2-cas

Setup

import 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,
  single_logout: false
})

Options

| Name | Type | Description | Default | |:-----|:----:|:------------|:-------:| | cas_url | string | The URL of the CAS server. | (required) | | service_url | string | The URL of the application which is registered with the CAS server as a valid service. | (required) | | cas_version | "1.0"|"2.0|"3.0"|"saml1.1" | The CAS protocol version. | "3.0" | | renew | boolean | If true, an unauthenticated client will be required to login to the CAS system regardless of whether a single sign-on session exists. | false | | is_dev_mode | boolean | If true, no CAS authentication will be used and the session CAS variable will be set to whatever user is specified as dev_mode_user. | false | | dev_mode_user | string | The CAS user to use if dev mode is active. | "" | | dev_mode_info | Object | The CAS user information to use if dev mode is active. | {} | | session_name | string | The name of the session variable that will store the CAS user once they are authenticated. | "cas_user" | | session_info | string | The name of the session variable that will store the CAS user information once they are authenticated. If set to false (or something that evaluates as false), the additional information supplied by the CAS will not be forwarded. This will not work with CAS 1.0, as it does not support additional user information. | false | | destroy_session | boolean | If true, the logout function will destroy the entire session upon CAS logout. Otherwise, it will only delete the session variable storing the CAS user. | false | | single_logout | boolean | (BETA FEATURE): If true, single logout will be enabled, external store needed be configured for koa session, (e.g. redis store via koa-session-redis-store) | false | | logout_redirect_url | string | redirect to this url after logout | "" |

Usage

const Koa = require('koa')
const Router = require('koa-router')
const Session = require('koa-session')
const Cas = require('koa-auth-cas')
const RedisStore = require('koa-session-redis-store')

// Set up an Koa session, which is required for CASAuthentication.
app.keys = ['some secret hurr']
app.use(Session({
  key: 'my-session-key',
  store: new RedisStore({
    host: 'my-redis-host'
  })
}))

// 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)

// This route will handle the SLO POST request from CAS server and
// destroy local session
router.post('/single_logout', cas.handle_single_logout)

app.use(router.routes())

app.listen(3000, _ => {
  console.log('listening on port 3000')
})