{"id":21740990,"url":"https://github.com/produck/cas-client","last_synced_at":"2025-04-13T03:41:37.840Z","repository":{"id":33955062,"uuid":"163853616","full_name":"produck/cas-client","owner":"produck","description":"A complete implement of CAS Client middleware for Node.js, support CAS 1.0, 2.0+, 3.0+ protocol.","archived":false,"fork":false,"pushed_at":"2024-01-10T09:39:13.000Z","size":265,"stargazers_count":18,"open_issues_count":2,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T20:51:27.102Z","etag":null,"topics":["apereo","cas-client","cas-protocol","cas-proxy","koa","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/produck.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-02T14:49:17.000Z","updated_at":"2025-02-28T09:30:44.000Z","dependencies_parsed_at":"2024-06-19T00:17:56.456Z","dependency_job_id":"eae9492d-d728-498a-bfcd-4ab840ddbefd","html_url":"https://github.com/produck/cas-client","commit_stats":null,"previous_names":["lemonce/cas-client"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/produck%2Fcas-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/produck%2Fcas-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/produck%2Fcas-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/produck%2Fcas-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/produck","download_url":"https://codeload.github.com/produck/cas-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248660874,"owners_count":21141365,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apereo","cas-client","cas-protocol","cas-proxy","koa","nodejs"],"created_at":"2024-11-26T06:16:12.761Z","updated_at":"2025-04-13T03:41:37.815Z","avatar_url":"https://github.com/produck.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# http-cas-client\n[![Build Status](https://img.shields.io/travis/lemonce/cas-client.svg?style=flat-square)](https://www.npmjs.com/package/http-cas-client)\n[![NPM Downloads](https://img.shields.io/npm/dm/http-cas-client.svg?style=flat-square)](https://www.npmjs.com/package/http-cas-client)\n[![NPM Version](https://img.shields.io/npm/v/http-cas-client.svg?style=flat-square)](https://www.npmjs.com/package/http-cas-client)\n\nA complete implement of CAS Client middleware for Node.js, support CAS 1.0, 2.0+, 3.0+ protocol.\n\nCAS(Central Authentication Service) is a single-sign-on / single-sign-off protocol for the web.\n\nWe suppose you are already familiar with the CAS protocol, if not, please read this [document](https://apereo.github.io/cas/6.0.x/protocol/CAS-Protocol.html) before you use this.\n\n## Installation\n\n```base\n$ npm install http-cas-client\n```\n\n## Feature\n\n* Singing Sign On (SSO)\n* CAS Proxy with axios api for POST, PUT, DELETE...\n* CAS Proxy - proxiex chain checking\n* Single Logout (SLO)\n* Renew \u0026 gateway\n* Native http module supported\n* No-session mode supported\n* Easy to wrap for all popular backend framework integration\n* Cluster friendly //TODO\n* Principal adapter for application debugging //TODO\n* SMAL1.1 //TODO\n* Restlet integration supported //TODO\n* Conditional skip CAS authentication //TODO\n* PT cache //TODO\n\n## Getting Started\n\n### CAS Client Handler for Native\n\nBasic usage with default options for creating a cas client handler and use it in nodejs native http server. For example,\n```js\nconst http = require('http');\nconst httpCasClient = require('http-cas-client');\n\n// A CAS server deployed at url http://localhost:8080.\n// Default prefix is '/'.\nconst handler = httpCasClient({\n\tcasServerUrlPrefix: 'http://localhost:9000/cas',\n\tserverName: 'http://127.0.0.1'\n});\n\nhttp.createServer(async (req, res) =\u003e {\n\tif(!await handler(req, res)) {\n\t\treturn res.end();\n\t}\n\n\tconst { principal, ticket } = req;\n\tconsole.log(principal, ticket);\n\t// { user: 'test', attributes: { ... } }\n\n\t// your statements...\n\tres.end('hello world');\n}).listen(80);\n```\n### Koa2 Wrap\nIt can also use with popular backend framework like Koa2. For example,\n```js\nconst koaCasClient = require('http-cas-client/wrap/koa2');\nconst Koa = require('koa');\nconst bodyparser = require('koa-bodyparser');\n\nconst casServerUrlPrefix = 'http://localhost:9000/cas';\n\nconst app = new Koa();\n\n// NOTICE: If you put bodyparser after cas client, bodyparser will not receive req.socket data.\n// A native body parser is used in handler.\n// Sometimes you need to make some adjustments for your especial case.\napp.use(bodyparser());\n\n// NOTICE: Put the middleware include casClientHandler before your specific api code.\n// For example, put it before routes.\napp.use(koaCasClient({\n\tcasServerUrlPrefix: 'http://localhost:9000/cas',\n\tserverName: 'http://127.0.0.1'\n})).use(ctx =\u003e {\n\tconst { principal, ticket } = ctx;\n\n\t// your statements...\n\tctx.body = `\u003ca href=\"${casServerUrlPrefix}/logout\"\u003eSLO\u003c/a\u003e\u003cpre\u003e`\n\tctx.body += JSON.stringify(principal, null, 2);\n\tctx.body += '\u003c/pre\u003e'\n}).listen(80);\n```\nUnder the traditional pattern, cas client NEED to use with session, especially those 'Spring mvc' project in servlet.\n\nSo there is also a way to implement with all nodejs backend frameworks. For example in Koa2,\n```js\nconst koaSessionCasClient = require('http-cas-client/wrap/koa2-session');\nconst session = require('koa-session');\nconst Koa = require('koa');\nconst casServerUrlPrefix = 'http://localhost:9000/cas';\n\nconst app = new Koa();\nconst sessionMiddleware = session(app);\napp.keys = ['koa-app'];\n\napp.use(session(app)).use(koaSessionCasClient({\n\tcasServerUrlPrefix: 'http://localhost:9000/cas',\n\tserverName: 'http://127.0.0.1'\n})).use(ctx =\u003e {\n\tconst { principal } = ctx;\n\n\t// your statements...\n\tctx.body = `\u003ca href=\"${casServerUrlPrefix}/logout\"\u003eSLO\u003c/a\u003e\u003cpre\u003e`\n\tctx.body += JSON.stringify(principal, null, 2);\n\tctx.body += '\u003c/pre\u003e'\n}).listen(80);\n```\n### CAS Proxy (Use ServiceTicket instance)\n```js\nconst koaSessionCasClient = require('http-cas-client/wrap/koa2-session');\nconst koaCasClient = require('http-cas-client/wrap/koa2');\nconst Koa = require('koa');\nconst session = require('koa-session');\n\nconst casServerUrlPrefix = 'http://localhost:9000/cas';\n\nconst app = new Koa();\napp.keys = ['koa-app'];\napp.use(session(app)).use(koaSessionCasClient({\n\tcasServerUrlPrefix: 'http://localhost:9000/cas',\n\tserverName: 'http://127.0.0.1:2000',\n\tclient: {\n\t\tproxy: {\n\t\t\tcallbackUrl: 'http://127.0.0.1:2000/callback',\n\t\t\treceptorUrl: '/callback'\n\t\t}\n\t}\n})).use((ctx, next) =\u003e {\n\t// If req.url matches /app, skip into next middleware.\n\tif (ctx.request.path === '/app') {\n\t\treturn next();\n\t}\n\n\tconst { principal } = ctx;\n\n\t// This is the 1st cas client.\n\t// your statements...\n\tctx.body = `\u003cp\u003eThis is proxy\u003c/p\u003e`;\n\tctx.body = `\u003ca href=\"${casServerUrlPrefix}/logout\"\u003eSLO\u003c/a\u003e\u003cpre\u003e`\n\tctx.body += JSON.stringify(principal, null, 2);\n\tctx.body += '\u003c/pre\u003e'\n}).use(async ctx =\u003e {\n\tconst { ticket } = ctx;\n\n\t// Proxy request some data from 2rd cas client 'http://127.0.0.1:3000'.\n\tconst response = await ticket.request('http://127.0.0.1:3000/').then(axios =\u003e {\n\t\treturn axios.post('/test');\n\t});\n\n\t// Proxy send the data from 2rd.\n\tctx.body = response.data;\n}).listen(2000);\n\nconst app2 = new Koa();\napp2.use(koaCasClient({\n\tcasServerUrlPrefix: 'http://localhost:9000/cas',\n\tserverName: 'http://127.0.0.1:3000',\n\tclient: {\n\t\tproxy: {\n\t\t\tacceptAny: true,\n\t\t\tcallbackUrl: 'http://127.0.0.1:3000/proxyCallback',\n\t\t\treceptorUrl: '/proxyCallback'\n\t\t}\n\t}\n})).use(async ctx =\u003e {\n\t//This is the 2nd cas client.\n\tconst { principal, ticket } = ctx;\n\n\t// Proxy request some data from 3rd cas client 'http://127.0.0.1:4000/'.\n\tconst response = await ticket.request('http://127.0.0.1:4000/').then(axios =\u003e {\n\t\treturn axios.post('/test');\n\t});\n\n\t// your statements...\n\tctx.body = `\u003cp\u003eThis is App\u003c/p\u003e`;\n\tctx.body += `\u003ca href=\"${casServerUrlPrefix}/logout\"\u003eSLO\u003c/a\u003e\u003cpre\u003e`;\n\tctx.body += JSON.stringify(principal, null, 2);\n\tctx.body += '\u003c/pre\u003e';\n\n\t// Combine data from the 3rd.\n\tctx.body += response.data;\n}).listen(3000);\n\nconst app3 = new Koa();\napp3.use(koaCasClient({\n\tcasServerUrlPrefix: 'http://localhost:9000/cas',\n\tserverName: 'http://127.0.0.1:4000',\n\tclient: {\n\t\tproxy: {\n\t\t\tacceptAny: true,\n\t\t}\n\t}\n})).use(async ctx =\u003e {\n\t// This is the 3rd cas client.\n\t// your statements...\n\tctx.body = 'from the proxy proxy app.'\n}).listen(4000);\n```\n### Custom Wrap\n//TODO But you can review 'http-cas-client/wrap/koa2.js'. Maybe you can understand how to do.\n\nAt least I think that's easy. Good luck.\n\n## API Referrence\n### Options\nThe origin of CAS Server is essential. The simplest form is like,\n```js\nconst httpCasClient = require('http-cas-client');\nconst handler = httpCasClient({\n\tcasServerUrlPrefix: 'http://localhost:9000/cas',\n\tserverName: 'http://127.0.0.1',\n});\n```\n#### Full Default Options\n```js\n// Other items are optional.\nconst defaultOptions = {\n\tcas: 3, // CAS protocol version 1, 2, 3\n\n\tclient: {\n\t\tservice: null,\n\t\tslo: true, // Use SLO?\n\t\trenew: false, // CAS renew.\n\t\tgateway: false, // CAS gateway\n\t\tuseSession: false,\n\t\tmethod: 'GET',\n\t\t// The resource path rules let cas client ignore.\n\t\tignore: [/\\.(ico|css|js|jpe?g|svg|png)/],\n\t\tproxy: {\n\t\t\tacceptAny: false,\n\t\t\tallowedChains: () =\u003e true,\n\t\t\tcallbackUrl: null,\n\t\t\treceptorUrl: null\n\t\t}\n\t},\n\n\tserver: {\n\t\tloginUrl: null,\n\n\t\t// CAS Server URIs. Normally no change is required.\n\t\t// Useful when use a nonstandard cas server or url re-writed.\n\t\tpath: {\n\t\t\tlogin: '/login',\n\t\t\tlogout: '/logout',\n\t\t\tvalidate: '/validate',\n\t\t\tserviceValidate: '/serviceValidate',\n\t\t\tproxyValidate: '/proxyValidate',\n\t\t\tproxy: '/proxy',\n\t\t\tp3: {\n\t\t\t\tserviceValidate: '/p3/serviceValidate',\n\t\t\t\tproxyValidate: '/p3/proxyValidate',\n\t\t\t}\n\t\t}\n\t}\n}\n```\nWhy these paths? See also, [CAS Protocol 3.0 Specification](https://apereo.github.io/cas/5.2.x/protocol/CAS-Protocol-Specification.html#2-cas-uris).\n\n#### Customs Options for Special Purposes\nYou can also override all items of options for your special cas server. And use chained multiple options arguments to create handler,\n```js\nconst casClientHandler = httpCasClient(options1, options2, ...);\n```\n### Store\nStore is an event emitter.\n#### Method\n\n//TODO\n\n#### Event\n//TODO\n\n## CAS Client Cluster\n### Shared Ticket Store\n### Sync ST store\n#### In Frontend\n#### In Backend\n\n## Debug\nBecause CAS protocol is complicated, we remove this option. We recommend you to always log every step that what CAS client do on your production environment.\n\nSetting env.DEBUG=\"cas,cas:*\";\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fproduck%2Fcas-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fproduck%2Fcas-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fproduck%2Fcas-client/lists"}