@ciscode/authentication-kit 1.1.0 → 1.1.1
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 +57 -73
- package/package.json +68 -43
- package/.github/workflows/ci .yml +0 -36
- package/.github/workflows/publish.yml +0 -30
- package/CODE_OF_CONDUCT +0 -38
- package/CONTRIBUTING.md +0 -40
- package/SECURITY +0 -31
- package/azure-pipelines.yml +0 -100
- package/src/config/db.config.js +0 -21
- package/src/config/passport.config.js +0 -280
- package/src/controllers/auth.controller.js +0 -566
- package/src/controllers/passwordReset.controller.js +0 -127
- package/src/controllers/permission.controller.js +0 -81
- package/src/controllers/roles.controller.js +0 -108
- package/src/controllers/user.controller.js +0 -283
- package/src/index.js +0 -32
- package/src/middleware/auth.middleware.js +0 -16
- package/src/middleware/authenticate.js +0 -25
- package/src/middleware/rbac.middleware.js +0 -24
- package/src/middleware/tenant.middleware.js +0 -16
- package/src/models/client.model.js +0 -39
- package/src/models/permission.model.js +0 -9
- package/src/models/role.model.js +0 -14
- package/src/models/tenant.model.js +0 -9
- package/src/models/user.model.js +0 -51
- package/src/routes/admin.routes.js +0 -8
- package/src/routes/auth.routes.js +0 -77
- package/src/routes/passwordReset.routes.js +0 -8
- package/src/routes/permission.routes.js +0 -17
- package/src/routes/roles.routes.js +0 -11
- package/src/routes/user.routes.js +0 -22
- package/src/utils/helper.js +0 -26
package/README.md
CHANGED
|
@@ -1,48 +1,31 @@
|
|
|
1
|
-
Auth Service (
|
|
2
|
-
Internal package
|
|
3
|
-
This package is not published on npmjs. Install it only from the company
|
|
1
|
+
Auth Service (NestJS, JWT, Multi-tenant, RBAC)
|
|
2
|
+
Internal package - private to the company.
|
|
3
|
+
This package is not published on npmjs. Install it only from the company Azure Artifacts feed using a project or user-level .npmrc.
|
|
4
4
|
|
|
5
|
-
Authentication
|
|
6
|
-
Provides local email/password auth with lockout, JWT access tokens
|
|
5
|
+
Authentication and authorization module for NestJS apps.
|
|
6
|
+
Provides local email/password auth with lockout, JWT access tokens and refresh, tenant scoping, RBAC, and optional OAuth (Microsoft Entra, Google, Facebook).
|
|
7
7
|
|
|
8
8
|
Features
|
|
9
9
|
Local auth (email/password) with account lockout policy.
|
|
10
10
|
JWT access tokens (Bearer) and refresh endpoint (cookie or body).
|
|
11
11
|
Multi-tenant scope on requests.
|
|
12
|
-
RBAC (roles
|
|
13
|
-
Microsoft Entra (Azure AD) OAuth (optional).
|
|
12
|
+
RBAC (roles -> permission strings).
|
|
13
|
+
Microsoft Entra (Azure AD), Google, Facebook OAuth (optional).
|
|
14
14
|
MongoDB/Mongoose models.
|
|
15
|
+
|
|
15
16
|
Routes are mounted under:
|
|
16
17
|
|
|
17
18
|
/api/auth (auth, password reset)
|
|
18
19
|
/api/users (user admin)
|
|
19
20
|
/api/auth/roles and /api/auth/permissions (RBAC)
|
|
20
|
-
|
|
21
|
-
1) Configure .npmrc
|
|
22
|
-
Do not commit real tokens. Prefer ~/.npmrc or generate .npmrc in CI using secrets.
|
|
23
|
-
|
|
24
|
-
For developers (user-level ~/.npmrc):
|
|
25
|
-
|
|
26
|
-
registry=https://registry.npmjs.org/
|
|
27
|
-
|
|
28
|
-
# Route @ciscodeapps scope to the private feed
|
|
29
|
-
@ciscodeapps:registry=https://pkgs.dev.azure.com/CISCODEAPPS/Templates/_packaging/testfeed/npm/registry/
|
|
21
|
+
/api/admin (admin actions)
|
|
30
22
|
|
|
31
|
-
|
|
32
|
-
always-auth=true
|
|
33
|
-
Set the token as an environment variable before installing:
|
|
23
|
+
Installation
|
|
34
24
|
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
1) Install the package
|
|
26
|
+
npm i @ciscode/authentication-kit
|
|
37
27
|
|
|
38
|
-
|
|
39
|
-
//pkgs.dev.azure.com/...:_password=${BASE64_PAT}
|
|
40
|
-
//pkgs.dev.azure.com/...:email=not-used@localhost
|
|
41
|
-
where BASE64_PAT=$(printf %s "$AZURE_ARTIFACTS_PAT" | base64).
|
|
42
|
-
|
|
43
|
-
2) Install the package
|
|
44
|
-
npm i @ciscodeapps/auth-service
|
|
45
|
-
3) Required environment variables (host app)
|
|
28
|
+
2) Required environment variables (host app)
|
|
46
29
|
Create a .env in the host project:
|
|
47
30
|
|
|
48
31
|
# Server
|
|
@@ -64,61 +47,59 @@ MAX_FAILED_LOGIN_ATTEMPTS=5
|
|
|
64
47
|
ACCOUNT_LOCK_TIME_MINUTES=15
|
|
65
48
|
|
|
66
49
|
# (Optional) Microsoft Entra ID (Azure AD)
|
|
67
|
-
|
|
50
|
+
MICROSOFT_TENANT_ID=common
|
|
68
51
|
MICROSOFT_CLIENT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
|
69
52
|
MICROSOFT_CLIENT_SECRET=your-secret
|
|
70
53
|
MICROSOFT_CALLBACK_URL=${BASE_URL}/api/auth/microsoft/callback
|
|
71
|
-
Use inside an existing Express app
|
|
72
|
-
Your package exports an Express app that already parses JSON, connects to Mongo, and mounts its routes. Just mount it:
|
|
73
54
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
55
|
+
Use inside an existing Nest app
|
|
56
|
+
The module connects to Mongo on init and mounts its controllers.
|
|
57
|
+
|
|
58
|
+
// app.module.ts (host app)
|
|
59
|
+
import { Module } from '@nestjs/common';
|
|
60
|
+
import { AuthKitModule } from '@ciscode/authentication-kit';
|
|
61
|
+
|
|
62
|
+
@Module({
|
|
63
|
+
imports: [AuthKitModule]
|
|
64
|
+
})
|
|
65
|
+
export class AppModule {}
|
|
78
66
|
|
|
79
|
-
|
|
80
|
-
app.use(authApp); // exposes /api/auth, /api/users, /api/auth/roles, /api/auth/permissions
|
|
67
|
+
If you need to run it standalone, build and start the package:
|
|
81
68
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
console.log('Host app on', process.env.PORT || 3000)
|
|
85
|
-
);
|
|
86
|
-
Prefer mounting the service. If you need to run it standalone, you can also start this package directly (it calls connectDB() on import).
|
|
69
|
+
npm run build
|
|
70
|
+
npm start
|
|
87
71
|
|
|
88
|
-
What
|
|
72
|
+
What is included (routes and behavior)
|
|
89
73
|
Auth
|
|
90
|
-
POST /api/auth/
|
|
91
|
-
POST /api/auth/
|
|
92
|
-
POST /api/auth/
|
|
93
|
-
POST /api/auth/
|
|
94
|
-
|
|
95
|
-
PATCH /api/auth/reset-password – Consumes the reset token and sets a new password.
|
|
96
|
-
GET /api/auth/microsoft → GET /api/auth/microsoft/callback – Optional Microsoft Entra OAuth; issues first-party tokens.
|
|
74
|
+
POST /api/auth/login - Local login. On success, returns accessToken and may set a refreshToken httpOnly cookie.
|
|
75
|
+
POST /api/auth/refresh-token - New access token from a valid refresh token (cookie or body).
|
|
76
|
+
POST /api/auth/request-password-reset - Sends a reset token (e.g., by email).
|
|
77
|
+
POST /api/auth/reset-password - Consumes the reset token and sets a new password.
|
|
78
|
+
GET /api/auth/microsoft - GET /api/auth/microsoft/callback - Optional Microsoft Entra OAuth; issues first-party tokens.
|
|
97
79
|
Users
|
|
98
|
-
GET /api/users
|
|
99
|
-
POST /api/users
|
|
80
|
+
GET /api/users - List users (tenant-scoped, paginated).
|
|
81
|
+
POST /api/users - Create a user.
|
|
100
82
|
Additional CRUD endpoints as exposed by controllers.
|
|
101
|
-
Roles
|
|
102
|
-
GET/POST /api/auth/roles
|
|
103
|
-
GET /api/auth/permissions
|
|
83
|
+
Roles and Permissions
|
|
84
|
+
GET/POST /api/auth/roles - Manage roles (name, tenantId, permissions: string[]).
|
|
85
|
+
GET /api/auth/permissions - List permission strings and metadata.
|
|
86
|
+
|
|
104
87
|
Protecting your own routes (host app)
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
88
|
+
import { UseGuards } from '@nestjs/common';
|
|
89
|
+
import { AuthenticateGuard, hasPermission } from '@ciscode/authentication-kit';
|
|
90
|
+
|
|
91
|
+
@UseGuards(AuthenticateGuard, hasPermission('reports:read'))
|
|
92
|
+
@Get('reports')
|
|
93
|
+
getReports() {
|
|
94
|
+
return { ok: true };
|
|
95
|
+
}
|
|
96
|
+
|
|
113
97
|
Tenant scope comes from the JWT payload (e.g., tenantId) and is used inside controllers/guards to filter queries.
|
|
114
98
|
|
|
115
99
|
Quick start (smoke tests)
|
|
116
|
-
Start your host app:
|
|
117
|
-
|
|
118
|
-
node server.js
|
|
119
|
-
Register & Login
|
|
100
|
+
Start your host app, then create a user and log in:
|
|
120
101
|
|
|
121
|
-
curl -X POST http://localhost:3000/api/
|
|
102
|
+
curl -X POST http://localhost:3000/api/users \
|
|
122
103
|
-H 'Content-Type: application/json' \
|
|
123
104
|
-d '{"email":"a@b.com","password":"Secret123!","tenantId":"t-001","name":"Alice"}'
|
|
124
105
|
|
|
@@ -126,17 +107,20 @@ curl -X POST http://localhost:3000/api/auth/login \
|
|
|
126
107
|
-H 'Content-Type: application/json' \
|
|
127
108
|
-d '{"email":"a@b.com","password":"Secret123!","tenantId":"t-001"}'
|
|
128
109
|
# => { "accessToken": "...", "refreshToken": "..." }
|
|
110
|
+
|
|
129
111
|
Call a protected route
|
|
130
112
|
|
|
131
113
|
ACCESS=<paste_access_token_here>
|
|
132
114
|
curl http://localhost:3000/api/users -H "Authorization: Bearer $ACCESS"
|
|
115
|
+
|
|
133
116
|
Refresh token
|
|
134
117
|
|
|
135
118
|
curl -X POST http://localhost:3000/api/auth/refresh-token \
|
|
136
119
|
-H 'Content-Type: application/json' \
|
|
137
120
|
-d '{"refreshToken":"<paste_refresh_token_here>"}'
|
|
138
121
|
# => { "accessToken": "..." }
|
|
139
|
-
|
|
122
|
+
|
|
123
|
+
Microsoft OAuth (optional) - Visit: http://localhost:3000/api/auth/microsoft to complete sign-in.
|
|
140
124
|
- Callback: ${BASE_URL}/api/auth/microsoft/callback returns tokens (and may set the refresh cookie).
|
|
141
125
|
|
|
142
126
|
CI/CD (Azure Pipelines)
|
|
@@ -151,7 +135,7 @@ CI/CD (Azure Pipelines)
|
|
|
151
135
|
|
|
152
136
|
Security notes
|
|
153
137
|
Never commit real PATs. Use env vars or CI secrets.
|
|
154
|
-
Run behind HTTPS. Rotate JWT
|
|
138
|
+
Run behind HTTPS. Rotate JWT and refresh secrets periodically.
|
|
155
139
|
Limit login attempts; log auth events for auditing.
|
|
156
140
|
License
|
|
157
|
-
Internal
|
|
141
|
+
Internal - Company proprietary.
|
package/package.json
CHANGED
|
@@ -1,45 +1,70 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
2
|
+
"name": "@ciscode/authentication-kit",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/CISCODE-MA/AuthKit.git"
|
|
9
|
+
},
|
|
10
|
+
"version": "1.1.1",
|
|
11
|
+
"description": "A login library with local login, Microsoft Entra ID authentication, password reset, and roles/permissions for multi-tenant applications.",
|
|
12
|
+
"main": "dist/index.js",
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.json",
|
|
21
|
+
"start": "node dist/standalone.js",
|
|
22
|
+
"test": "echo \"No tests defined\" && exit 0",
|
|
23
|
+
"release": "semantic-release"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"login",
|
|
27
|
+
"authentication",
|
|
28
|
+
"microsoft-oauth",
|
|
29
|
+
"password-reset",
|
|
30
|
+
"roles",
|
|
31
|
+
"permissions",
|
|
32
|
+
"multi-tenant"
|
|
33
|
+
],
|
|
34
|
+
"author": "Ciscode",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@nestjs/common": "^10.4.0",
|
|
38
|
+
"@nestjs/core": "^10.4.0",
|
|
39
|
+
"@nestjs/platform-express": "^10.4.0",
|
|
40
|
+
"axios": "^1.7.7",
|
|
41
|
+
"bcryptjs": "^2.4.3",
|
|
42
|
+
"cookie-parser": "^1.4.6",
|
|
43
|
+
"dotenv": "^16.0.3",
|
|
44
|
+
"express": "^4.18.2",
|
|
45
|
+
"jsonwebtoken": "^9.0.0",
|
|
46
|
+
"jwks-rsa": "^3.1.0",
|
|
47
|
+
"mongoose": "^7.0.0",
|
|
48
|
+
"mongoose-paginate-v2": "^1.7.1",
|
|
49
|
+
"nodemailer": "^7.0.12",
|
|
50
|
+
"passport": "^0.6.0",
|
|
51
|
+
"passport-azure-ad-oauth2": "^0.0.4",
|
|
52
|
+
"passport-facebook": "^3.0.0",
|
|
53
|
+
"passport-google-oauth20": "^2.0.0",
|
|
54
|
+
"passport-local": "^1.0.0",
|
|
55
|
+
"reflect-metadata": "^0.2.2",
|
|
56
|
+
"rxjs": "^7.8.1"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@types/cookie-parser": "^1.4.6",
|
|
60
|
+
"@types/express": "^4.17.21",
|
|
61
|
+
"@types/jsonwebtoken": "^9.0.6",
|
|
62
|
+
"@types/node": "^20.12.12",
|
|
63
|
+
"@types/passport-facebook": "^3.0.4",
|
|
64
|
+
"@types/passport-google-oauth20": "^2.0.15",
|
|
65
|
+
"@types/passport-local": "^1.0.38",
|
|
66
|
+
"semantic-release": "^25.0.2",
|
|
67
|
+
"ts-node": "^10.9.2",
|
|
68
|
+
"typescript": "^5.6.2"
|
|
69
|
+
}
|
|
45
70
|
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request:
|
|
5
|
-
branches: [master, develop]
|
|
6
|
-
push:
|
|
7
|
-
branches: [develop]
|
|
8
|
-
|
|
9
|
-
permissions:
|
|
10
|
-
contents: read
|
|
11
|
-
|
|
12
|
-
jobs:
|
|
13
|
-
ci:
|
|
14
|
-
runs-on: ubuntu-latest
|
|
15
|
-
steps:
|
|
16
|
-
- name: Checkout
|
|
17
|
-
uses: actions/checkout@v4
|
|
18
|
-
|
|
19
|
-
- name: Use Node.js
|
|
20
|
-
uses: actions/setup-node@v4
|
|
21
|
-
with:
|
|
22
|
-
node-version: 22
|
|
23
|
-
cache: npm
|
|
24
|
-
registry-url: https://registry.npmjs.org/
|
|
25
|
-
|
|
26
|
-
- name: Install dependencies
|
|
27
|
-
run: npm ci
|
|
28
|
-
|
|
29
|
-
- name: Lint
|
|
30
|
-
run: npm run lint --if-present
|
|
31
|
-
|
|
32
|
-
- name: Test
|
|
33
|
-
run: npm test --if-present
|
|
34
|
-
|
|
35
|
-
- name: Build
|
|
36
|
-
run: npm run build --if-present
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
name: Publish to npm
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
tags:
|
|
6
|
-
- "v*.*.*"
|
|
7
|
-
|
|
8
|
-
permissions:
|
|
9
|
-
contents: read
|
|
10
|
-
id-token: write
|
|
11
|
-
|
|
12
|
-
jobs:
|
|
13
|
-
publish:
|
|
14
|
-
runs-on: ubuntu-latest
|
|
15
|
-
steps:
|
|
16
|
-
- uses: actions/checkout@v4
|
|
17
|
-
|
|
18
|
-
- uses: actions/setup-node@v4
|
|
19
|
-
with:
|
|
20
|
-
node-version: 22
|
|
21
|
-
registry-url: https://registry.npmjs.org/
|
|
22
|
-
cache: npm
|
|
23
|
-
- name: Install dependencies
|
|
24
|
-
run: npm ci
|
|
25
|
-
- name: Build library
|
|
26
|
-
run: npm run build:lib --if-present
|
|
27
|
-
- name: Publish to npm
|
|
28
|
-
run: npm publish --access public --provenance
|
|
29
|
-
env:
|
|
30
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/CODE_OF_CONDUCT
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# Code of Conduct
|
|
2
|
-
|
|
3
|
-
This project adheres to the Contributor Covenant Code of Conduct.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## Our Pledge
|
|
8
|
-
|
|
9
|
-
We pledge to make participation in this project a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity.
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## Our Standards
|
|
14
|
-
|
|
15
|
-
Examples of behavior that contributes to a positive environment include:
|
|
16
|
-
- Being respectful and inclusive
|
|
17
|
-
- Giving and accepting constructive feedback
|
|
18
|
-
- Focusing on what is best for the community
|
|
19
|
-
|
|
20
|
-
Examples of unacceptable behavior include:
|
|
21
|
-
- Harassment or discriminatory language
|
|
22
|
-
- Personal attacks or trolling
|
|
23
|
-
- Publishing private information without consent
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
## Enforcement
|
|
28
|
-
|
|
29
|
-
Project maintainers are responsible for clarifying and enforcing standards of acceptable behavior.
|
|
30
|
-
|
|
31
|
-
Instances of abusive behavior may be reported to the maintainers through private communication channels.
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
## Attribution
|
|
36
|
-
|
|
37
|
-
This Code of Conduct is adapted from the Contributor Covenant
|
|
38
|
-
version 2.1 — https://www.contributor-covenant.org/
|
package/CONTRIBUTING.md
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# Contributing
|
|
2
|
-
|
|
3
|
-
Thank you for your interest in contributing to this project.
|
|
4
|
-
|
|
5
|
-
Contributions of all kinds are welcome, including bug reports, feature requests, documentation improvements, and code contributions.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## How to Contribute
|
|
10
|
-
|
|
11
|
-
1. Fork the repository
|
|
12
|
-
2. Create a new branch from `main`
|
|
13
|
-
3. Make your changes
|
|
14
|
-
4. Add or update tests where applicable
|
|
15
|
-
5. Ensure existing tests pass
|
|
16
|
-
6. Open a pull request with a clear description
|
|
17
|
-
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
## Guidelines
|
|
21
|
-
|
|
22
|
-
- Keep changes focused and minimal
|
|
23
|
-
- Follow existing code style and conventions
|
|
24
|
-
- Avoid breaking backward compatibility when possible
|
|
25
|
-
- Write clear commit messages
|
|
26
|
-
- Do not include secrets, credentials, or tokens
|
|
27
|
-
|
|
28
|
-
---
|
|
29
|
-
|
|
30
|
-
## Reporting Bugs
|
|
31
|
-
|
|
32
|
-
When reporting bugs, please include:
|
|
33
|
-
- A clear description of the issue
|
|
34
|
-
- Steps to reproduce
|
|
35
|
-
- Expected vs actual behavior
|
|
36
|
-
- Relevant logs or error messages (redacted if needed)
|
|
37
|
-
|
|
38
|
-
---
|
|
39
|
-
|
|
40
|
-
By contributing, you agree that your contributions will be licensed under the same license as the project.
|
package/SECURITY
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# Security Policy
|
|
2
|
-
|
|
3
|
-
Security is taken seriously in this project.
|
|
4
|
-
|
|
5
|
-
If you discover a security vulnerability, please **do not open a public issue**.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## Reporting a Vulnerability
|
|
10
|
-
|
|
11
|
-
Please report security issues privately by contacting the maintainers using one of the following methods:
|
|
12
|
-
|
|
13
|
-
- Email the address listed in the repository’s contact or maintainer information
|
|
14
|
-
- Use private disclosure channels if available on the hosting platform
|
|
15
|
-
|
|
16
|
-
When reporting, please include:
|
|
17
|
-
- A description of the vulnerability
|
|
18
|
-
- Steps to reproduce
|
|
19
|
-
- Potential impact
|
|
20
|
-
- Any suggested mitigations (if known)
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
## Security Best Practices
|
|
25
|
-
|
|
26
|
-
- Never commit secrets or credentials
|
|
27
|
-
- Use strong, rotated secrets for JWT signing
|
|
28
|
-
- Run services behind HTTPS
|
|
29
|
-
- Apply rate limiting and monitoring in production environments
|
|
30
|
-
|
|
31
|
-
We appreciate responsible disclosure and will work to address issues promptly.
|
package/azure-pipelines.yml
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
trigger:
|
|
2
|
-
- main
|
|
3
|
-
|
|
4
|
-
pool:
|
|
5
|
-
vmImage: 'ubuntu-latest'
|
|
6
|
-
|
|
7
|
-
variables:
|
|
8
|
-
- group: BE # AZURE_ARTIFACTS_PAT lives here; add NPM_TOKEN and (optionally) GH_PAT as secrets
|
|
9
|
-
|
|
10
|
-
# Optional toggles (default = behave exactly like your old pipeline: publish only to Azure Artifacts)
|
|
11
|
-
parameters:
|
|
12
|
-
- name: pushToGitHub
|
|
13
|
-
type: boolean
|
|
14
|
-
default: false
|
|
15
|
-
- name: publishToNpm
|
|
16
|
-
type: boolean
|
|
17
|
-
default: false
|
|
18
|
-
- name: packagePath
|
|
19
|
-
type: string
|
|
20
|
-
default: 'modules/login'
|
|
21
|
-
|
|
22
|
-
steps:
|
|
23
|
-
# Allows pushing back to GitHub if pushToGitHub=true (we'll still use GH_PAT if provided)
|
|
24
|
-
- checkout: self
|
|
25
|
-
persistCredentials: true
|
|
26
|
-
displayName: 'Checkout (allows push when enabled)'
|
|
27
|
-
|
|
28
|
-
# 1) Use Node.js (unchanged)
|
|
29
|
-
- task: NodeTool@0
|
|
30
|
-
inputs:
|
|
31
|
-
versionSpec: '20.x'
|
|
32
|
-
displayName: 'Use Node.js'
|
|
33
|
-
|
|
34
|
-
# 2) Authenticate with Azure Artifacts (unchanged)
|
|
35
|
-
- script: |
|
|
36
|
-
echo "Setting up npm authentication for Azure Artifacts..."
|
|
37
|
-
echo "//pkgs.dev.azure.com/CISCODEAPPS/Templates/_packaging/testfeed/npm/registry/:_authToken=$(AZURE_ARTIFACTS_PAT)" > ~/.npmrc
|
|
38
|
-
npm set registry "https://pkgs.dev.azure.com/CISCODEAPPS/Templates/_packaging/testfeed/npm/registry/"
|
|
39
|
-
displayName: 'Authenticate with Azure Artifacts'
|
|
40
|
-
|
|
41
|
-
# 3) Bump + publish to Azure Artifacts (mandatory)
|
|
42
|
-
- script: |
|
|
43
|
-
set -e
|
|
44
|
-
echo "Bumping package version before publishing login..."
|
|
45
|
-
cd ${{ parameters.packagePath }}
|
|
46
|
-
npm version patch --no-git-tag-version
|
|
47
|
-
|
|
48
|
-
# capture for optional steps
|
|
49
|
-
NEW_VERSION=$(node -p "require('./package.json').version")
|
|
50
|
-
PKG_NAME=$(node -p "require('./package.json').name")
|
|
51
|
-
echo "Decided version: ${NEW_VERSION} for ${PKG_NAME}"
|
|
52
|
-
echo "##vso[task.setvariable variable=NEW_VERSION]$NEW_VERSION"
|
|
53
|
-
echo "##vso[task.setvariable variable=PKG_NAME]$PKG_NAME"
|
|
54
|
-
|
|
55
|
-
# sanity: see what will be published
|
|
56
|
-
npm pack --dry-run
|
|
57
|
-
|
|
58
|
-
# publish to Azure Artifacts (mandatory)
|
|
59
|
-
npm publish --registry=https://pkgs.dev.azure.com/CISCODEAPPS/Templates/_packaging/testfeed/npm/registry/
|
|
60
|
-
displayName: 'Publish authentication module (Azure Artifacts - mandatory)'
|
|
61
|
-
|
|
62
|
-
# OPTIONAL: push the version bump back to GitHub
|
|
63
|
-
- ${{ if eq(parameters.pushToGitHub, true) }}:
|
|
64
|
-
- script: |
|
|
65
|
-
set -e
|
|
66
|
-
cd ${{ parameters.packagePath }}
|
|
67
|
-
|
|
68
|
-
# bot identity for the commit
|
|
69
|
-
git config user.name "azure-pipelines[bot]"
|
|
70
|
-
git config user.email "azure-pipelines-bot@example.local"
|
|
71
|
-
|
|
72
|
-
# If a GitHub PAT is provided, use it to ensure push works (esp. with GitHub App connections)
|
|
73
|
-
if [ -n "$(GH_PAT)" ]; then
|
|
74
|
-
echo "Using GH_PAT to authenticate push..."
|
|
75
|
-
git remote set-url origin "https://x-access-token:$(GH_PAT)@github.com/CISCODE-MA/auth_package"
|
|
76
|
-
fi
|
|
77
|
-
|
|
78
|
-
git add package.json package-lock.json || true
|
|
79
|
-
git commit -m "chore(login): bump $(PKG_NAME) to v$(NEW_VERSION) [skip ci]" || echo "No changes to commit"
|
|
80
|
-
git push origin HEAD:$(Build.SourceBranchName)
|
|
81
|
-
displayName: 'Push version bump to GitHub (optional)'
|
|
82
|
-
|
|
83
|
-
# OPTIONAL: publish same version to npm public (with pre-check)
|
|
84
|
-
- ${{ if eq(parameters.publishToNpm, true) }}:
|
|
85
|
-
- script: |
|
|
86
|
-
set -e
|
|
87
|
-
echo "Switching npm auth to npm public..."
|
|
88
|
-
rm -f ~/.npmrc || true
|
|
89
|
-
echo "//registry.npmjs.org/:_authToken=$(NPM_TOKEN)" > ~/.npmrc
|
|
90
|
-
npm set registry "https://registry.npmjs.org/"
|
|
91
|
-
|
|
92
|
-
cd ${{ parameters.packagePath }}
|
|
93
|
-
|
|
94
|
-
# Skip if the exact version already exists on npm
|
|
95
|
-
if npm view "$(PKG_NAME)@$(NEW_VERSION)" version >/dev/null 2>&1; then
|
|
96
|
-
echo "$(PKG_NAME)@$(NEW_VERSION) already exists on npm; skipping publish."
|
|
97
|
-
else
|
|
98
|
-
npm publish --access public
|
|
99
|
-
fi
|
|
100
|
-
displayName: 'Publish to npm public (optional)'
|
package/src/config/db.config.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const mongoose = require('mongoose');
|
|
2
|
-
require('dotenv').config();
|
|
3
|
-
|
|
4
|
-
// Optionally, set strictQuery per Mongoose recommendations
|
|
5
|
-
mongoose.set('strictQuery', false);
|
|
6
|
-
|
|
7
|
-
const connectDB = async () => {
|
|
8
|
-
try {
|
|
9
|
-
const mongoURI = process.env.MONGO_URI_T;
|
|
10
|
-
if (!mongoURI) {
|
|
11
|
-
throw new Error('MONGO_URI is not defined in the environment variables.');
|
|
12
|
-
}
|
|
13
|
-
await mongoose.connect(mongoURI);
|
|
14
|
-
console.log("MongoDB Connected...");
|
|
15
|
-
} catch (error) {
|
|
16
|
-
console.error("MongoDB Connection Error:", error);
|
|
17
|
-
process.exit(1);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
module.exports = connectDB;
|