@ciscode/authentication-kit 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +57 -73
  2. package/dist/auth-kit.module.d.ts +7 -0
  3. package/dist/auth-kit.module.js +50 -0
  4. package/dist/config/db.config.d.ts +1 -0
  5. package/dist/config/db.config.js +22 -0
  6. package/dist/config/passport.config.d.ts +3 -0
  7. package/dist/config/passport.config.js +272 -0
  8. package/dist/controllers/admin.controller.d.ts +4 -0
  9. package/dist/controllers/admin.controller.js +59 -0
  10. package/dist/controllers/auth.controller.d.ts +23 -0
  11. package/dist/controllers/auth.controller.js +645 -0
  12. package/dist/controllers/password-reset.controller.d.ts +8 -0
  13. package/dist/controllers/password-reset.controller.js +146 -0
  14. package/dist/controllers/permissions.controller.d.ts +7 -0
  15. package/dist/controllers/permissions.controller.js +115 -0
  16. package/dist/controllers/roles.controller.d.ts +7 -0
  17. package/dist/controllers/roles.controller.js +113 -0
  18. package/dist/controllers/users.controller.d.ts +8 -0
  19. package/dist/controllers/users.controller.js +259 -0
  20. package/dist/index.d.ts +6 -0
  21. package/dist/index.js +14 -0
  22. package/dist/middleware/auth.guard.d.ts +4 -0
  23. package/dist/middleware/auth.guard.js +39 -0
  24. package/dist/middleware/authenticate.guard.d.ts +4 -0
  25. package/dist/middleware/authenticate.guard.js +44 -0
  26. package/dist/middleware/permission.guard.d.ts +4 -0
  27. package/dist/middleware/permission.guard.js +52 -0
  28. package/dist/middleware/tenant.guard.d.ts +4 -0
  29. package/dist/middleware/tenant.guard.js +39 -0
  30. package/dist/models/client.model.d.ts +54 -0
  31. package/dist/models/client.model.js +34 -0
  32. package/dist/models/permission.model.d.ts +19 -0
  33. package/dist/models/permission.model.js +17 -0
  34. package/dist/models/role.model.d.ts +33 -0
  35. package/dist/models/role.model.js +19 -0
  36. package/dist/models/tenant.model.d.ts +19 -0
  37. package/dist/models/tenant.model.js +15 -0
  38. package/dist/models/user.model.d.ts +63 -0
  39. package/dist/models/user.model.js +41 -0
  40. package/dist/standalone.d.ts +1 -0
  41. package/dist/standalone.js +12 -0
  42. package/dist/utils/helper.d.ts +1 -0
  43. package/dist/utils/helper.js +22 -0
  44. package/package.json +69 -43
  45. package/.github/workflows/ci .yml +0 -36
  46. package/.github/workflows/publish.yml +0 -30
  47. package/CODE_OF_CONDUCT +0 -38
  48. package/CONTRIBUTING.md +0 -40
  49. package/SECURITY +0 -31
  50. package/azure-pipelines.yml +0 -100
  51. package/src/config/db.config.js +0 -21
  52. package/src/config/passport.config.js +0 -280
  53. package/src/controllers/auth.controller.js +0 -566
  54. package/src/controllers/passwordReset.controller.js +0 -127
  55. package/src/controllers/permission.controller.js +0 -81
  56. package/src/controllers/roles.controller.js +0 -108
  57. package/src/controllers/user.controller.js +0 -283
  58. package/src/index.js +0 -32
  59. package/src/middleware/auth.middleware.js +0 -16
  60. package/src/middleware/authenticate.js +0 -25
  61. package/src/middleware/rbac.middleware.js +0 -24
  62. package/src/middleware/tenant.middleware.js +0 -16
  63. package/src/models/client.model.js +0 -39
  64. package/src/models/permission.model.js +0 -9
  65. package/src/models/role.model.js +0 -14
  66. package/src/models/tenant.model.js +0 -9
  67. package/src/models/user.model.js +0 -51
  68. package/src/routes/admin.routes.js +0 -8
  69. package/src/routes/auth.routes.js +0 -77
  70. package/src/routes/passwordReset.routes.js +0 -8
  71. package/src/routes/permission.routes.js +0 -17
  72. package/src/routes/roles.routes.js +0 -11
  73. package/src/routes/user.routes.js +0 -22
  74. package/src/utils/helper.js +0 -26
package/package.json CHANGED
@@ -1,45 +1,71 @@
1
1
  {
2
- "name": "@ciscode/authentication-kit",
3
- "publishConfig": {
4
- "access": "public"
5
- },
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/CISCODE-MA/authentication-kit.git"
9
- },
10
- "version": "1.1.0",
11
- "description": "A login library with local login, Microsoft Entra ID authentication, password reset, and roles/permissions for multi-tenant applications.",
12
- "main": "src/index.js",
13
- "scripts": {
14
- "start": "node src/index.js",
15
- "test": "echo \"No tests defined\" && exit 0",
16
- "release": "semantic-release"
17
- },
18
- "keywords": [
19
- "login",
20
- "authentication",
21
- "microsoft-oauth",
22
- "password-reset",
23
- "roles",
24
- "permissions",
25
- "multi-tenant"
26
- ],
27
- "author": "Ciscode",
28
- "license": "MIT",
29
- "dependencies": {
30
- "bcryptjs": "^2.4.3",
31
- "crypto": "^1.0.1",
32
- "dotenv": "^16.0.3",
33
- "express": "^4.18.2",
34
- "jsonwebtoken": "^9.0.0",
35
- "mongoose": "^7.0.0",
36
- "mongoose-paginate-v2": "^1.7.1",
37
- "nodemailer": "^6.9.1",
38
- "passport": "^0.6.0",
39
- "passport-azure-ad-oauth2": "^0.0.4",
40
- "passport-local": "^1.0.0"
41
- },
42
- "devDependencies": {
43
- "semantic-release": "^25.0.2"
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.2",
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
+ "prepack": "npm run build",
24
+ "release": "semantic-release"
25
+ },
26
+ "keywords": [
27
+ "login",
28
+ "authentication",
29
+ "microsoft-oauth",
30
+ "password-reset",
31
+ "roles",
32
+ "permissions",
33
+ "multi-tenant"
34
+ ],
35
+ "author": "Ciscode",
36
+ "license": "MIT",
37
+ "dependencies": {
38
+ "@nestjs/common": "^10.4.0",
39
+ "@nestjs/core": "^10.4.0",
40
+ "@nestjs/platform-express": "^10.4.0",
41
+ "axios": "^1.7.7",
42
+ "bcryptjs": "^2.4.3",
43
+ "cookie-parser": "^1.4.6",
44
+ "dotenv": "^16.0.3",
45
+ "express": "^4.18.2",
46
+ "jsonwebtoken": "^9.0.0",
47
+ "jwks-rsa": "^3.1.0",
48
+ "mongoose": "^7.0.0",
49
+ "mongoose-paginate-v2": "^1.7.1",
50
+ "nodemailer": "^7.0.12",
51
+ "passport": "^0.6.0",
52
+ "passport-azure-ad-oauth2": "^0.0.4",
53
+ "passport-facebook": "^3.0.0",
54
+ "passport-google-oauth20": "^2.0.0",
55
+ "passport-local": "^1.0.0",
56
+ "reflect-metadata": "^0.2.2",
57
+ "rxjs": "^7.8.1"
58
+ },
59
+ "devDependencies": {
60
+ "@types/cookie-parser": "^1.4.6",
61
+ "@types/express": "^4.17.21",
62
+ "@types/jsonwebtoken": "^9.0.6",
63
+ "@types/node": "^20.12.12",
64
+ "@types/passport-facebook": "^3.0.4",
65
+ "@types/passport-google-oauth20": "^2.0.15",
66
+ "@types/passport-local": "^1.0.38",
67
+ "semantic-release": "^25.0.2",
68
+ "ts-node": "^10.9.2",
69
+ "typescript": "^5.6.2"
70
+ }
45
71
  }
@@ -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.
@@ -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)'
@@ -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;