adminforth 1.3.22 → 1.3.23
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/auth.ts +9 -8
- package/dist/auth.js +4 -4
- package/dist/modules/restApi.js +9 -2
- package/modules/restApi.ts +9 -2
- package/package.json +1 -1
- package/spa/src/views/LoginView.vue +11 -2
- package/types/AdminForthConfig.ts +9 -2
package/auth.ts
CHANGED
|
@@ -30,10 +30,15 @@ class AdminForthAuth {
|
|
|
30
30
|
response.setHeader('Set-Cookie', `adminforth_jwt=; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict; Expires=Thu, 01 Jan 1970 00:00:00 GMT`);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
setAuthCookie({ response, username, pk}: {
|
|
34
|
-
|
|
33
|
+
setAuthCookie({ expireInDays, response, username, pk}: {
|
|
34
|
+
expireInDays?: number,
|
|
35
|
+
response: any,
|
|
36
|
+
username: string,
|
|
37
|
+
pk: string | null
|
|
35
38
|
}) {
|
|
36
|
-
const
|
|
39
|
+
const expiresIn: string = expireInDays ? `${expireInDays}d` : (process.env.ADMINFORTH_AUTH_EXPIRESIN || '24h');
|
|
40
|
+
|
|
41
|
+
const token = this.issueJWT({ username, pk}, 'auth', expiresIn);
|
|
37
42
|
response.setHeader('Set-Cookie', `adminforth_jwt=${token}; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict`);
|
|
38
43
|
}
|
|
39
44
|
|
|
@@ -47,11 +52,8 @@ class AdminForthAuth {
|
|
|
47
52
|
const {name,value,expiry,httpOnly} = payload
|
|
48
53
|
response.setHeader('Set-Cookie', `adminforth_${name}=${value}; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict; Expires=${new Date(Date.now() + expiry).toUTCString() } `);
|
|
49
54
|
}
|
|
50
|
-
|
|
51
55
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
issueJWT(payload: Object, type: string) {
|
|
56
|
+
issueJWT(payload: Object, type: string, expiresIn: string = '24h'): string {
|
|
55
57
|
// read ADMINFORH_SECRET from environment if not drop error
|
|
56
58
|
const secret = process.env.ADMINFORTH_SECRET;
|
|
57
59
|
if (!secret) {
|
|
@@ -59,7 +61,6 @@ class AdminForthAuth {
|
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
// issue JWT token
|
|
62
|
-
const expiresIn = process.env.ADMINFORTH_AUTH_EXPIRESIN || '24h';
|
|
63
64
|
return jwt.sign({...payload, t: type}, secret, { expiresIn });
|
|
64
65
|
}
|
|
65
66
|
|
package/dist/auth.js
CHANGED
|
@@ -30,8 +30,9 @@ class AdminForthAuth {
|
|
|
30
30
|
removeAuthCookie(response) {
|
|
31
31
|
response.setHeader('Set-Cookie', `adminforth_jwt=; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict; Expires=Thu, 01 Jan 1970 00:00:00 GMT`);
|
|
32
32
|
}
|
|
33
|
-
setAuthCookie({ response, username, pk }) {
|
|
34
|
-
const
|
|
33
|
+
setAuthCookie({ expireInDays, response, username, pk }) {
|
|
34
|
+
const expiresIn = expireInDays ? `${expireInDays}d` : (process.env.ADMINFORTH_AUTH_EXPIRESIN || '24h');
|
|
35
|
+
const token = this.issueJWT({ username, pk }, 'auth', expiresIn);
|
|
35
36
|
response.setHeader('Set-Cookie', `adminforth_jwt=${token}; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict`);
|
|
36
37
|
}
|
|
37
38
|
removeCustomCookie({ response, name }) {
|
|
@@ -41,14 +42,13 @@ class AdminForthAuth {
|
|
|
41
42
|
const { name, value, expiry, httpOnly } = payload;
|
|
42
43
|
response.setHeader('Set-Cookie', `adminforth_${name}=${value}; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict; Expires=${new Date(Date.now() + expiry).toUTCString()} `);
|
|
43
44
|
}
|
|
44
|
-
issueJWT(payload, type) {
|
|
45
|
+
issueJWT(payload, type, expiresIn = '24h') {
|
|
45
46
|
// read ADMINFORH_SECRET from environment if not drop error
|
|
46
47
|
const secret = process.env.ADMINFORTH_SECRET;
|
|
47
48
|
if (!secret) {
|
|
48
49
|
throw new Error('ADMINFORTH_SECRET environment not set');
|
|
49
50
|
}
|
|
50
51
|
// issue JWT token
|
|
51
|
-
const expiresIn = process.env.ADMINFORTH_AUTH_EXPIRESIN || '24h';
|
|
52
52
|
return jwt.sign(Object.assign(Object.assign({}, payload), { t: type }), secret, { expiresIn });
|
|
53
53
|
}
|
|
54
54
|
verify(jwtToken_1, mustHaveType_1) {
|
package/dist/modules/restApi.js
CHANGED
|
@@ -44,7 +44,7 @@ export default class AdminForthRestAPI {
|
|
|
44
44
|
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response }) {
|
|
45
45
|
var _b, _c, _d, _e;
|
|
46
46
|
const INVALID_MESSAGE = 'Invalid Username or Password';
|
|
47
|
-
const { username, password } = body;
|
|
47
|
+
const { username, password, rememberMe } = body;
|
|
48
48
|
let adminUser;
|
|
49
49
|
let toReturn = { ok: true, allowedLogin: true };
|
|
50
50
|
// get resource from db
|
|
@@ -93,7 +93,13 @@ export default class AdminForthRestAPI {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
if (toReturn.allowedLogin) {
|
|
96
|
-
|
|
96
|
+
const expireInDays = rememberMe && this.adminforth.config.auth.rememberMeDays;
|
|
97
|
+
this.adminforth.auth.setAuthCookie({
|
|
98
|
+
expireInDays,
|
|
99
|
+
response,
|
|
100
|
+
username,
|
|
101
|
+
pk: userRecord[userResource.columns.find((col) => col.primaryKey).name]
|
|
102
|
+
});
|
|
97
103
|
}
|
|
98
104
|
}
|
|
99
105
|
else {
|
|
@@ -140,6 +146,7 @@ export default class AdminForthRestAPI {
|
|
|
140
146
|
demoCredentials: this.adminforth.config.auth.demoCredentials,
|
|
141
147
|
loginPromptHTML: this.adminforth.config.auth.loginPromptHTML,
|
|
142
148
|
loginPageInjections: this.adminforth.config.customization.loginPageInjections,
|
|
149
|
+
rememberMeDays: this.adminforth.config.auth.rememberMeDays,
|
|
143
150
|
};
|
|
144
151
|
}),
|
|
145
152
|
});
|
package/modules/restApi.ts
CHANGED
|
@@ -63,7 +63,7 @@ export default class AdminForthRestAPI {
|
|
|
63
63
|
handler: async ({ body, response }) => {
|
|
64
64
|
|
|
65
65
|
const INVALID_MESSAGE = 'Invalid Username or Password';
|
|
66
|
-
const { username, password } = body;
|
|
66
|
+
const { username, password, rememberMe } = body;
|
|
67
67
|
let adminUser: AdminUser;
|
|
68
68
|
let toReturn: { ok: boolean, redirectTo?: string, allowedLogin:boolean } = { ok: true, allowedLogin:true};
|
|
69
69
|
|
|
@@ -120,7 +120,13 @@ export default class AdminForthRestAPI {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
if (toReturn.allowedLogin){
|
|
123
|
-
|
|
123
|
+
const expireInDays = rememberMe && this.adminforth.config.auth.rememberMeDays;
|
|
124
|
+
this.adminforth.auth.setAuthCookie({
|
|
125
|
+
expireInDays,
|
|
126
|
+
response,
|
|
127
|
+
username,
|
|
128
|
+
pk: userRecord[userResource.columns.find((col) => col.primaryKey).name]
|
|
129
|
+
});
|
|
124
130
|
}
|
|
125
131
|
} else {
|
|
126
132
|
return { error: INVALID_MESSAGE };
|
|
@@ -172,6 +178,7 @@ export default class AdminForthRestAPI {
|
|
|
172
178
|
demoCredentials: this.adminforth.config.auth.demoCredentials,
|
|
173
179
|
loginPromptHTML: this.adminforth.config.auth.loginPromptHTML,
|
|
174
180
|
loginPageInjections: this.adminforth.config.customization.loginPageInjections,
|
|
181
|
+
rememberMeDays: this.adminforth.config.auth.rememberMeDays,
|
|
175
182
|
};
|
|
176
183
|
},
|
|
177
184
|
});
|
package/package.json
CHANGED
|
@@ -56,9 +56,16 @@
|
|
|
56
56
|
</button>
|
|
57
57
|
</div>
|
|
58
58
|
|
|
59
|
-
<div
|
|
59
|
+
<div v-if="coreStore.config.rememberMeDays"
|
|
60
|
+
class="flex items-start mb-5"
|
|
61
|
+
:title="`Stay logged in for ${coreStore.config.rememberMeDays} days`"
|
|
62
|
+
>
|
|
60
63
|
<div class="flex items-center h-5">
|
|
61
|
-
<input id="remember"
|
|
64
|
+
<input id="remember"
|
|
65
|
+
ref="rememberInput"
|
|
66
|
+
type="checkbox"
|
|
67
|
+
value=""
|
|
68
|
+
class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-blue-300 dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-blue-600 dark:ring-offset-gray-800 dark:focus:ring-offset-gray-800" />
|
|
62
69
|
</div>
|
|
63
70
|
<label for="remember" class="ms-2 text-sm font-medium text-gray-900 dark:text-gray-300">Remember me</label>
|
|
64
71
|
</div>
|
|
@@ -125,6 +132,7 @@ import { useRouter } from 'vue-router';
|
|
|
125
132
|
|
|
126
133
|
const passwordInput = ref(null);
|
|
127
134
|
const usernameInput = ref(null);
|
|
135
|
+
const rememberInput = ref(null);
|
|
128
136
|
|
|
129
137
|
const router = useRouter();
|
|
130
138
|
const inProgress = ref(false);
|
|
@@ -166,6 +174,7 @@ async function login() {
|
|
|
166
174
|
body: {
|
|
167
175
|
username,
|
|
168
176
|
password,
|
|
177
|
+
rememberMe: rememberInput.value.checked,
|
|
169
178
|
}
|
|
170
179
|
});
|
|
171
180
|
inProgress.value = false;
|
|
@@ -239,11 +239,11 @@ export interface IAdminForthDataSourceConnectorConstructor {
|
|
|
239
239
|
|
|
240
240
|
export interface IAdminForthAuth {
|
|
241
241
|
verify(jwt : string, mustHaveType: string, decodeUser?: boolean): Promise<any>;
|
|
242
|
-
issueJWT(payload: Object, type: string): string;
|
|
242
|
+
issueJWT(payload: Object, type: string, expiresIn?: string): string;
|
|
243
243
|
|
|
244
244
|
removeCustomCookie({response, name}: {response: any, name: string}): void;
|
|
245
245
|
|
|
246
|
-
setAuthCookie({response, username, pk,}: {response: any, username: string, pk: string}): void;
|
|
246
|
+
setAuthCookie({expireInDays, response, username, pk,}: {expireInDays?: number, response: any, username: string, pk: string}): void;
|
|
247
247
|
|
|
248
248
|
removeAuthCookie(response: any): void;
|
|
249
249
|
}
|
|
@@ -1178,6 +1178,13 @@ export type AdminForthConfig = {
|
|
|
1178
1178
|
* Any prompt to show users on login. Supports HTML.
|
|
1179
1179
|
*/
|
|
1180
1180
|
loginPromptHTML?: string,
|
|
1181
|
+
|
|
1182
|
+
/**
|
|
1183
|
+
* Remember me days for "Remember Me" checkbox on login page.
|
|
1184
|
+
* If not set or set to null/0/undefined, "Remember Me" checkbox will not be displayed.
|
|
1185
|
+
* If rememberMeDays is set, then users who check "Remember Me" will be staying logged in for this amount of days.
|
|
1186
|
+
*/
|
|
1187
|
+
rememberMeDays?: number,
|
|
1181
1188
|
},
|
|
1182
1189
|
/**
|
|
1183
1190
|
* Array of resources which will be displayed in the admin panel.
|