mbkauthe 3.0.0 → 3.2.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.
- package/README.md +98 -16
- package/docs/api.md +212 -117
- package/docs/db.md +71 -16
- package/docs/env.md +91 -8
- package/index.d.ts +59 -21
- package/lib/config/index.js +48 -1
- package/lib/main.js +27 -1
- package/lib/middleware/index.js +4 -2
- package/lib/routes/auth.js +25 -3
- package/lib/routes/misc.js +29 -17
- package/lib/routes/oauth.js +379 -264
- package/lib/utils/response.js +2 -2
- package/package.json +30 -10
- package/test.spec.js +196 -0
- package/views/2fa.handlebars +2 -2
- package/views/loginmbkauthe.handlebars +35 -5
- package/views/sharedStyles.handlebars +5 -0
- package/views/showmessage.handlebars +27 -1
- package/.env.example +0 -3
- package/.github/PACKAGE.md +0 -17
- package/.github/workflows/codeql.yml +0 -98
- package/.github/workflows/publish.yml +0 -87
package/lib/utils/response.js
CHANGED
|
@@ -2,7 +2,7 @@ import { mbkautheVar, packageJson } from "../config/index.js";
|
|
|
2
2
|
|
|
3
3
|
// Helper function to render error pages consistently
|
|
4
4
|
export const renderError = (res, { code, error, message, page, pagename, details }) => {
|
|
5
|
-
res.status(code);
|
|
5
|
+
res.status(parseInt(code, 10));
|
|
6
6
|
const renderData = {
|
|
7
7
|
layout: false,
|
|
8
8
|
code,
|
|
@@ -18,4 +18,4 @@ export const renderError = (res, { code, error, message, page, pagename, details
|
|
|
18
18
|
if (details !== undefined) renderData.details = details;
|
|
19
19
|
|
|
20
20
|
return res.render("Error/dError.handlebars", renderData);
|
|
21
|
-
};
|
|
21
|
+
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mbkauthe",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "MBKTech's reusable authentication system for Node.js applications.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"dev": "cross-env test=dev nodemon index.js"
|
|
9
|
+
"dev": "cross-env test=dev nodemon index.js",
|
|
10
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
|
11
|
+
"test:watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch"
|
|
10
12
|
},
|
|
11
13
|
"repository": {
|
|
12
14
|
"type": "git",
|
|
@@ -26,12 +28,22 @@
|
|
|
26
28
|
"url": "https://github.com/MIbnEKhalid/mbkauthe/issues"
|
|
27
29
|
},
|
|
28
30
|
"homepage": "https://github.com/MIbnEKhalid/mbkauthe#readme",
|
|
31
|
+
"files": [
|
|
32
|
+
"index.js",
|
|
33
|
+
"index.d.ts",
|
|
34
|
+
"LICENSE",
|
|
35
|
+
"README.md",
|
|
36
|
+
"test.spec.js",
|
|
37
|
+
"docs/",
|
|
38
|
+
"lib/",
|
|
39
|
+
"public/",
|
|
40
|
+
"views/",
|
|
41
|
+
"vercel.json"
|
|
42
|
+
],
|
|
29
43
|
"publishConfig": {
|
|
30
44
|
"registry": "https://registry.npmjs.org/"
|
|
31
45
|
},
|
|
32
46
|
"dependencies": {
|
|
33
|
-
"bcrypt": "^6.0.0",
|
|
34
|
-
"cheerio": "^1.0.0",
|
|
35
47
|
"connect-pg-simple": "^10.0.0",
|
|
36
48
|
"cookie-parser": "^1.4.7",
|
|
37
49
|
"csurf": "^1.2.2",
|
|
@@ -40,19 +52,27 @@
|
|
|
40
52
|
"express-handlebars": "^8.0.1",
|
|
41
53
|
"express-rate-limit": "^7.5.0",
|
|
42
54
|
"express-session": "^1.18.1",
|
|
43
|
-
"marked": "^15.0.11",
|
|
44
55
|
"node-fetch": "^3.3.2",
|
|
45
56
|
"passport": "^0.7.0",
|
|
46
57
|
"passport-github2": "^0.1.12",
|
|
47
|
-
"
|
|
58
|
+
"passport-google-oauth20": "^2.0.0",
|
|
48
59
|
"pg": "^8.14.1",
|
|
49
|
-
"speakeasy": "^2.0.0"
|
|
50
|
-
"url": "^0.11.4"
|
|
60
|
+
"speakeasy": "^2.0.0"
|
|
51
61
|
},
|
|
52
62
|
"devDependencies": {
|
|
53
63
|
"@types/express": "^5.0.6",
|
|
54
|
-
"@types/node": "^22.19.1",
|
|
55
64
|
"cross-env": "^7.0.3",
|
|
56
|
-
"
|
|
65
|
+
"jest": "^30.2.0",
|
|
66
|
+
"nodemon": "^3.1.11",
|
|
67
|
+
"supertest": "^7.1.4"
|
|
68
|
+
},
|
|
69
|
+
"jest": {
|
|
70
|
+
"testEnvironment": "node",
|
|
71
|
+
"testMatch": [
|
|
72
|
+
"**/*.spec.js",
|
|
73
|
+
"**/*.test.js"
|
|
74
|
+
],
|
|
75
|
+
"testTimeout": 10000,
|
|
76
|
+
"transform": {}
|
|
57
77
|
}
|
|
58
78
|
}
|
package/test.spec.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import request from 'supertest';
|
|
2
|
+
|
|
3
|
+
const BASE_URL = "http://localhost:5555";
|
|
4
|
+
|
|
5
|
+
// Helper to get CSRF token and cookies
|
|
6
|
+
const getCSRFTokenAndCookies = async () => {
|
|
7
|
+
const response = await request(BASE_URL).get('/mbkauthe/login');
|
|
8
|
+
const html = response.text;
|
|
9
|
+
const csrfMatch = html.match(/name="_csrf".*?value="([^"]+)"/i) ||
|
|
10
|
+
html.match(/content="([^"]+)".*?name="_csrf"/i);
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
csrfToken: csrfMatch?.[1] || '',
|
|
14
|
+
cookies: response.headers['set-cookie'] || []
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
describe('mbkauthe Routes', () => {
|
|
19
|
+
|
|
20
|
+
describe('Redirect Routes', () => {
|
|
21
|
+
test('GET /login redirects to /mbkauthe/login', async () => {
|
|
22
|
+
const response = await request(BASE_URL)
|
|
23
|
+
.get('/login')
|
|
24
|
+
.redirects(0);
|
|
25
|
+
|
|
26
|
+
expect(response.status).toBe(302);
|
|
27
|
+
expect(response.headers.location).toContain('/mbkauthe/login');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('GET /signin redirects to /mbkauthe/login', async () => {
|
|
31
|
+
const response = await request(BASE_URL)
|
|
32
|
+
.get('/signin')
|
|
33
|
+
.redirects(0);
|
|
34
|
+
|
|
35
|
+
expect(response.status).toBe(302);
|
|
36
|
+
expect(response.headers.location).toContain('/mbkauthe/login');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('Authentication Pages', () => {
|
|
41
|
+
test('GET /mbkauthe/login contains loginUsername input', async () => {
|
|
42
|
+
const response = await request(BASE_URL).get('/mbkauthe/login');
|
|
43
|
+
|
|
44
|
+
expect(response.status).toBe(200);
|
|
45
|
+
expect(response.text).toMatch(/id\s*=\s*["']loginUsername["']/i);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('GET /mbkauthe/2fa contains token input or redirects', async () => {
|
|
49
|
+
const response = await request(BASE_URL)
|
|
50
|
+
.get('/mbkauthe/2fa')
|
|
51
|
+
.redirects(0);
|
|
52
|
+
|
|
53
|
+
if (response.status === 302) {
|
|
54
|
+
expect(response.headers.location).toContain('/mbkauthe/login');
|
|
55
|
+
} else {
|
|
56
|
+
expect(response.status).toBe(200);
|
|
57
|
+
expect(response.text).toMatch(/id\s*=\s*["']token["']/i);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('Info Pages', () => {
|
|
63
|
+
test.each([
|
|
64
|
+
['/mbkauthe/info', 'info page'],
|
|
65
|
+
['/mbkauthe/i', 'info short page'],
|
|
66
|
+
])('GET %s contains CurrentVersion div', async (path, desc) => {
|
|
67
|
+
const response = await request(BASE_URL).get(path);
|
|
68
|
+
|
|
69
|
+
expect(response.status).toBe(200);
|
|
70
|
+
expect(response.text).toMatch(/id\s*=\s*["']CurrentVersion["']/i);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('GET /mbkauthe/ErrorCode contains error-603 div', async () => {
|
|
74
|
+
const response = await request(BASE_URL).get('/mbkauthe/ErrorCode');
|
|
75
|
+
|
|
76
|
+
expect(response.status).toBe(200);
|
|
77
|
+
expect(response.text).toMatch(/id\s*=\s*["']error-603["']/i);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('Static Assets', () => {
|
|
82
|
+
test('GET /mbkauthe/main.js returns JavaScript', async () => {
|
|
83
|
+
const response = await request(BASE_URL).get('/mbkauthe/main.js');
|
|
84
|
+
|
|
85
|
+
expect(response.status).toBe(200);
|
|
86
|
+
expect(response.headers['content-type']).toContain('javascript');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('GET /icon.svg returns SVG content', async () => {
|
|
90
|
+
const response = await request(BASE_URL).get('/icon.svg');
|
|
91
|
+
|
|
92
|
+
expect(response.status).toBe(200);
|
|
93
|
+
expect(response.text || response.body.toString()).toMatch(/<svg|SVG/);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test.each([
|
|
97
|
+
['/favicon.ico', 'favicon'],
|
|
98
|
+
['/icon.ico', 'icon'],
|
|
99
|
+
])('GET %s returns ICO content', async (path, desc) => {
|
|
100
|
+
const response = await request(BASE_URL).get(path);
|
|
101
|
+
expect(response.status).toBe(200);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('GET /mbkauthe/bg.webp returns WEBP content', async () => {
|
|
105
|
+
const response = await request(BASE_URL).get('/mbkauthe/bg.webp');
|
|
106
|
+
|
|
107
|
+
expect(response.status).toBe(200);
|
|
108
|
+
expect(response.headers['content-type']).toContain('image/webp');
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('Protected Routes', () => {
|
|
113
|
+
test('GET /mbkauthe/test responds appropriately', async () => {
|
|
114
|
+
const response = await request(BASE_URL).get('/mbkauthe/test');
|
|
115
|
+
expect([200, 302, 401, 403, 429]).toContain(response.status);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('OAuth Routes', () => {
|
|
120
|
+
test('GET /mbkauthe/api/github/login handles GitHub OAuth', async () => {
|
|
121
|
+
const response = await request(BASE_URL)
|
|
122
|
+
.get('/mbkauthe/api/github/login')
|
|
123
|
+
.redirects(0);
|
|
124
|
+
|
|
125
|
+
expect([200, 302, 403, 500, 429]).toContain(response.status);
|
|
126
|
+
|
|
127
|
+
if (response.status === 302) {
|
|
128
|
+
const location = response.headers.location;
|
|
129
|
+
expect(location).toMatch(/github\.com|login/);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('GET /mbkauthe/api/github/login/callback handles callback', async () => {
|
|
134
|
+
const response = await request(BASE_URL).get('/mbkauthe/api/github/login/callback');
|
|
135
|
+
expect([200, 302, 400, 401, 403, 429]).toContain(response.status);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('GET /mbkauthe/api/google/login handles Google OAuth', async () => {
|
|
139
|
+
const response = await request(BASE_URL)
|
|
140
|
+
.get('/mbkauthe/api/google/login')
|
|
141
|
+
.redirects(0);
|
|
142
|
+
|
|
143
|
+
expect([200, 302, 403, 500, 429]).toContain(response.status);
|
|
144
|
+
|
|
145
|
+
if (response.status === 302) {
|
|
146
|
+
const location = response.headers.location;
|
|
147
|
+
expect(location).toMatch(/accounts\.google\.com|login/);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('GET /mbkauthe/api/google/login/callback handles callback', async () => {
|
|
152
|
+
const response = await request(BASE_URL).get('/mbkauthe/api/google/login/callback');
|
|
153
|
+
expect([200, 302, 400, 401, 403, 429]).toContain(response.status);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('API Endpoints', () => {
|
|
158
|
+
test('POST /mbkauthe/api/login handles login API', async () => {
|
|
159
|
+
const response = await request(BASE_URL)
|
|
160
|
+
.post('/mbkauthe/api/login')
|
|
161
|
+
.send({ username: 'test', password: 'test' });
|
|
162
|
+
|
|
163
|
+
expect([200, 400, 401, 403, 429]).toContain(response.status);
|
|
164
|
+
expect(response.headers['content-type']).toContain('application/json');
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('POST /mbkauthe/api/verify-2fa handles 2FA API', async () => {
|
|
168
|
+
const { csrfToken, cookies } = await getCSRFTokenAndCookies();
|
|
169
|
+
|
|
170
|
+
const response = await request(BASE_URL)
|
|
171
|
+
.post('/mbkauthe/api/verify-2fa')
|
|
172
|
+
.set('Cookie', cookies)
|
|
173
|
+
.send({ token: '123456', _csrf: csrfToken });
|
|
174
|
+
|
|
175
|
+
expect([200, 400, 401, 403, 429]).toContain(response.status);
|
|
176
|
+
expect(response.headers['content-type']).toContain('application/json');
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('POST /mbkauthe/api/terminateAllSessions handles session termination', async () => {
|
|
180
|
+
const { csrfToken, cookies } = await getCSRFTokenAndCookies();
|
|
181
|
+
|
|
182
|
+
const response = await request(BASE_URL)
|
|
183
|
+
.post('/mbkauthe/api/terminateAllSessions')
|
|
184
|
+
.set('Cookie', cookies)
|
|
185
|
+
.send({ _csrf: csrfToken });
|
|
186
|
+
|
|
187
|
+
expect([200, 400, 401, 403, 429]).toContain(response.status);
|
|
188
|
+
|
|
189
|
+
if (response.status === 401) {
|
|
190
|
+
expect(response.headers['content-type']).not.toContain('application/json');
|
|
191
|
+
} else {
|
|
192
|
+
expect(response.headers['content-type']).toContain('application/json');
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
});
|
package/views/2fa.handlebars
CHANGED
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
|
|
41
41
|
<p class="terms-info">
|
|
42
42
|
By logging in, you agree to our
|
|
43
|
-
<a href="https://
|
|
43
|
+
<a href="https://mbktech.org/PrivacyPolicy" target="_blank"
|
|
44
44
|
class="terms-link">Terms & Conditions</a>
|
|
45
45
|
and
|
|
46
|
-
<a href="https://
|
|
46
|
+
<a href="https://mbktech.org/PrivacyPolicy" target="_blank"
|
|
47
47
|
class="terms-link">Privacy Policy</a>.
|
|
48
48
|
</p>
|
|
49
49
|
</form>
|
|
@@ -33,6 +33,11 @@
|
|
|
33
33
|
<i class="fas fa-eye input-icon" id="togglePassword"></i>
|
|
34
34
|
</div>
|
|
35
35
|
|
|
36
|
+
<div class="remember-me">
|
|
37
|
+
<input type="checkbox" id="rememberMe" name="rememberMe">
|
|
38
|
+
<label for="rememberMe">Remember me</label>
|
|
39
|
+
</div>
|
|
40
|
+
|
|
36
41
|
<button type="submit" class="btn-login" id="loginButton">
|
|
37
42
|
<span id="loginButtonText">Login</span>
|
|
38
43
|
</button>
|
|
@@ -48,10 +53,20 @@
|
|
|
48
53
|
</a>
|
|
49
54
|
</div>
|
|
50
55
|
{{/if }}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
{{#if googleLoginEnabled }}
|
|
57
|
+
<div class="social-login">
|
|
58
|
+
{{#unless githubLoginEnabled }}
|
|
59
|
+
<div class="divider">
|
|
60
|
+
<span>or</span>
|
|
61
|
+
</div>
|
|
62
|
+
{{/unless}}
|
|
63
|
+
<!-- Use JS to initiate Google login and pass redirect param to backend -->
|
|
64
|
+
<a type="button" id="googleLoginBtn" class="btn-github">
|
|
65
|
+
<i class="fab fa-google"></i>
|
|
66
|
+
<span>Continue with Google</span>
|
|
67
|
+
</a>
|
|
54
68
|
</div>
|
|
69
|
+
{{/if }}
|
|
55
70
|
|
|
56
71
|
{{#if userLoggedIn }}
|
|
57
72
|
<div class="WarningboxInfo">
|
|
@@ -68,10 +83,10 @@
|
|
|
68
83
|
|
|
69
84
|
<p class="terms-info">
|
|
70
85
|
By logging in, you agree to our
|
|
71
|
-
<a href="https://
|
|
86
|
+
<a href="https://mbktech.org/PrivacyPolicy" target="_blank"
|
|
72
87
|
class="terms-link">Terms & Conditions</a>
|
|
73
88
|
and
|
|
74
|
-
<a href="https://
|
|
89
|
+
<a href="https://mbktech.org/PrivacyPolicy" target="_blank"
|
|
75
90
|
class="terms-link">Privacy Policy</a>.
|
|
76
91
|
</p>
|
|
77
92
|
</form>
|
|
@@ -256,6 +271,21 @@
|
|
|
256
271
|
const githubBtn = document.getElementById('githubLoginBtn');
|
|
257
272
|
if (githubBtn) githubBtn.addEventListener('click', startGithubLogin);
|
|
258
273
|
{{/if }}
|
|
274
|
+
|
|
275
|
+
{{#if googleLoginEnabled }}
|
|
276
|
+
|
|
277
|
+
// Google login: Navigate directly to Google OAuth flow
|
|
278
|
+
async function startGoogleLogin() {
|
|
279
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
280
|
+
const redirect = urlParams.get('redirect') || '{{customURL}}';
|
|
281
|
+
|
|
282
|
+
// Navigate directly to the backend GET endpoint with redirect query
|
|
283
|
+
window.location.href = `/mbkauthe/api/google/login?redirect=${encodeURIComponent(redirect)}`;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const googleBtn = document.getElementById('googleLoginBtn');
|
|
287
|
+
if (googleBtn) googleBtn.addEventListener('click', startGoogleLogin);
|
|
288
|
+
{{/if }}
|
|
259
289
|
</script>
|
|
260
290
|
</body>
|
|
261
291
|
|
|
@@ -8,9 +8,35 @@
|
|
|
8
8
|
</div>
|
|
9
9
|
<script>
|
|
10
10
|
// showMessage("Failed to load the page. Please try again later.", "Error", "404");
|
|
11
|
+
|
|
12
|
+
// Sanitize HTML to prevent XSS while allowing safe HTML tags
|
|
13
|
+
function sanitizeHTML(html) {
|
|
14
|
+
const temp = document.createElement('div');
|
|
15
|
+
temp.textContent = html;
|
|
16
|
+
let sanitized = temp.innerHTML;
|
|
17
|
+
|
|
18
|
+
// Allow only safe HTML tags (no script, iframe, object, embed, etc.)
|
|
19
|
+
const allowedTags = ['b', 'i', 'u', 'strong', 'em', 'br', 'p', 'span', 'div'];
|
|
20
|
+
const tagRegex = /<(\/)?([\w]+)([^>]*)>/gi;
|
|
21
|
+
|
|
22
|
+
sanitized = sanitized.replace(tagRegex, (match, closing, tagName, attributes) => {
|
|
23
|
+
tagName = tagName.toLowerCase();
|
|
24
|
+
if (allowedTags.includes(tagName)) {
|
|
25
|
+
// Remove event handlers and javascript: from attributes
|
|
26
|
+
const safeAttrs = attributes.replace(/on\w+\s*=\s*["'][^"']*["']/gi, '')
|
|
27
|
+
.replace(/javascript:/gi, '');
|
|
28
|
+
return `<${closing || ''}${tagName}${safeAttrs}>`;
|
|
29
|
+
}
|
|
30
|
+
return ''; // Remove disallowed tags
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return sanitized;
|
|
34
|
+
}
|
|
35
|
+
|
|
11
36
|
function showMessage(message, heading, errorCode) {
|
|
12
37
|
document.querySelector(".showmessageWindow h1").innerText = heading;
|
|
13
|
-
|
|
38
|
+
// Sanitize and set innerHTML to allow safe HTML formatting
|
|
39
|
+
document.querySelector(".showmessageWindow p").innerHTML = sanitizeHTML(message);
|
|
14
40
|
|
|
15
41
|
if (errorCode) {
|
|
16
42
|
document.querySelector(".showmessageWindow .error-code").style.display = "block";
|
package/.env.example
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
mbkautheVar={"APP_NAME":"mbkauthe","Main_SECRET_TOKEN": 123,"SESSION_SECRET_KEY":"123","IS_DEPLOYED":"true","LOGIN_DB":"postgres://","MBKAUTH_TWO_FA_ENABLE":"true","COOKIE_EXPIRE_TIME":2,"DOMAIN":"mbktech.org","loginRedirectURL":"/mbkauthe/test","GITHUB_LOGIN_ENABLED":"true","GITHUB_CLIENT_ID":"","GITHUB_CLIENT_SECRET":"","DEVICE_TRUST_DURATION_DAYS":7,"EncPass":"false"}
|
|
2
|
-
|
|
3
|
-
# See docs/env.md for more details
|
package/.github/PACKAGE.md
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# Package Information
|
|
2
|
-
|
|
3
|
-
This package is published on npm: [mbkauthe](https://www.npmjs.com/package/mbkauthe)
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install mbkauthe
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Version
|
|
12
|
-
|
|
13
|
-
Current Version: 1.4.2
|
|
14
|
-
|
|
15
|
-
## Registry
|
|
16
|
-
|
|
17
|
-
Published to: npm Registry (https://registry.npmjs.org/)
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
# For most projects, this workflow file will not need changing; you simply need
|
|
2
|
-
# to commit it to your repository.
|
|
3
|
-
#
|
|
4
|
-
# You may wish to alter this file to override the set of languages analyzed,
|
|
5
|
-
# or to provide custom queries or build logic.
|
|
6
|
-
#
|
|
7
|
-
# ******** NOTE ********
|
|
8
|
-
# We have attempted to detect the languages in your repository. Please check
|
|
9
|
-
# the `language` matrix defined below to confirm you have the correct set of
|
|
10
|
-
# supported CodeQL languages.
|
|
11
|
-
#
|
|
12
|
-
name: "CodeQL Advanced"
|
|
13
|
-
|
|
14
|
-
on:
|
|
15
|
-
push:
|
|
16
|
-
branches: [ "main" ]
|
|
17
|
-
pull_request:
|
|
18
|
-
branches: [ "main" ]
|
|
19
|
-
schedule:
|
|
20
|
-
- cron: '17 1 * * 3'
|
|
21
|
-
|
|
22
|
-
jobs:
|
|
23
|
-
analyze:
|
|
24
|
-
name: Analyze (${{ matrix.language }})
|
|
25
|
-
# Runner size impacts CodeQL analysis time. To learn more, please see:
|
|
26
|
-
# - https://gh.io/recommended-hardware-resources-for-running-codeql
|
|
27
|
-
# - https://gh.io/supported-runners-and-hardware-resources
|
|
28
|
-
# - https://gh.io/using-larger-runners (GitHub.com only)
|
|
29
|
-
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
|
|
30
|
-
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
|
|
31
|
-
permissions:
|
|
32
|
-
# required for all workflows
|
|
33
|
-
security-events: write
|
|
34
|
-
|
|
35
|
-
# required to fetch internal or private CodeQL packs
|
|
36
|
-
packages: read
|
|
37
|
-
|
|
38
|
-
# only required for workflows in private repositories
|
|
39
|
-
actions: read
|
|
40
|
-
contents: read
|
|
41
|
-
|
|
42
|
-
strategy:
|
|
43
|
-
fail-fast: false
|
|
44
|
-
matrix:
|
|
45
|
-
include:
|
|
46
|
-
- language: actions
|
|
47
|
-
build-mode: none
|
|
48
|
-
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
|
|
49
|
-
# Use `c-cpp` to analyze code written in C, C++ or both
|
|
50
|
-
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
|
|
51
|
-
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
|
|
52
|
-
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
|
|
53
|
-
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
|
|
54
|
-
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
|
|
55
|
-
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
|
|
56
|
-
steps:
|
|
57
|
-
- name: Checkout repository
|
|
58
|
-
uses: actions/checkout@v4
|
|
59
|
-
|
|
60
|
-
# Add any setup steps before running the `github/codeql-action/init` action.
|
|
61
|
-
# This includes steps like installing compilers or runtimes (`actions/setup-node`
|
|
62
|
-
# or others). This is typically only required for manual builds.
|
|
63
|
-
# - name: Setup runtime (example)
|
|
64
|
-
# uses: actions/setup-example@v1
|
|
65
|
-
|
|
66
|
-
# Initializes the CodeQL tools for scanning.
|
|
67
|
-
- name: Initialize CodeQL
|
|
68
|
-
uses: github/codeql-action/init@v3
|
|
69
|
-
with:
|
|
70
|
-
languages: ${{ matrix.language }}
|
|
71
|
-
build-mode: ${{ matrix.build-mode }}
|
|
72
|
-
# If you wish to specify custom queries, you can do so here or in a config file.
|
|
73
|
-
# By default, queries listed here will override any specified in a config file.
|
|
74
|
-
# Prefix the list here with "+" to use these queries and those in the config file.
|
|
75
|
-
|
|
76
|
-
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
|
|
77
|
-
# queries: security-extended,security-and-quality
|
|
78
|
-
|
|
79
|
-
# If the analyze step fails for one of the languages you are analyzing with
|
|
80
|
-
# "We were unable to automatically build your code", modify the matrix above
|
|
81
|
-
# to set the build mode to "manual" for that language. Then modify this step
|
|
82
|
-
# to build your code.
|
|
83
|
-
# ℹ️ Command-line programs to run using the OS shell.
|
|
84
|
-
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
|
85
|
-
- if: matrix.build-mode == 'manual'
|
|
86
|
-
shell: bash
|
|
87
|
-
run: |
|
|
88
|
-
echo 'If you are using a "manual" build mode for one or more of the' \
|
|
89
|
-
'languages you are analyzing, replace this with the commands to build' \
|
|
90
|
-
'your code, for example:'
|
|
91
|
-
echo ' make bootstrap'
|
|
92
|
-
echo ' make release'
|
|
93
|
-
exit 1
|
|
94
|
-
|
|
95
|
-
- name: Perform CodeQL Analysis
|
|
96
|
-
uses: github/codeql-action/analyze@v3
|
|
97
|
-
with:
|
|
98
|
-
category: "/language:${{matrix.language}}"
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
name: Publish to npm and GitHub Packages
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
branches:
|
|
5
|
-
- main
|
|
6
|
-
|
|
7
|
-
permissions:
|
|
8
|
-
contents: read
|
|
9
|
-
packages: write
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
publish:
|
|
13
|
-
runs-on: ubuntu-latest
|
|
14
|
-
permissions:
|
|
15
|
-
contents: read
|
|
16
|
-
packages: write
|
|
17
|
-
steps:
|
|
18
|
-
- name: Checkout code
|
|
19
|
-
uses: actions/checkout@v3
|
|
20
|
-
|
|
21
|
-
- name: Setup Node.js for npm
|
|
22
|
-
uses: actions/setup-node@v3
|
|
23
|
-
with:
|
|
24
|
-
node-version: '18'
|
|
25
|
-
registry-url: 'https://registry.npmjs.org'
|
|
26
|
-
|
|
27
|
-
- name: Cache Node.js modules
|
|
28
|
-
uses: actions/cache@v3
|
|
29
|
-
with:
|
|
30
|
-
path: ~/.npm
|
|
31
|
-
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
|
32
|
-
restore-keys: |
|
|
33
|
-
${{ runner.os }}-node-
|
|
34
|
-
|
|
35
|
-
- name: Install dependencies
|
|
36
|
-
run: |
|
|
37
|
-
for i in {1..3}; do npm install && break || sleep 10; done
|
|
38
|
-
|
|
39
|
-
- name: Check if version exists on npm
|
|
40
|
-
id: check_version
|
|
41
|
-
run: |
|
|
42
|
-
PACKAGE_NAME=$(node -p "require('./package.json').name")
|
|
43
|
-
VERSION=$(node -p "require('./package.json').version")
|
|
44
|
-
if npm view $PACKAGE_NAME@$VERSION version 2>/dev/null; then
|
|
45
|
-
echo "exists=true" >> $GITHUB_OUTPUT
|
|
46
|
-
echo "Version $VERSION already exists on npm"
|
|
47
|
-
else
|
|
48
|
-
echo "exists=false" >> $GITHUB_OUTPUT
|
|
49
|
-
echo "Version $VERSION does not exist, will publish"
|
|
50
|
-
fi
|
|
51
|
-
|
|
52
|
-
- name: Publish to npm
|
|
53
|
-
if: steps.check_version.outputs.exists == 'false'
|
|
54
|
-
run: npm publish
|
|
55
|
-
env:
|
|
56
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
57
|
-
|
|
58
|
-
- name: Check if version exists on GitHub Packages
|
|
59
|
-
id: check_github_version
|
|
60
|
-
run: |
|
|
61
|
-
VERSION=$(node -p "require('./package.json').version")
|
|
62
|
-
if curl -f -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
|
|
63
|
-
https://npm.pkg.github.com/@mibnekhalid/mbkauthe/$VERSION 2>/dev/null; then
|
|
64
|
-
echo "exists=true" >> $GITHUB_OUTPUT
|
|
65
|
-
echo "Version $VERSION already exists on GitHub Packages"
|
|
66
|
-
else
|
|
67
|
-
echo "exists=false" >> $GITHUB_OUTPUT
|
|
68
|
-
echo "Version $VERSION does not exist on GitHub Packages, will publish"
|
|
69
|
-
fi
|
|
70
|
-
|
|
71
|
-
- name: Modify package.json for GitHub Packages
|
|
72
|
-
if: steps.check_github_version.outputs.exists == 'false'
|
|
73
|
-
run: |
|
|
74
|
-
node -e "const pkg = require('./package.json'); pkg.name = '@mibnekhalid/mbkauthe'; pkg.publishConfig = { registry: 'https://npm.pkg.github.com' }; require('fs').writeFileSync('package.json', JSON.stringify(pkg, null, 2));"
|
|
75
|
-
|
|
76
|
-
- name: Setup Node.js for GitHub Packages
|
|
77
|
-
if: steps.check_github_version.outputs.exists == 'false'
|
|
78
|
-
uses: actions/setup-node@v3
|
|
79
|
-
with:
|
|
80
|
-
node-version: '18'
|
|
81
|
-
registry-url: 'https://npm.pkg.github.com'
|
|
82
|
-
|
|
83
|
-
- name: Publish to GitHub Packages
|
|
84
|
-
if: steps.check_github_version.outputs.exists == 'false'
|
|
85
|
-
run: npm publish
|
|
86
|
-
env:
|
|
87
|
-
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|