{"_id":"@cas-system/js-cas-client","name":"@cas-system/js-cas-client","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@cas-system/js-cas-client","version":"1.0.0","description":"Browser JavaScript SDK for CAS (Central Authentication Service) SSO integration","main":"src/cas-client.js","browser":"src/cas-client.js","scripts":{"build":"echo 'No build step needed — vanilla JS'"},"keywords":["cas","sso","authentication","browser","single-sign-on","javascript","one-system"],"author":{"name":"One System"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/InSol-2021/one-system.git","directory":"packages/javascript-cas-client"},"publishConfig":{"access":"public"},"_id":"@cas-system/js-cas-client@1.0.0","gitHead":"80ec5e5285cd1d810e8222df1dae82376d7da0dc","bugs":{"url":"https://github.com/InSol-2021/one-system/issues"},"homepage":"https://github.com/InSol-2021/one-system#readme","_nodeVersion":"18.19.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-5sN78J8meCJXrOAXEsw9PicplRDNoZRfHGDRWJzAiVrd2bucU3BSpplzlm5/sIMIOZQ/KVOH8YVpIll4F6qzeg==","shasum":"78171047e94e3631e643a9cee6ae23c57dd4c29d","tarball":"https://registry.npmjs.org/@cas-system/js-cas-client/-/js-cas-client-1.0.0.tgz","fileCount":4,"unpackedSize":12469,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCl5SQp002eCttOuC1ETHS+fETN809JL2gqCY7xy75wWwIhAJlj3cHtbT7KTRONt5ZromgQC0Mg6xCanUpz1UN1frco"}]},"_npmUser":{"name":"insol_user","email":"insoldev000@gmail.com"},"directories":{},"maintainers":[{"name":"insol_user","email":"insoldev000@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/js-cas-client_1.0.0_1783485301647_0.8501072725746648"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-08T04:35:01.461Z","1.0.0":"2026-07-08T04:35:01.798Z","modified":"2026-07-08T04:35:02.011Z"},"maintainers":[{"name":"insol_user","email":"insoldev000@gmail.com"}],"description":"Browser JavaScript SDK for CAS (Central Authentication Service) SSO integration","homepage":"https://github.com/InSol-2021/one-system#readme","keywords":["cas","sso","authentication","browser","single-sign-on","javascript","one-system"],"repository":{"type":"git","url":"git+https://github.com/InSol-2021/one-system.git","directory":"packages/javascript-cas-client"},"author":{"name":"One System"},"bugs":{"url":"https://github.com/InSol-2021/one-system/issues"},"license":"MIT","readme":"# JavaScript CAS Client (Browser)\n\nA lightweight JavaScript SDK for browser-based CAS SSO integration. No build tools required — works with a simple `<script>` tag (UMD: exposes a global `CasClient`, and is `require()`-able via CommonJS).\n\n## Features\n\n- 🔐 **SSO Login/Logout** — One-click login redirects\n- 🔄 **Token Handling** — Extract tokens from callback URLs\n- 🛡️ **Backend Validation** — Send tokens to your server for secure validation\n- 👥 **Role Checking** — Client-side role-based UI control\n- 📦 **Zero Dependencies** — Pure vanilla JavaScript, UMD compatible\n- 💾 **Session Storage** — Persists user data across page navigations\n\n> **⚠️ Important:** Never validate tokens in the browser. This SDK sends tokens to your backend for server-side validation.\n\n## Installation\n\n### Script Tag (CDN)\n\n```html\n<script src=\"https://your-cas-server.com/assets/js/cas-client.js\"></script>\n```\n\n### npm\n\n```bash\nnpm install @cas-system/js-cas-client\n```\n\n## Quick Start\n\n### 1. Initialize\n\n```html\n<script src=\"https://your-cas-server.com/assets/js/cas-client.js\"></script>\n<script>\n  var cas = new CasClient({\n    serverUrl: 'https://your-cas-server.com',\n    clientId: 'your_client_id',\n    callbackUrl: 'https://your-app.com/cas/callback',\n    backendValidateUrl: '/api/auth/validate',  // Your backend endpoint\n  });\n</script>\n```\n\n### 2. Login Button\n\n```html\n<button onclick=\"cas.login()\">Login with CAS</button>\n\n<!-- Or with a return URL -->\n<button onclick=\"cas.login('/dashboard')\">Login</button>\n```\n\n### 3. Callback Page\n\n```html\n<!-- On your callback page (e.g., /cas/callback) -->\n<script>\n  cas.handleCallback().then(function(user) {\n    if (user) {\n      console.log('Welcome,', user.username);\n      window.location.href = cas.consumeReturnUrl() || '/dashboard';\n    } else {\n      alert('Login failed');\n      window.location.href = '/login';\n    }\n  });\n</script>\n```\n\n### 4. Protected Pages\n\n```html\n<script>\n  if (!cas.isAuthenticated()) {\n    cas.login(window.location.href);\n  }\n\n  var user = cas.getUser();\n  document.getElementById('username').textContent = user.username;\n\n  // Role-based UI\n  if (cas.userHasRole('admin')) {\n    document.getElementById('admin-panel').style.display = 'block';\n  }\n</script>\n```\n\n### 5. Logout\n\n```html\n<button onclick=\"cas.logout('/')\">Logout</button>\n```\n\n## API Reference\n\n| Method | Description |\n|--------|-------------|\n| `login(returnUrl?)` | Redirect to CAS login (stashes `returnUrl` for after the callback) |\n| `getLoginUrl()` | Get login URL without redirect |\n| `consumeReturnUrl()` | Read + clear the `returnUrl` stashed by `login()` |\n| `handleCallback()` | Extract + validate token on callback page |\n| `extractTokenFromUrl()` | Extract token from URL query string |\n| `validateTokenViaBackend(token)` | Send token to backend for validation |\n| `getUser()` | Get stored user data |\n| `isAuthenticated()` | Check if user is logged in |\n| `logout(redirectUrl?)` | Clear session and redirect to CAS logout |\n| `userHasRole(role)` | Check single role |\n| `userHasAnyRole(roles)` | Check any of roles |\n| `userHasAllRoles(roles)` | Check all roles |\n\n## Backend Validation Contract\n\nThis browser SDK never holds your `client_secret` and never validates tokens itself.\n`validateTokenViaBackend(token)` POSTs `{ \"token\": \"<jwt>\" }` to your `backendValidateUrl`.\nYour backend must then validate the token **server-to-server** against the CAS server:\n\n```\nPOST {CAS_BASE}/api/validate-token        Content-Type: application/json\n{ \"token\": \"<jwt>\", \"client_id\": \"...\", \"client_secret\": \"...\" }\n\n200 → { \"valid\": true, \"user\": { \"id\", \"username\", \"email\" }, \"expires_at\": \"...\" }\n401 → { \"error\": \"<message>\" }\n```\n\nThe token is **single-use** — validate it once, then establish your own app session. Your\nbackend endpoint should return a JSON body containing a `user` object back to the browser.\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-fa8497a3ee84adf3f0b5d81537cd20b0"}