@peterbud/nuxt-aegis 1.1.0-alpha
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.
- package/README.md +166 -0
- package/dist/module.d.mts +6 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +354 -0
- package/dist/runtime/app/composables/useAuth.d.ts +85 -0
- package/dist/runtime/app/composables/useAuth.js +187 -0
- package/dist/runtime/app/middleware/auth-logged-in.d.ts +16 -0
- package/dist/runtime/app/middleware/auth-logged-in.js +25 -0
- package/dist/runtime/app/middleware/auth-logged-out.d.ts +20 -0
- package/dist/runtime/app/middleware/auth-logged-out.js +17 -0
- package/dist/runtime/app/pages/AuthCallback.d.vue.ts +3 -0
- package/dist/runtime/app/pages/AuthCallback.vue +92 -0
- package/dist/runtime/app/pages/AuthCallback.vue.d.ts +3 -0
- package/dist/runtime/app/plugins/api.client.d.ts +11 -0
- package/dist/runtime/app/plugins/api.client.js +92 -0
- package/dist/runtime/app/plugins/api.server.d.ts +13 -0
- package/dist/runtime/app/plugins/api.server.js +28 -0
- package/dist/runtime/app/plugins/ssr-state.server.d.ts +2 -0
- package/dist/runtime/app/plugins/ssr-state.server.js +13 -0
- package/dist/runtime/app/router.options.d.ts +12 -0
- package/dist/runtime/app/router.options.js +11 -0
- package/dist/runtime/app/utils/logger.d.ts +18 -0
- package/dist/runtime/app/utils/logger.js +48 -0
- package/dist/runtime/app/utils/redirectValidation.d.ts +18 -0
- package/dist/runtime/app/utils/redirectValidation.js +21 -0
- package/dist/runtime/app/utils/routeMatching.d.ts +13 -0
- package/dist/runtime/app/utils/routeMatching.js +10 -0
- package/dist/runtime/app/utils/tokenStore.d.ts +24 -0
- package/dist/runtime/app/utils/tokenStore.js +14 -0
- package/dist/runtime/app/utils/tokenUtils.d.ts +17 -0
- package/dist/runtime/app/utils/tokenUtils.js +4 -0
- package/dist/runtime/server/middleware/auth.d.ts +6 -0
- package/dist/runtime/server/middleware/auth.js +82 -0
- package/dist/runtime/server/plugins/ssr-auth.d.ts +7 -0
- package/dist/runtime/server/plugins/ssr-auth.js +82 -0
- package/dist/runtime/server/providers/auth0.d.ts +12 -0
- package/dist/runtime/server/providers/auth0.js +57 -0
- package/dist/runtime/server/providers/github.d.ts +12 -0
- package/dist/runtime/server/providers/github.js +44 -0
- package/dist/runtime/server/providers/google.d.ts +12 -0
- package/dist/runtime/server/providers/google.js +46 -0
- package/dist/runtime/server/providers/mock.d.ts +37 -0
- package/dist/runtime/server/providers/mock.js +129 -0
- package/dist/runtime/server/providers/oauthBase.d.ts +72 -0
- package/dist/runtime/server/providers/oauthBase.js +183 -0
- package/dist/runtime/server/routes/impersonate.post.d.ts +21 -0
- package/dist/runtime/server/routes/impersonate.post.js +68 -0
- package/dist/runtime/server/routes/logout.post.d.ts +9 -0
- package/dist/runtime/server/routes/logout.post.js +24 -0
- package/dist/runtime/server/routes/me.get.d.ts +6 -0
- package/dist/runtime/server/routes/me.get.js +11 -0
- package/dist/runtime/server/routes/mock/authorize.get.d.ts +29 -0
- package/dist/runtime/server/routes/mock/authorize.get.js +103 -0
- package/dist/runtime/server/routes/mock/token.post.d.ts +31 -0
- package/dist/runtime/server/routes/mock/token.post.js +88 -0
- package/dist/runtime/server/routes/mock/userinfo.get.d.ts +27 -0
- package/dist/runtime/server/routes/mock/userinfo.get.js +59 -0
- package/dist/runtime/server/routes/password/change.post.d.ts +4 -0
- package/dist/runtime/server/routes/password/change.post.js +108 -0
- package/dist/runtime/server/routes/password/login-verify.get.d.ts +2 -0
- package/dist/runtime/server/routes/password/login-verify.get.js +79 -0
- package/dist/runtime/server/routes/password/login.post.d.ts +4 -0
- package/dist/runtime/server/routes/password/login.post.js +66 -0
- package/dist/runtime/server/routes/password/register-verify.get.d.ts +2 -0
- package/dist/runtime/server/routes/password/register-verify.get.js +86 -0
- package/dist/runtime/server/routes/password/register.post.d.ts +4 -0
- package/dist/runtime/server/routes/password/register.post.js +87 -0
- package/dist/runtime/server/routes/password/reset-complete.post.d.ts +4 -0
- package/dist/runtime/server/routes/password/reset-complete.post.js +75 -0
- package/dist/runtime/server/routes/password/reset-request.post.d.ts +5 -0
- package/dist/runtime/server/routes/password/reset-request.post.js +52 -0
- package/dist/runtime/server/routes/password/reset-verify.get.d.ts +2 -0
- package/dist/runtime/server/routes/password/reset-verify.get.js +50 -0
- package/dist/runtime/server/routes/refresh.post.d.ts +8 -0
- package/dist/runtime/server/routes/refresh.post.js +102 -0
- package/dist/runtime/server/routes/token.post.d.ts +28 -0
- package/dist/runtime/server/routes/token.post.js +90 -0
- package/dist/runtime/server/routes/unimpersonate.post.d.ts +16 -0
- package/dist/runtime/server/routes/unimpersonate.post.js +65 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/runtime/server/utils/auth.d.ts +94 -0
- package/dist/runtime/server/utils/auth.js +54 -0
- package/dist/runtime/server/utils/authCodeStore.d.ts +137 -0
- package/dist/runtime/server/utils/authCodeStore.js +123 -0
- package/dist/runtime/server/utils/cookies.d.ts +15 -0
- package/dist/runtime/server/utils/cookies.js +23 -0
- package/dist/runtime/server/utils/customClaims.d.ts +37 -0
- package/dist/runtime/server/utils/customClaims.js +45 -0
- package/dist/runtime/server/utils/handler.d.ts +77 -0
- package/dist/runtime/server/utils/handler.js +7 -0
- package/dist/runtime/server/utils/impersonation.d.ts +48 -0
- package/dist/runtime/server/utils/impersonation.js +259 -0
- package/dist/runtime/server/utils/jwt.d.ts +24 -0
- package/dist/runtime/server/utils/jwt.js +77 -0
- package/dist/runtime/server/utils/logger.d.ts +18 -0
- package/dist/runtime/server/utils/logger.js +49 -0
- package/dist/runtime/server/utils/magicCodeStore.d.ts +27 -0
- package/dist/runtime/server/utils/magicCodeStore.js +66 -0
- package/dist/runtime/server/utils/mockCodeStore.d.ts +89 -0
- package/dist/runtime/server/utils/mockCodeStore.js +71 -0
- package/dist/runtime/server/utils/password.d.ts +33 -0
- package/dist/runtime/server/utils/password.js +48 -0
- package/dist/runtime/server/utils/refreshToken.d.ts +74 -0
- package/dist/runtime/server/utils/refreshToken.js +108 -0
- package/dist/runtime/server/utils/resetSessionStore.d.ts +12 -0
- package/dist/runtime/server/utils/resetSessionStore.js +29 -0
- package/dist/runtime/tasks/cleanup/magic-codes.d.ts +10 -0
- package/dist/runtime/tasks/cleanup/magic-codes.js +79 -0
- package/dist/runtime/tasks/cleanup/refresh-tokens.d.ts +10 -0
- package/dist/runtime/tasks/cleanup/refresh-tokens.js +55 -0
- package/dist/runtime/tasks/cleanup/reset-sessions.d.ts +8 -0
- package/dist/runtime/tasks/cleanup/reset-sessions.js +45 -0
- package/dist/runtime/types/augmentation.d.ts +73 -0
- package/dist/runtime/types/augmentation.js +0 -0
- package/dist/runtime/types/authCode.d.ts +60 -0
- package/dist/runtime/types/authCode.js +0 -0
- package/dist/runtime/types/callbacks.d.ts +54 -0
- package/dist/runtime/types/callbacks.js +0 -0
- package/dist/runtime/types/config.d.ts +129 -0
- package/dist/runtime/types/config.js +0 -0
- package/dist/runtime/types/hooks.d.ts +118 -0
- package/dist/runtime/types/hooks.js +0 -0
- package/dist/runtime/types/index.d.ts +13 -0
- package/dist/runtime/types/index.js +1 -0
- package/dist/runtime/types/providers.d.ts +212 -0
- package/dist/runtime/types/providers.js +0 -0
- package/dist/runtime/types/refresh.d.ts +61 -0
- package/dist/runtime/types/refresh.js +0 -0
- package/dist/runtime/types/routes.d.ts +30 -0
- package/dist/runtime/types/routes.js +0 -0
- package/dist/runtime/types/token.d.ts +182 -0
- package/dist/runtime/types/token.js +0 -0
- package/dist/types.d.mts +7 -0
- package/package.json +80 -0
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nuxt Aegis Type Definitions
|
|
3
|
+
* Main barrel file for all type exports
|
|
4
|
+
*/
|
|
5
|
+
import './augmentations.js';
|
|
6
|
+
export type { TokenPayload, TokenConfig, RefreshTokenData, RefreshResponse, ClaimsValidationConfig, CustomClaimsCallback, ImpersonationContext, CustomTokenClaims, ExtractClaims, } from './token.js';
|
|
7
|
+
export type { OAuthProviderConfig, GoogleProviderConfig, MicrosoftProviderConfig, GithubProviderConfig, Auth0ProviderConfig, MockProviderConfig, CustomProviderConfig, OAuthConfig, } from './providers.js';
|
|
8
|
+
export type { CookieConfig, TokenRefreshConfig, EncryptionConfig, StorageConfig, } from './refresh.js';
|
|
9
|
+
export type { AuthCodeData, TokenExchangeRequest, TokenExchangeResponse, AuthCodeConfig, } from './authCode.js';
|
|
10
|
+
export type { NitroAegisAuth, NuxtAegisRouteRules, ClientMiddlewareConfig, } from './routes.js';
|
|
11
|
+
export type { OnError, OnUserInfo, OnSuccess, OnSuccessParams, } from './callbacks.js';
|
|
12
|
+
export type { UserInfoHookPayload, SuccessHookPayload, ImpersonateCheckPayload, ImpersonateFetchTargetPayload, ImpersonateStartPayload, ImpersonateEndPayload, } from './hooks.js';
|
|
13
|
+
export type { RedirectConfig, EndpointConfig, NuxtAegisRuntimeConfig, ModuleOptions, LoggingConfig, ImpersonationConfig, } from './config.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./augmentations";
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import type { CustomClaimsCallback, OnError, OnUserInfo, OnSuccess } from './index.js';
|
|
2
|
+
/**
|
|
3
|
+
* OAuth provider configuration types
|
|
4
|
+
* Defines configuration interfaces for all supported OAuth providers
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Base OAuth provider configuration
|
|
8
|
+
*/
|
|
9
|
+
export interface OAuthProviderConfig {
|
|
10
|
+
/** OAuth client ID from the provider */
|
|
11
|
+
clientId: string;
|
|
12
|
+
/** OAuth client secret from the provider */
|
|
13
|
+
clientSecret: string;
|
|
14
|
+
/** OAuth scopes to request from the provider */
|
|
15
|
+
scopes?: string[];
|
|
16
|
+
/** Authorization endpoint URL (override provider default) */
|
|
17
|
+
authorizeUrl?: string;
|
|
18
|
+
/** Token endpoint URL (override provider default) */
|
|
19
|
+
tokenUrl?: string;
|
|
20
|
+
/** User info endpoint URL (override provider default) */
|
|
21
|
+
userInfoUrl?: string;
|
|
22
|
+
/** Redirect URI for OAuth callback (defaults to authPath + '/providers/[provider]') */
|
|
23
|
+
redirectUri?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Custom query parameters to append to the authorization URL
|
|
26
|
+
*
|
|
27
|
+
* These parameters will be included when redirecting to the OAuth provider's authorization endpoint.
|
|
28
|
+
* Custom parameters override default parameters, but critical OAuth parameters (client_id, redirect_uri,
|
|
29
|
+
* code, grant_type) are protected and cannot be overridden for security reasons.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* // Google-specific parameters
|
|
33
|
+
* authorizationParams: {
|
|
34
|
+
* access_type: 'offline', // Request refresh token
|
|
35
|
+
* prompt: 'consent', // Force consent screen
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* // Auth0-specific parameters
|
|
40
|
+
* authorizationParams: {
|
|
41
|
+
* prompt: 'login', // Force login screen
|
|
42
|
+
* screen_hint: 'signup', // Show signup page
|
|
43
|
+
* }
|
|
44
|
+
*/
|
|
45
|
+
authorizationParams?: Record<string, string>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Google OAuth provider configuration
|
|
49
|
+
*/
|
|
50
|
+
export interface GoogleProviderConfig extends Partial<OAuthProviderConfig> {
|
|
51
|
+
/** Google OAuth client ID */
|
|
52
|
+
clientId: string;
|
|
53
|
+
/** Google OAuth client secret */
|
|
54
|
+
clientSecret: string;
|
|
55
|
+
/** Google OAuth scopes (default: ['openid', 'profile', 'email']) */
|
|
56
|
+
scopes?: string[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Microsoft OAuth provider configuration
|
|
60
|
+
*/
|
|
61
|
+
export interface MicrosoftProviderConfig extends Partial<OAuthProviderConfig> {
|
|
62
|
+
/** Microsoft OAuth client ID */
|
|
63
|
+
clientId: string;
|
|
64
|
+
/** Microsoft OAuth client secret */
|
|
65
|
+
clientSecret: string;
|
|
66
|
+
/** Microsoft tenant ID or 'common', 'organizations', 'consumers' (default: 'common') */
|
|
67
|
+
tenant?: string;
|
|
68
|
+
/** Microsoft OAuth scopes (default: ['openid', 'profile', 'email']) */
|
|
69
|
+
scopes?: string[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* GitHub OAuth provider configuration
|
|
73
|
+
*/
|
|
74
|
+
export interface GithubProviderConfig extends Partial<OAuthProviderConfig> {
|
|
75
|
+
/** GitHub OAuth client ID */
|
|
76
|
+
clientId: string;
|
|
77
|
+
/** GitHub OAuth client secret */
|
|
78
|
+
clientSecret: string;
|
|
79
|
+
/** GitHub OAuth scopes (default: ['user:email']) */
|
|
80
|
+
scopes?: string[];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Auth0 OAuth provider configuration
|
|
84
|
+
*/
|
|
85
|
+
export interface Auth0ProviderConfig extends Partial<OAuthProviderConfig> {
|
|
86
|
+
/** Auth0 OAuth client ID */
|
|
87
|
+
clientId: string;
|
|
88
|
+
/** Auth0 OAuth client secret */
|
|
89
|
+
clientSecret: string;
|
|
90
|
+
/** Auth0 domain (e.g., 'your-tenant.auth0.com' or 'your-tenant.us.auth0.com') */
|
|
91
|
+
domain?: string;
|
|
92
|
+
/** Auth0 OAuth scopes (default: ['openid', 'profile', 'email']) */
|
|
93
|
+
scopes?: string[];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Password provider configuration
|
|
97
|
+
*/
|
|
98
|
+
export interface PasswordProviderConfig {
|
|
99
|
+
/** Magic code time-to-live in seconds (default: 600 = 10 minutes) */
|
|
100
|
+
magicCodeTTL?: number;
|
|
101
|
+
/** Maximum magic code verification attempts (default: 5) */
|
|
102
|
+
magicCodeMaxAttempts?: number;
|
|
103
|
+
/** Password hashing rounds (default: 12) */
|
|
104
|
+
passwordHashRounds?: number;
|
|
105
|
+
/** Password policy configuration */
|
|
106
|
+
passwordPolicy?: {
|
|
107
|
+
/** Minimum password length (default: 8) */
|
|
108
|
+
minLength?: number;
|
|
109
|
+
/** Require uppercase letter (default: true) */
|
|
110
|
+
requireUppercase?: boolean;
|
|
111
|
+
/** Require lowercase letter (default: true) */
|
|
112
|
+
requireLowercase?: boolean;
|
|
113
|
+
/** Require number (default: true) */
|
|
114
|
+
requireNumber?: boolean;
|
|
115
|
+
/** Require special character (default: false) */
|
|
116
|
+
requireSpecial?: boolean;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Password user interface
|
|
121
|
+
*/
|
|
122
|
+
export interface PasswordUser {
|
|
123
|
+
/** User ID (optional) */
|
|
124
|
+
id?: string;
|
|
125
|
+
/** User email */
|
|
126
|
+
email: string;
|
|
127
|
+
/** Hashed password */
|
|
128
|
+
hashedPassword: string;
|
|
129
|
+
/** Additional user properties */
|
|
130
|
+
[key: string]: unknown;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Mock provider configuration (for testing)
|
|
134
|
+
*/
|
|
135
|
+
export interface MockProviderConfig extends Partial<OAuthProviderConfig> {
|
|
136
|
+
/** Mock OAuth client ID (required, can be any string) */
|
|
137
|
+
clientId: string;
|
|
138
|
+
/** Mock OAuth client secret (required, can be any string) */
|
|
139
|
+
clientSecret: string;
|
|
140
|
+
/**
|
|
141
|
+
* Mock user personas for testing different user scenarios
|
|
142
|
+
* Each key is a user identifier, value contains user profile data
|
|
143
|
+
* Required fields: sub (subject), email, name
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* mockUsers: {
|
|
147
|
+
* admin: {
|
|
148
|
+
* sub: 'mock-user-admin',
|
|
149
|
+
* email: 'admin@example.com',
|
|
150
|
+
* name: 'Admin User',
|
|
151
|
+
* role: 'admin',
|
|
152
|
+
* },
|
|
153
|
+
* user: {
|
|
154
|
+
* sub: 'mock-user-001',
|
|
155
|
+
* email: 'user@example.com',
|
|
156
|
+
* name: 'Regular User',
|
|
157
|
+
* },
|
|
158
|
+
* }
|
|
159
|
+
*/
|
|
160
|
+
mockUsers: Record<string, {
|
|
161
|
+
/** Subject identifier (required) */
|
|
162
|
+
sub: string;
|
|
163
|
+
/** User email (required) */
|
|
164
|
+
email: string;
|
|
165
|
+
/** User display name (required) */
|
|
166
|
+
name: string;
|
|
167
|
+
/** Additional custom claims */
|
|
168
|
+
[key: string]: unknown;
|
|
169
|
+
}>;
|
|
170
|
+
/**
|
|
171
|
+
* Default user to return when no ?user= parameter specified
|
|
172
|
+
* Must match a key in mockUsers
|
|
173
|
+
*/
|
|
174
|
+
defaultUser?: string;
|
|
175
|
+
/**
|
|
176
|
+
* Allow mock provider in production (NOT RECOMMENDED)
|
|
177
|
+
* Default: false
|
|
178
|
+
* @deprecated For testing purposes only - never use in production
|
|
179
|
+
*/
|
|
180
|
+
enableInProduction?: boolean;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Custom OAuth provider configuration
|
|
184
|
+
*/
|
|
185
|
+
export interface CustomProviderConfig extends OAuthProviderConfig {
|
|
186
|
+
/** Unique name identifier for the custom provider */
|
|
187
|
+
name: string;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* OAuth configuration wrapper
|
|
191
|
+
*/
|
|
192
|
+
export interface OAuthConfig<TConfig> {
|
|
193
|
+
config?: Partial<TConfig>;
|
|
194
|
+
onError?: OnError;
|
|
195
|
+
/**
|
|
196
|
+
* Custom claims to add to the generated JWT
|
|
197
|
+
* Can be a static object or a callback function that receives user and tokens
|
|
198
|
+
*/
|
|
199
|
+
customClaims?: Record<string, string | number | boolean | Array<string | number | boolean> | null> | CustomClaimsCallback;
|
|
200
|
+
/**
|
|
201
|
+
* User information transformation hook (provider-level)
|
|
202
|
+
* Called after fetching user info from the provider, before storing it
|
|
203
|
+
* Allows provider-specific user object shaping
|
|
204
|
+
*/
|
|
205
|
+
onUserInfo?: OnUserInfo;
|
|
206
|
+
/**
|
|
207
|
+
* Success hook (provider-level)
|
|
208
|
+
* Called after successful authentication, before generating authorization CODE
|
|
209
|
+
* Use for side effects like database storage
|
|
210
|
+
*/
|
|
211
|
+
onSuccess?: OnSuccess;
|
|
212
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token refresh and cookie configuration types
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Refresh cookie configuration
|
|
6
|
+
*/
|
|
7
|
+
export interface CookieConfig {
|
|
8
|
+
/** Name of the refresh cookie (default: 'nuxt-aegis-refresh') */
|
|
9
|
+
cookieName?: string;
|
|
10
|
+
/** Refresh cookie max age in seconds (default: 604800 - 7 days) */
|
|
11
|
+
maxAge?: number;
|
|
12
|
+
/** Enable secure flag for cookies (default: true in production) */
|
|
13
|
+
secure?: boolean;
|
|
14
|
+
/** SameSite cookie attribute (default: 'lax') */
|
|
15
|
+
sameSite?: 'strict' | 'lax' | 'none';
|
|
16
|
+
/** HttpOnly flag for cookies (default: true) */
|
|
17
|
+
httpOnly?: boolean;
|
|
18
|
+
/** Cookie path (default: '/') */
|
|
19
|
+
path?: string;
|
|
20
|
+
/** Cookie domain (optional) */
|
|
21
|
+
domain?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Encryption configuration for refresh token storage
|
|
25
|
+
*/
|
|
26
|
+
export interface EncryptionConfig {
|
|
27
|
+
/** SC-16: Enable encryption-at-rest for user data (default: false) */
|
|
28
|
+
enabled?: boolean;
|
|
29
|
+
/** SC-18: Encryption key (loaded from environment variable) */
|
|
30
|
+
key?: string;
|
|
31
|
+
/** SC-17: Encryption algorithm (default: 'aes-256-gcm') */
|
|
32
|
+
algorithm?: 'aes-256-gcm';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Storage configuration for refresh tokens
|
|
36
|
+
*/
|
|
37
|
+
export interface StorageConfig {
|
|
38
|
+
/** RS-10: Storage driver to use (default: 'fs' for filesystem) */
|
|
39
|
+
driver?: 'fs' | 'redis' | 'memory';
|
|
40
|
+
/** Key prefix for refresh tokens in storage (default: 'refresh:') */
|
|
41
|
+
prefix?: string;
|
|
42
|
+
/** Base path for filesystem storage (default: './.data/refresh-tokens') */
|
|
43
|
+
base?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Token refresh configuration
|
|
47
|
+
*/
|
|
48
|
+
export interface TokenRefreshConfig {
|
|
49
|
+
/** Enable automatic token refresh (default: true) */
|
|
50
|
+
enabled?: boolean;
|
|
51
|
+
/** Automatically refresh tokens in the background (default: true) */
|
|
52
|
+
automaticRefresh?: boolean;
|
|
53
|
+
/** Refresh token cookie configuration */
|
|
54
|
+
cookie?: CookieConfig;
|
|
55
|
+
/** Encryption configuration for stored user data */
|
|
56
|
+
encryption?: EncryptionConfig;
|
|
57
|
+
/** Storage configuration */
|
|
58
|
+
storage?: StorageConfig;
|
|
59
|
+
/** Token lifetime for server-generated access tokens during SSR (default: '5m') */
|
|
60
|
+
ssrTokenExpiry?: string;
|
|
61
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route protection configuration types
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Authentication requirement for Nitro route rules
|
|
6
|
+
* - true | 'required' | 'protected': Route requires authentication
|
|
7
|
+
* - false | 'public' | 'skip': Route is public and skips authentication
|
|
8
|
+
*/
|
|
9
|
+
export type NitroAegisAuth = boolean | 'required' | 'protected' | 'public' | 'skip';
|
|
10
|
+
/**
|
|
11
|
+
* Nuxt Aegis route rules configuration
|
|
12
|
+
*/
|
|
13
|
+
export interface NuxtAegisRouteRules {
|
|
14
|
+
auth?: NitroAegisAuth;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Client-side middleware configuration for route protection
|
|
18
|
+
*/
|
|
19
|
+
export interface ClientMiddlewareConfig {
|
|
20
|
+
/** Enable client-side route protection middleware (default: false) */
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
/** Register middleware globally for all routes (default: false) */
|
|
23
|
+
global?: boolean;
|
|
24
|
+
/** Redirect destination for unauthenticated users (required when enabled) */
|
|
25
|
+
redirectTo: string;
|
|
26
|
+
/** Redirect destination for authenticated users on logged-out pages (required when enabled) */
|
|
27
|
+
loggedOutRedirectTo: string;
|
|
28
|
+
/** Array of route patterns excluded from authentication (glob patterns supported) */
|
|
29
|
+
publicRoutes?: string[];
|
|
30
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token-related type definitions
|
|
3
|
+
* Handles JWT tokens, payloads, and token validation
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Impersonation context stored in JWT
|
|
7
|
+
* Contains essential information about the original user when impersonating
|
|
8
|
+
*/
|
|
9
|
+
export interface ImpersonationContext {
|
|
10
|
+
/** Original user ID (sub) who is performing the impersonation */
|
|
11
|
+
originalUserId: string;
|
|
12
|
+
/** Original user email */
|
|
13
|
+
originalUserEmail?: string;
|
|
14
|
+
/** Original user name */
|
|
15
|
+
originalUserName?: string;
|
|
16
|
+
/** Timestamp when impersonation started */
|
|
17
|
+
impersonatedAt: string;
|
|
18
|
+
/** Optional reason for impersonation (debugging, support, etc.) */
|
|
19
|
+
reason?: string;
|
|
20
|
+
/** Original user's complete claims (role, permissions, etc.) for restoration */
|
|
21
|
+
originalClaims?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* JWT Token payload interface
|
|
25
|
+
* Represents the decoded JWT token structure with standard and custom claims
|
|
26
|
+
* This is what gets stored in the JWT and attached to event.context.user
|
|
27
|
+
*/
|
|
28
|
+
export interface TokenPayload {
|
|
29
|
+
/** Subject identifier (user ID) - required claim */
|
|
30
|
+
sub: string;
|
|
31
|
+
/** User email address */
|
|
32
|
+
email?: string;
|
|
33
|
+
/** User full name */
|
|
34
|
+
name?: string;
|
|
35
|
+
/**
|
|
36
|
+
* User profile picture URL.
|
|
37
|
+
* Pay attention if it's a base64 string image, it can create huge payloads
|
|
38
|
+
* Better to use a URL pointing to the image location or leave it empty
|
|
39
|
+
*/
|
|
40
|
+
picture?: string;
|
|
41
|
+
/** Provider name (e.g., 'google', 'github', 'microsoft', 'auth0', 'password', 'mock') */
|
|
42
|
+
provider?: string;
|
|
43
|
+
/** Issuer claim - identifies who issued the token */
|
|
44
|
+
iss?: string;
|
|
45
|
+
/** Audience claim - identifies the recipients of the token */
|
|
46
|
+
aud?: string | string[];
|
|
47
|
+
/** Issued at timestamp - when the token was created */
|
|
48
|
+
iat?: number;
|
|
49
|
+
/** Expiration timestamp - when the token expires */
|
|
50
|
+
exp?: number;
|
|
51
|
+
/** Impersonation context if this token represents an impersonated session */
|
|
52
|
+
impersonation?: ImpersonationContext;
|
|
53
|
+
/** Additional custom claims */
|
|
54
|
+
[key: string]: unknown;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Refresh token stored data interface
|
|
58
|
+
* Represents the data stored alongside a refresh token
|
|
59
|
+
* on the server side for validation and management
|
|
60
|
+
*/
|
|
61
|
+
export interface RefreshTokenData {
|
|
62
|
+
/** Subject identifier, links the token back to the specific user account */
|
|
63
|
+
sub: string;
|
|
64
|
+
/** Timestamp when the refresh token expires */
|
|
65
|
+
expiresAt: number;
|
|
66
|
+
/** Allows for immediate revocation if the user logs out, changes a password, or a security event occurs */
|
|
67
|
+
isRevoked: boolean;
|
|
68
|
+
/** Hash of the previous refresh token for rotation tracking */
|
|
69
|
+
previousTokenHash?: string;
|
|
70
|
+
/** Complete OAuth provider user data - NOT the JWT payload. This is the full user object from the provider (Google, GitHub, etc.) */
|
|
71
|
+
providerUserInfo: Record<string, unknown>;
|
|
72
|
+
/** Provider name for dynamic custom claims generation during refresh (e.g., 'google', 'github', 'microsoft', 'auth0') */
|
|
73
|
+
provider: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Response from token refresh operation
|
|
77
|
+
*/
|
|
78
|
+
export interface RefreshResponse {
|
|
79
|
+
success: boolean;
|
|
80
|
+
message: string;
|
|
81
|
+
accessToken?: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Token configuration
|
|
85
|
+
*/
|
|
86
|
+
export interface TokenConfig {
|
|
87
|
+
/** JWT secret key */
|
|
88
|
+
secret: string;
|
|
89
|
+
/** JWT expiration time (in seconds or as a string) */
|
|
90
|
+
expiresIn?: string | number;
|
|
91
|
+
/** JWT algorithm (default: 'HS256') */
|
|
92
|
+
algorithm?: 'HS256' | 'HS384' | 'HS512' | 'RS256' | 'RS384' | 'RS512';
|
|
93
|
+
/** JWT issuer claim */
|
|
94
|
+
issuer?: string;
|
|
95
|
+
/** JWT audience claim */
|
|
96
|
+
audience?: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Claims validation configuration
|
|
100
|
+
*/
|
|
101
|
+
export interface ClaimsValidationConfig {
|
|
102
|
+
/** Required claims that must be present in the JWT */
|
|
103
|
+
requiredClaims?: string[];
|
|
104
|
+
/** Custom claim validation rules */
|
|
105
|
+
customRules?: Record<string, (value: unknown) => boolean>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* JSON-compatible value type for JWT custom claims
|
|
109
|
+
* Supports primitives, arrays, and one level of object nesting
|
|
110
|
+
*/
|
|
111
|
+
export type JSONValue = string | number | boolean | null | undefined | string[] | number[] | {
|
|
112
|
+
[key: string]: string | number | boolean | null | undefined | string[] | number[];
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Helper type for creating custom token payloads with type safety
|
|
116
|
+
*
|
|
117
|
+
* Extends TokenPayload with custom claims while ensuring type safety.
|
|
118
|
+
* Prevents overriding standard JWT claims and ensures all custom claims
|
|
119
|
+
* are JSON-serializable.
|
|
120
|
+
*
|
|
121
|
+
* @template T - Record of custom claims to add to the token payload
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* // Define your custom claims
|
|
126
|
+
* type AppTokenPayload = CustomTokenClaims<{
|
|
127
|
+
* role: string
|
|
128
|
+
* permissions: string[]
|
|
129
|
+
* organizationId: string
|
|
130
|
+
* }>
|
|
131
|
+
*
|
|
132
|
+
* // Use with useAuth
|
|
133
|
+
* const { user } = useAuth<AppTokenPayload>()
|
|
134
|
+
* console.log(user.value?.role) // Type-safe access
|
|
135
|
+
* ```
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* // With nested objects (one level)
|
|
140
|
+
* type AppTokenPayload = CustomTokenClaims<{
|
|
141
|
+
* role: string
|
|
142
|
+
* metadata: {
|
|
143
|
+
* tenantId: string
|
|
144
|
+
* plan: string
|
|
145
|
+
* }
|
|
146
|
+
* }>
|
|
147
|
+
* ```
|
|
148
|
+
*
|
|
149
|
+
* @warning Never include sensitive data like passwords, API keys, or secrets in JWT tokens
|
|
150
|
+
* @warning Keep token payloads small (< 1KB recommended) for performance
|
|
151
|
+
*/
|
|
152
|
+
export type CustomTokenClaims<T extends Record<string, JSONValue>> = TokenPayload & T;
|
|
153
|
+
/**
|
|
154
|
+
* Utility type to extract only custom claims from a token payload
|
|
155
|
+
*
|
|
156
|
+
* Removes all standard TokenPayload fields, leaving only your custom claims.
|
|
157
|
+
* Useful for type composition and claim validation.
|
|
158
|
+
*
|
|
159
|
+
* @template T - A token payload type extending TokenPayload
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* type AppTokenPayload = CustomTokenClaims<{
|
|
164
|
+
* role: string
|
|
165
|
+
* permissions: string[]
|
|
166
|
+
* }>
|
|
167
|
+
*
|
|
168
|
+
* type CustomClaims = ExtractClaims<AppTokenPayload>
|
|
169
|
+
* // Result: { role: string, permissions: string[] }
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export type ExtractClaims<T extends TokenPayload> = Omit<T, keyof TokenPayload>;
|
|
173
|
+
/**
|
|
174
|
+
* Custom claims callback function
|
|
175
|
+
* Receives the full OAuth provider user data and tokens
|
|
176
|
+
* Returns claims to add to the JWT (must be JWT-compatible types)
|
|
177
|
+
*
|
|
178
|
+
* @param providerUserInfo - Complete user object from OAuth provider
|
|
179
|
+
* @param tokens - OAuth tokens from the provider
|
|
180
|
+
* @returns Record of custom claims to add to the JWT
|
|
181
|
+
*/
|
|
182
|
+
export type CustomClaimsCallback<TProviderUserInfo = any, TTokens = any> = (providerUserInfo: TProviderUserInfo, tokens: TTokens) => Record<string, string | number | boolean | Array<string | number | boolean> | null> | Promise<Record<string, string | number | boolean | Array<string | number | boolean> | null>>;
|
|
File without changes
|
package/dist/types.d.mts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@peterbud/nuxt-aegis",
|
|
3
|
+
"version": "1.1.0-alpha",
|
|
4
|
+
"description": "Nuxt module for authentication with JWT token generation and session management.",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/peterbud/nuxt-aegis.git"
|
|
11
|
+
},
|
|
12
|
+
"author": "Peter Budai",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/types.d.mts",
|
|
18
|
+
"import": "./dist/module.mjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"vue",
|
|
23
|
+
"nuxt",
|
|
24
|
+
"authentication",
|
|
25
|
+
"nuxt-module",
|
|
26
|
+
"oauth"
|
|
27
|
+
],
|
|
28
|
+
"main": "./dist/module.mjs",
|
|
29
|
+
"typesVersions": {
|
|
30
|
+
"*": {
|
|
31
|
+
".": [
|
|
32
|
+
"./dist/types.d.mts"
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "nuxt-module-build prepare && nuxt-module-build build",
|
|
41
|
+
"prepack": "nuxt-module-build build",
|
|
42
|
+
"dev": "pnpm run dev:prepare && nuxi dev playground",
|
|
43
|
+
"dev:build": "nuxi build playground",
|
|
44
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
45
|
+
"docs:dev": "pnpm --filter docs docs:dev",
|
|
46
|
+
"release": "pnpm run lint && pnpm run test && pnpm run prepack && changelogen --release && npm publish && git push --follow-tags",
|
|
47
|
+
"lint": "eslint .",
|
|
48
|
+
"lint:fix": "eslint . --fix",
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"test:watch": "vitest watch",
|
|
51
|
+
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@nuxt/kit": "^4.2.1",
|
|
55
|
+
"consola": "^3.4.2",
|
|
56
|
+
"defu": "^6.1.4",
|
|
57
|
+
"jose": "^6.1.3",
|
|
58
|
+
"ufo": "^1.6.1"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@nuxt/devtools": "^3.1.1",
|
|
62
|
+
"@nuxt/eslint-config": "^1.11.0",
|
|
63
|
+
"@nuxt/module-builder": "^1.0.2",
|
|
64
|
+
"@nuxt/schema": "^4.2.1",
|
|
65
|
+
"@nuxt/test-utils": "^3.21.0",
|
|
66
|
+
"@types/node": "latest",
|
|
67
|
+
"changelogen": "^0.6.2",
|
|
68
|
+
"eslint": "^9.39.1",
|
|
69
|
+
"nuxt": "^4.2.1",
|
|
70
|
+
"typescript": "~5.9.3",
|
|
71
|
+
"vitest": "^3.2.4",
|
|
72
|
+
"vue-tsc": "^3.1.5"
|
|
73
|
+
},
|
|
74
|
+
"pnpm": {
|
|
75
|
+
"overrides": {
|
|
76
|
+
"vue-router": "4.4.5"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"packageManager": "pnpm@10.17.1"
|
|
80
|
+
}
|