@cas-system/nextjs-cas-client 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +148 -0
  3. package/dist/CasProvider.d.ts +63 -0
  4. package/dist/CasProvider.d.ts.map +1 -0
  5. package/dist/CasProvider.js +150 -0
  6. package/dist/CasProvider.js.map +1 -0
  7. package/dist/components/CasLoginButton.d.ts +36 -0
  8. package/dist/components/CasLoginButton.d.ts.map +1 -0
  9. package/dist/components/CasLoginButton.js +23 -0
  10. package/dist/components/CasLoginButton.js.map +1 -0
  11. package/dist/components/CasProtectedRoute.d.ts +51 -0
  12. package/dist/components/CasProtectedRoute.d.ts.map +1 -0
  13. package/dist/components/CasProtectedRoute.js +58 -0
  14. package/dist/components/CasProtectedRoute.js.map +1 -0
  15. package/dist/handlers/callback.d.ts +39 -0
  16. package/dist/handlers/callback.d.ts.map +1 -0
  17. package/dist/handlers/callback.js +65 -0
  18. package/dist/handlers/callback.js.map +1 -0
  19. package/dist/handlers/index.d.ts +8 -0
  20. package/dist/handlers/index.d.ts.map +1 -0
  21. package/dist/handlers/index.js +8 -0
  22. package/dist/handlers/index.js.map +1 -0
  23. package/dist/handlers/logout.d.ts +36 -0
  24. package/dist/handlers/logout.d.ts.map +1 -0
  25. package/dist/handlers/logout.js +61 -0
  26. package/dist/handlers/logout.js.map +1 -0
  27. package/dist/handlers/user.d.ts +27 -0
  28. package/dist/handlers/user.d.ts.map +1 -0
  29. package/dist/handlers/user.js +44 -0
  30. package/dist/handlers/user.js.map +1 -0
  31. package/dist/hooks/useCasAuth.d.ts +32 -0
  32. package/dist/hooks/useCasAuth.d.ts.map +1 -0
  33. package/dist/hooks/useCasAuth.js +14 -0
  34. package/dist/hooks/useCasAuth.js.map +1 -0
  35. package/dist/hooks/useCasUser.d.ts +33 -0
  36. package/dist/hooks/useCasUser.d.ts.map +1 -0
  37. package/dist/hooks/useCasUser.js +45 -0
  38. package/dist/hooks/useCasUser.js.map +1 -0
  39. package/dist/index.d.ts +19 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +17 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/middleware.d.ts +40 -0
  44. package/dist/middleware.d.ts.map +1 -0
  45. package/dist/middleware.js +111 -0
  46. package/dist/middleware.js.map +1 -0
  47. package/dist/server/auth.d.ts +111 -0
  48. package/dist/server/auth.d.ts.map +1 -0
  49. package/dist/server/auth.js +215 -0
  50. package/dist/server/auth.js.map +1 -0
  51. package/dist/server/cas-client.d.ts +93 -0
  52. package/dist/server/cas-client.d.ts.map +1 -0
  53. package/dist/server/cas-client.js +222 -0
  54. package/dist/server/cas-client.js.map +1 -0
  55. package/dist/server/index.d.ts +12 -0
  56. package/dist/server/index.d.ts.map +1 -0
  57. package/dist/server/index.js +11 -0
  58. package/dist/server/index.js.map +1 -0
  59. package/dist/types.d.ts +170 -0
  60. package/dist/types.d.ts.map +1 -0
  61. package/dist/types.js +6 -0
  62. package/dist/types.js.map +1 -0
  63. package/package.json +73 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,aAAa,EACb,aAAa,EACb,eAAe,EACf,WAAW,EACX,wBAAwB,GACzB,MAAM,QAAQ,CAAC;AAEhB,YAAY,EACV,SAAS,EACT,eAAe,EACf,OAAO,EACP,cAAc,EACd,gBAAgB,GACjB,MAAM,UAAU,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @module @cas-system/nextjs-cas-client/server
3
+ * @description Server-only entry point for the Next.js CAS Client SDK.
4
+ *
5
+ * Exposes the {@link CasClient} (token validation / generation / logout) and
6
+ * the cookie-based session helpers. These modules require the
7
+ * `clientSecret` / cookie signing secret and must never run in the browser.
8
+ */
9
+ export { CasClient } from './cas-client';
10
+ export { getCasSession, setCasSession, clearCasSession, withCasAuth, getCasSessionFromRequest, } from './auth';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,aAAa,EACb,aAAa,EACb,eAAe,EACf,WAAW,EACX,wBAAwB,GACzB,MAAM,QAAQ,CAAC"}
@@ -0,0 +1,170 @@
1
+ /**
2
+ * @module @cas-system/nextjs-cas-client/types
3
+ * @description Core TypeScript type definitions for the CAS Client SDK.
4
+ */
5
+ /**
6
+ * Base configuration for connecting to the CAS server.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const config: CasConfig = {
11
+ * serverUrl: 'https://cas.example.com',
12
+ * clientId: 'my-app',
13
+ * callbackUrl: 'https://myapp.com/api/cas/callback',
14
+ * };
15
+ * ```
16
+ */
17
+ export interface CasConfig {
18
+ /** Base URL of the CAS server (no trailing slash). */
19
+ serverUrl: string;
20
+ /** OAuth / SSO client identifier registered on the CAS server. */
21
+ clientId: string;
22
+ /**
23
+ * URL the CAS server redirects to after login.
24
+ * Defaults to `{origin}/api/cas/callback` when omitted.
25
+ */
26
+ callbackUrl?: string;
27
+ }
28
+ /**
29
+ * Server-side CAS configuration — extends {@link CasConfig} with the
30
+ * client secret that **must never be exposed to the browser**.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const serverConfig: CasServerConfig = {
35
+ * serverUrl: process.env.CAS_SERVER_URL!,
36
+ * clientId: process.env.CAS_CLIENT_ID!,
37
+ * clientSecret: process.env.CAS_CLIENT_SECRET!,
38
+ * };
39
+ * ```
40
+ */
41
+ export interface CasServerConfig extends CasConfig {
42
+ /** Secret key used for server-to-server token validation & generation. */
43
+ clientSecret: string;
44
+ }
45
+ /**
46
+ * Authenticated user object returned by the CAS server after token validation.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const user: CasUser = {
51
+ * id: '550e8400-e29b-41d4-a716-446655440000',
52
+ * username: 'jdoe',
53
+ * email: 'jdoe@example.com',
54
+ * roles: ['admin', 'editor'],
55
+ * };
56
+ * ```
57
+ */
58
+ export interface CasUser {
59
+ /** Unique identifier of the user. */
60
+ id: string;
61
+ /** Login username. */
62
+ username: string;
63
+ /** E-mail address. */
64
+ email: string;
65
+ /** Optional list of role names assigned to the user. */
66
+ roles?: string[];
67
+ }
68
+ /**
69
+ * Shape of the data persisted in the encrypted session cookie.
70
+ * @internal
71
+ */
72
+ export interface CasSessionData {
73
+ /** The authenticated user. */
74
+ user: CasUser;
75
+ /** Raw JWT token issued by the CAS server. */
76
+ token: string;
77
+ /** Unix-ms timestamp when the session was created. */
78
+ createdAt: number;
79
+ }
80
+ /**
81
+ * Configuration for the Next.js CAS authentication middleware.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * const mwConfig: CasMiddlewareConfig = {
86
+ * protectedPaths: ['/dashboard', '/admin'],
87
+ * publicPaths: ['/', '/about', '/api/health'],
88
+ * loginPath: '/login',
89
+ * };
90
+ * ```
91
+ */
92
+ export interface CasMiddlewareConfig {
93
+ /**
94
+ * Path prefixes that require authentication.
95
+ * A request whose `pathname` starts with any of these strings will be
96
+ * checked for a valid CAS session cookie.
97
+ */
98
+ protectedPaths: string[];
99
+ /**
100
+ * Custom path for the login page within the app.
101
+ * When provided, unauthenticated users are redirected here instead of
102
+ * directly to the CAS server login URL.
103
+ * @default undefined — redirects straight to CAS server
104
+ */
105
+ loginPath?: string;
106
+ /**
107
+ * Paths that are explicitly public even if they match a protected prefix.
108
+ * Useful for health-check endpoints nested under a protected prefix.
109
+ */
110
+ publicPaths?: string[];
111
+ }
112
+ /**
113
+ * Shape of the value provided by `CasProvider` through React Context.
114
+ */
115
+ export interface CasAuthContext {
116
+ /** The current user, or `null` when not authenticated. */
117
+ user: CasUser | null;
118
+ /** `true` while the initial session fetch is in progress. */
119
+ isLoading: boolean;
120
+ /** `true` when a valid session exists. */
121
+ isAuthenticated: boolean;
122
+ /** Error from the last session fetch, if any. */
123
+ error: Error | null;
124
+ /** Redirect the browser to the CAS login page. */
125
+ login: (returnUrl?: string) => void;
126
+ /** Clear the session and redirect to CAS logout. */
127
+ logout: () => Promise<void>;
128
+ /** Re-fetch the session from the server. */
129
+ refresh: () => Promise<void>;
130
+ }
131
+ /**
132
+ * Configuration for the API route handlers.
133
+ */
134
+ export interface CasHandlerConfig {
135
+ /** Server-side CAS configuration. */
136
+ cas: CasServerConfig;
137
+ /**
138
+ * URL to redirect to after successful login callback.
139
+ * @default '/'
140
+ */
141
+ afterLoginUrl?: string;
142
+ /**
143
+ * URL to redirect to after logout.
144
+ * @default '/'
145
+ */
146
+ afterLogoutUrl?: string;
147
+ }
148
+ /**
149
+ * Response shape returned by `POST {CAS_BASE}/api/validate-token`.
150
+ * Success: `{ valid: true, user: { id, username, email }, expires_at }`.
151
+ * Failure: HTTP 401 with `{ error }`.
152
+ * @internal
153
+ */
154
+ export interface CasValidateResponse {
155
+ valid?: boolean;
156
+ user?: CasUser;
157
+ expires_at?: string;
158
+ error?: string;
159
+ }
160
+ /**
161
+ * Response shape returned by `POST {CAS_BASE}/api/sso/token`.
162
+ * Success: `{ redirect_url, token }`.
163
+ * @internal
164
+ */
165
+ export interface CasTokenResponse {
166
+ redirect_url?: string;
167
+ token?: string;
168
+ error?: string;
169
+ }
170
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,SAAS;IACxB,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;IAElB,kEAAkE;IAClE,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACt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;AAMD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,qCAAqC;IACrC,GAAG,EAAE,eAAe,CAAC;IAErB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAMD;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @module @cas-system/nextjs-cas-client/types
3
+ * @description Core TypeScript type definitions for the CAS Client SDK.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@cas-system/nextjs-cas-client",
3
+ "version": "1.0.0",
4
+ "description": "Next.js CAS (Central Authentication System) Client SDK \u2014 App Router, Server Components, Middleware, and Client Hooks",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ },
14
+ "./server": {
15
+ "types": "./dist/server/index.d.ts",
16
+ "import": "./dist/server/index.mjs",
17
+ "require": "./dist/server/index.js"
18
+ },
19
+ "./middleware": {
20
+ "types": "./dist/middleware.d.ts",
21
+ "import": "./dist/middleware.mjs",
22
+ "require": "./dist/middleware.js"
23
+ },
24
+ "./handlers": {
25
+ "types": "./dist/handlers/index.d.ts",
26
+ "import": "./dist/handlers/index.mjs",
27
+ "require": "./dist/handlers/index.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "README.md"
33
+ ],
34
+ "scripts": {
35
+ "build": "tsc",
36
+ "dev": "tsc --watch",
37
+ "lint": "tsc --noEmit",
38
+ "clean": "rm -rf dist",
39
+ "prepublishOnly": "npm run build"
40
+ },
41
+ "peerDependencies": {
42
+ "next": ">=14",
43
+ "react": ">=18",
44
+ "react-dom": ">=18"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "^22.0.0",
48
+ "@types/react": "^18.0.0",
49
+ "next": "^14.0.0",
50
+ "react": "^18.0.0",
51
+ "react-dom": "^18.0.0",
52
+ "typescript": "^5.0.0"
53
+ },
54
+ "keywords": [
55
+ "nextjs",
56
+ "cas",
57
+ "sso",
58
+ "authentication",
59
+ "central-authentication",
60
+ "app-router",
61
+ "server-components",
62
+ "middleware"
63
+ ],
64
+ "license": "MIT",
65
+ "repository": {
66
+ "type": "git",
67
+ "url": "git+https://github.com/InSol-2021/one-system.git",
68
+ "directory": "packages/nextjs-cas-client"
69
+ },
70
+ "publishConfig": {
71
+ "access": "public"
72
+ }
73
+ }