@vunexa/lixa 0.0.1-alpha.16 → 0.0.1-alpha.18
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/dist/IProvider-2tDwRAnH.d.cts +18 -0
- package/dist/IProvider-2tDwRAnH.d.ts +18 -0
- package/dist/index.cjs +357 -15
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +261 -0
- package/dist/index.js +319 -10
- package/dist/index.js.map +1 -1
- package/dist/providers-entry.cjs +47 -26
- package/dist/providers-entry.cjs.map +1 -0
- package/dist/providers-entry.d.cts +25 -0
- package/dist/providers-entry.js +19 -21
- package/dist/providers-entry.js.map +1 -1
- package/package.json +20 -10
- package/dist/dao/session-cache.cjs +0 -24
- package/dist/dao/session-cache.js +0 -18
- package/dist/dao/session-cache.js.map +0 -1
- package/dist/dao/state-cache.cjs +0 -24
- package/dist/dao/state-cache.js +0 -18
- package/dist/dao/state-cache.js.map +0 -1
- package/dist/dao/types.cjs +0 -3
- package/dist/dao/types.js +0 -2
- package/dist/dao/types.js.map +0 -1
- package/dist/lixa.cjs +0 -295
- package/dist/lixa.js +0 -289
- package/dist/lixa.js.map +0 -1
- package/dist/models/session.cjs +0 -34
- package/dist/models/session.js +0 -30
- package/dist/models/session.js.map +0 -1
- package/dist/providers/IProvider.cjs +0 -3
- package/dist/providers/IProvider.js +0 -2
- package/dist/providers/IProvider.js.map +0 -1
- package/dist/providers/github.cjs +0 -15
- package/dist/providers/github.js +0 -12
- package/dist/providers/github.js.map +0 -1
- package/dist/providers/google.cjs +0 -15
- package/dist/providers/google.js +0 -12
- package/dist/providers/google.js.map +0 -1
- package/dist/providers/index.cjs +0 -8
- package/dist/providers/index.js +0 -3
- package/dist/providers/index.js.map +0 -1
- package/dist/types.cjs +0 -3
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/utils/constants.cjs +0 -8
- package/dist/utils/constants.js +0 -4
- package/dist/utils/constants.js.map +0 -1
package/dist/providers-entry.cjs
CHANGED
|
@@ -1,27 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
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
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/providers-entry.ts
|
|
21
|
+
var providers_entry_exports = {};
|
|
22
|
+
__export(providers_entry_exports, {
|
|
23
|
+
GithubProvider: () => GithubProvider,
|
|
24
|
+
GoogleProvider: () => GoogleProvider
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(providers_entry_exports);
|
|
27
|
+
|
|
28
|
+
// src/providers/github.ts
|
|
29
|
+
var GithubProvider = class {
|
|
30
|
+
providerType = "GITHUB";
|
|
31
|
+
authorizationEndpoint = "https://github.com/login/oauth/authorize";
|
|
32
|
+
tokenEndpoint = "https://github.com/login/oauth/access_token";
|
|
33
|
+
userInfoEndpoint = "https://api.github.com/user";
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// src/providers/google.ts
|
|
37
|
+
var GoogleProvider = class {
|
|
38
|
+
providerType = "GOOGLE";
|
|
39
|
+
authorizationEndpoint = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
40
|
+
tokenEndpoint = "https://oauth2.googleapis.com/token";
|
|
41
|
+
userInfoEndpoint = "https://www.googleapis.com/oauth2/v2/userinfo";
|
|
42
|
+
};
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
GithubProvider,
|
|
46
|
+
GoogleProvider
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=providers-entry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/providers-entry.ts","../src/providers/github.ts","../src/providers/google.ts"],"sourcesContent":["/**\n * Built-in OAuth providers for Lixa\n * \n * @remarks\n * Import and register these providers before using them in your Lixa configuration.\n * \n * @example\n * ```typescript\n * import { Lixa } from '@vunexa/lixa';\n * import { GoogleProvider, GithubProvider } from '@vunexa/lixa/providers';\n * \n * // Register the providers you want to use\n * Lixa.registerProvider({\n * google: new GoogleProvider(),\n * github: new GithubProvider(),\n * });\n * ```\n * \n * @packageDocumentation\n */\n\nexport { GoogleProvider, GithubProvider, type IProvider } from \"./providers\";","import { IProvider } from \"./IProvider\";\n\n/**\n * GitHub OAuth provider implementation\n * @public\n */\nclass GithubProvider implements IProvider {\n providerType = \"GITHUB\";\n authorizationEndpoint = \"https://github.com/login/oauth/authorize\";\n tokenEndpoint = \"https://github.com/login/oauth/access_token\";\n userInfoEndpoint = \"https://api.github.com/user\";\n}\n\nexport { GithubProvider };\n","import { IProvider } from \"./IProvider\";\n\n/**\n * Google OAuth provider implementation\n * @public\n */\nclass GoogleProvider implements IProvider {\n providerType = \"GOOGLE\";\n authorizationEndpoint = \"https://accounts.google.com/o/oauth2/v2/auth\";\n tokenEndpoint = \"https://oauth2.googleapis.com/token\";\n userInfoEndpoint = \"https://www.googleapis.com/oauth2/v2/userinfo\";\n}\n\nexport { GoogleProvider };"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,IAAM,iBAAN,MAA0C;AAAA,EACxC,eAAe;AAAA,EACf,wBAAwB;AAAA,EACxB,gBAAgB;AAAA,EAChB,mBAAmB;AACrB;;;ACLA,IAAM,iBAAN,MAA0C;AAAA,EACxC,eAAe;AAAA,EACf,wBAAwB;AAAA,EACxB,gBAAgB;AAAA,EAChB,mBAAmB;AACrB;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { I as IProvider } from './IProvider-2tDwRAnH.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GitHub OAuth provider implementation
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
declare class GithubProvider implements IProvider {
|
|
8
|
+
providerType: string;
|
|
9
|
+
authorizationEndpoint: string;
|
|
10
|
+
tokenEndpoint: string;
|
|
11
|
+
userInfoEndpoint: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Google OAuth provider implementation
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
declare class GoogleProvider implements IProvider {
|
|
19
|
+
providerType: string;
|
|
20
|
+
authorizationEndpoint: string;
|
|
21
|
+
tokenEndpoint: string;
|
|
22
|
+
userInfoEndpoint: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { GithubProvider, GoogleProvider, IProvider };
|
package/dist/providers-entry.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*/
|
|
21
|
-
export { GoogleProvider, GithubProvider } from "./providers";
|
|
1
|
+
// src/providers/github.ts
|
|
2
|
+
var GithubProvider = class {
|
|
3
|
+
providerType = "GITHUB";
|
|
4
|
+
authorizationEndpoint = "https://github.com/login/oauth/authorize";
|
|
5
|
+
tokenEndpoint = "https://github.com/login/oauth/access_token";
|
|
6
|
+
userInfoEndpoint = "https://api.github.com/user";
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// src/providers/google.ts
|
|
10
|
+
var GoogleProvider = class {
|
|
11
|
+
providerType = "GOOGLE";
|
|
12
|
+
authorizationEndpoint = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
13
|
+
tokenEndpoint = "https://oauth2.googleapis.com/token";
|
|
14
|
+
userInfoEndpoint = "https://www.googleapis.com/oauth2/v2/userinfo";
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
GithubProvider,
|
|
18
|
+
GoogleProvider
|
|
19
|
+
};
|
|
22
20
|
//# sourceMappingURL=providers-entry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/providers/github.ts","../src/providers/google.ts"],"sourcesContent":["import { IProvider } from \"./IProvider\";\n\n/**\n * GitHub OAuth provider implementation\n * @public\n */\nclass GithubProvider implements IProvider {\n providerType = \"GITHUB\";\n authorizationEndpoint = \"https://github.com/login/oauth/authorize\";\n tokenEndpoint = \"https://github.com/login/oauth/access_token\";\n userInfoEndpoint = \"https://api.github.com/user\";\n}\n\nexport { GithubProvider };\n","import { IProvider } from \"./IProvider\";\n\n/**\n * Google OAuth provider implementation\n * @public\n */\nclass GoogleProvider implements IProvider {\n providerType = \"GOOGLE\";\n authorizationEndpoint = \"https://accounts.google.com/o/oauth2/v2/auth\";\n tokenEndpoint = \"https://oauth2.googleapis.com/token\";\n userInfoEndpoint = \"https://www.googleapis.com/oauth2/v2/userinfo\";\n}\n\nexport { GoogleProvider };"],"mappings":";AAMA,IAAM,iBAAN,MAA0C;AAAA,EACxC,eAAe;AAAA,EACf,wBAAwB;AAAA,EACxB,gBAAgB;AAAA,EAChB,mBAAmB;AACrB;;;ACLA,IAAM,iBAAN,MAA0C;AAAA,EACxC,eAAe;AAAA,EACf,wBAAwB;AAAA,EACxB,gBAAgB;AAAA,EAChB,mBAAmB;AACrB;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vunexa/lixa",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.18",
|
|
4
4
|
"description": "Lixa is a flexible, provider-agnostic OAuth and OpenID Connect (OIDC) client library that simplifies multi-provider authentication flows. It supports seamless integration with providers like Google and GitHub, offers extensible session management, and enables dynamic provider resolution based on callback URLs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"oauth",
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"author": "vamsi",
|
|
11
11
|
"type": "module",
|
|
12
|
-
"main": "dist/index.
|
|
13
|
-
"
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/export-types/index.d.ts",
|
|
14
15
|
"exports": {
|
|
15
16
|
".": {
|
|
16
17
|
"types": "./dist/export-types/index.d.ts",
|
|
@@ -23,11 +24,17 @@
|
|
|
23
24
|
"require": "./dist/providers-entry.cjs"
|
|
24
25
|
}
|
|
25
26
|
},
|
|
27
|
+
"typesVersions": {
|
|
28
|
+
"*": {
|
|
29
|
+
"providers": [
|
|
30
|
+
"./dist/export-types/providers.d.ts"
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
26
34
|
"scripts": {
|
|
27
|
-
"build": "
|
|
28
|
-
"build:
|
|
29
|
-
"
|
|
30
|
-
"clean": "rm -rf dist dist-cjs",
|
|
35
|
+
"build": "tsup && npm run test && npm run build:api-docs",
|
|
36
|
+
"build:api-docs": "tsc --emitDeclarationOnly && api-extractor run --local && api-extractor run --local --config api-extractor-providers.json",
|
|
37
|
+
"clean": "rm -rf dist",
|
|
31
38
|
"prepublishOnly": "npm run clean && npm run build",
|
|
32
39
|
"lint": "eslint src/**/*.ts",
|
|
33
40
|
"lint:fix": "eslint src/**/*.ts --fix",
|
|
@@ -36,9 +43,11 @@
|
|
|
36
43
|
"test:coverage": "jest --coverage",
|
|
37
44
|
"api-extractor": "api-extractor run --local --verbose",
|
|
38
45
|
"docs:api": "npm run build && api-documenter markdown --input temp --output ./docs/api",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
46
|
+
"pub:alpha": "npm version prerelease --preid=alpha && npm publish --tag alpha",
|
|
47
|
+
"pub:beta": "npm version prerelease --preid=beta && npm publish --tag beta",
|
|
48
|
+
"pub:patch": "npm version patch && npm publish --tag latest",
|
|
49
|
+
"pub:minor": "npm version minor && npm publish --tag latest",
|
|
50
|
+
"pub:major": "npm version major && npm publish --tag latest"
|
|
42
51
|
},
|
|
43
52
|
"files": [
|
|
44
53
|
"dist",
|
|
@@ -59,6 +68,7 @@
|
|
|
59
68
|
"globals": "^16.3.0",
|
|
60
69
|
"jest": "^29.7.0",
|
|
61
70
|
"ts-jest": "^29.1.2",
|
|
71
|
+
"tsup": "^8.5.0",
|
|
62
72
|
"typescript": "^5.9.2"
|
|
63
73
|
},
|
|
64
74
|
"dependencies": {
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.LocalSessionCache = void 0;
|
|
7
|
-
const node_cache_1 = __importDefault(require("node-cache"));
|
|
8
|
-
class LocalSessionCache {
|
|
9
|
-
cache;
|
|
10
|
-
constructor(defaultTtlSeconds = 600) {
|
|
11
|
-
this.cache = new node_cache_1.default({ stdTTL: defaultTtlSeconds });
|
|
12
|
-
}
|
|
13
|
-
async saveSession(state, data, expiresInSeconds) {
|
|
14
|
-
this.cache.set(state, data, expiresInSeconds);
|
|
15
|
-
}
|
|
16
|
-
async getSession(state) {
|
|
17
|
-
return this.cache.get(state) || null;
|
|
18
|
-
}
|
|
19
|
-
async deleteSession(state) {
|
|
20
|
-
this.cache.del(state);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.LocalSessionCache = LocalSessionCache;
|
|
24
|
-
//# sourceMappingURL=session-cache.js.map
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import NodeCache from 'node-cache';
|
|
2
|
-
class LocalSessionCache {
|
|
3
|
-
cache;
|
|
4
|
-
constructor(defaultTtlSeconds = 600) {
|
|
5
|
-
this.cache = new NodeCache({ stdTTL: defaultTtlSeconds });
|
|
6
|
-
}
|
|
7
|
-
async saveSession(state, data, expiresInSeconds) {
|
|
8
|
-
this.cache.set(state, data, expiresInSeconds);
|
|
9
|
-
}
|
|
10
|
-
async getSession(state) {
|
|
11
|
-
return this.cache.get(state) || null;
|
|
12
|
-
}
|
|
13
|
-
async deleteSession(state) {
|
|
14
|
-
this.cache.del(state);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
export { LocalSessionCache };
|
|
18
|
-
//# sourceMappingURL=session-cache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session-cache.js","sourceRoot":"","sources":["../../src/dao/session-cache.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;AAGnC,MAAM,iBAAiB;IACb,KAAK,CAAY;IAEzB,YAAY,oBAA4B,GAAG;QACzC,IAAI,CAAC,KAAK,GAAG,IAAI,SAAS,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,KAAa,EAAE,IAAS,EAAE,gBAAwB;QAClE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,KAAa;QAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,KAAa;QAC/B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;CACF;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
package/dist/dao/state-cache.cjs
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.LocalStateCache = void 0;
|
|
7
|
-
const node_cache_1 = __importDefault(require("node-cache"));
|
|
8
|
-
class LocalStateCache {
|
|
9
|
-
cache;
|
|
10
|
-
constructor(defaultTtlSeconds = 600) {
|
|
11
|
-
this.cache = new node_cache_1.default({ stdTTL: defaultTtlSeconds });
|
|
12
|
-
}
|
|
13
|
-
async saveState(state, data, expiresInSeconds) {
|
|
14
|
-
this.cache.set(state, data, expiresInSeconds);
|
|
15
|
-
}
|
|
16
|
-
async getState(state) {
|
|
17
|
-
return this.cache.get(state) || null;
|
|
18
|
-
}
|
|
19
|
-
async deleteState(state) {
|
|
20
|
-
this.cache.del(state);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.LocalStateCache = LocalStateCache;
|
|
24
|
-
//# sourceMappingURL=state-cache.js.map
|
package/dist/dao/state-cache.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import NodeCache from 'node-cache';
|
|
2
|
-
class LocalStateCache {
|
|
3
|
-
cache;
|
|
4
|
-
constructor(defaultTtlSeconds = 600) {
|
|
5
|
-
this.cache = new NodeCache({ stdTTL: defaultTtlSeconds });
|
|
6
|
-
}
|
|
7
|
-
async saveState(state, data, expiresInSeconds) {
|
|
8
|
-
this.cache.set(state, data, expiresInSeconds);
|
|
9
|
-
}
|
|
10
|
-
async getState(state) {
|
|
11
|
-
return this.cache.get(state) || null;
|
|
12
|
-
}
|
|
13
|
-
async deleteState(state) {
|
|
14
|
-
this.cache.del(state);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
export { LocalStateCache };
|
|
18
|
-
//# sourceMappingURL=state-cache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"state-cache.js","sourceRoot":"","sources":["../../src/dao/state-cache.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;AAGnC,MAAM,eAAe;IACX,KAAK,CAAY;IAEzB,YAAY,oBAA4B,GAAG;QACzC,IAAI,CAAC,KAAK,GAAG,IAAI,SAAS,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,KAAa,EAAE,IAAS,EAAE,gBAAwB;QAChE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,KAAa;QAC7B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;CACF;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
package/dist/dao/types.cjs
DELETED
package/dist/dao/types.js
DELETED
package/dist/dao/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/dao/types.ts"],"names":[],"mappings":""}
|
package/dist/lixa.cjs
DELETED
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Lixa = void 0;
|
|
7
|
-
const crypto_1 = require("crypto");
|
|
8
|
-
const state_cache_1 = require("./dao/state-cache.cjs");
|
|
9
|
-
const crypto_2 = __importDefault(require("crypto"));
|
|
10
|
-
const session_cache_1 = require("./dao/session-cache.cjs");
|
|
11
|
-
const session_1 = require("./models/session.cjs");
|
|
12
|
-
/**
|
|
13
|
-
* A flexible, provider-agnostic OAuth 2.0 and OpenID Connect (OIDC) client library.
|
|
14
|
-
*
|
|
15
|
-
* @remarks
|
|
16
|
-
* Lixa simplifies multi-provider authentication flows and supports extensible session management.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* import { Lixa } from '@vunexa/lixa';
|
|
21
|
-
* import { GoogleProvider } from '@vunexa/lixa/providers';
|
|
22
|
-
*
|
|
23
|
-
* // Register providers before using them
|
|
24
|
-
* Lixa.registerProvider({ google: new GoogleProvider() });
|
|
25
|
-
*
|
|
26
|
-
* const config = Lixa.createConfig({
|
|
27
|
-
* providers: {
|
|
28
|
-
* google: {
|
|
29
|
-
* clientId: 'your-client-id',
|
|
30
|
-
* clientSecret: 'your-client-secret',
|
|
31
|
-
* redirectUri: 'https://yourapp.com/auth/google/callback',
|
|
32
|
-
* scopes: ['openid', 'email', 'profile']
|
|
33
|
-
* }
|
|
34
|
-
* }
|
|
35
|
-
* });
|
|
36
|
-
*
|
|
37
|
-
* const lixa = new Lixa(config);
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* @public
|
|
41
|
-
*/
|
|
42
|
-
class Lixa {
|
|
43
|
-
static CONFIGURED_PROVIDERS = new Map();
|
|
44
|
-
static LOCAL_STATE_CACHE = new state_cache_1.LocalStateCache();
|
|
45
|
-
static LOCAL_SESSION_CACHE = new session_cache_1.LocalSessionCache();
|
|
46
|
-
static DEFAULT_SESSION_STRATEGY = new session_1.DefaultSessionStrategy();
|
|
47
|
-
config;
|
|
48
|
-
stateDao;
|
|
49
|
-
sesionDao;
|
|
50
|
-
sessionStrategy;
|
|
51
|
-
/**
|
|
52
|
-
* Creates a new Lixa instance with the provided configuration.
|
|
53
|
-
*
|
|
54
|
-
* @param config - The configuration object containing provider settings and optional session strategy
|
|
55
|
-
*/
|
|
56
|
-
constructor(config) {
|
|
57
|
-
// Validate that all providers in config are registered
|
|
58
|
-
const configuredProviders = Object.keys(config.providers);
|
|
59
|
-
const registeredProviders = Lixa.getRegisteredProviders();
|
|
60
|
-
for (const provider of configuredProviders) {
|
|
61
|
-
if (!registeredProviders.includes(provider.toLowerCase())) {
|
|
62
|
-
throw new Error(`Provider '${provider}' is not registered. Please register it first using Lixa.registerProvider()`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
this.config = config;
|
|
66
|
-
this.stateDao = config.stateDao || Lixa.LOCAL_STATE_CACHE;
|
|
67
|
-
this.sesionDao = config.sessionDao || Lixa.LOCAL_SESSION_CACHE;
|
|
68
|
-
this.sessionStrategy = config.sessionStrategy || Lixa.DEFAULT_SESSION_STRATEGY;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Checks if a provider is both registered and configured for this instance.
|
|
72
|
-
* This is a type guard that narrows the provider type for use with getAuthUrl.
|
|
73
|
-
*
|
|
74
|
-
* @param provider - The provider name to check (case-insensitive)
|
|
75
|
-
* @returns True if the provider is registered and configured, false otherwise
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```typescript
|
|
79
|
-
* if (lixa.isProviderConfigured(provider)) {
|
|
80
|
-
* // TypeScript now knows provider is a valid ConfiguredProviderKey
|
|
81
|
-
* const authUrl = lixa.getAuthUrl(provider, state);
|
|
82
|
-
* }
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
isProviderConfigured(provider) {
|
|
86
|
-
const providerType = provider.toLowerCase();
|
|
87
|
-
return Lixa.CONFIGURED_PROVIDERS.has(providerType) &&
|
|
88
|
-
this.config.providers.hasOwnProperty(providerType);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Registers custom OAuth providers for use with Lixa.
|
|
92
|
-
*
|
|
93
|
-
* @param providerMap - A map of provider names to IProvider implementations
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* ```typescript
|
|
97
|
-
* class CustomProvider implements IProvider {
|
|
98
|
-
* authorizationEndpoint = 'https://custom.com/oauth/authorize';
|
|
99
|
-
* tokenEndpoint = 'https://custom.com/oauth/token';
|
|
100
|
-
* userInfoEndpoint = 'https://custom.com/api/user';
|
|
101
|
-
* }
|
|
102
|
-
*
|
|
103
|
-
* Lixa.registerProvider({ custom: new CustomProvider() });
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
static registerProvider(providerMap) {
|
|
107
|
-
Object.entries(providerMap).forEach(([key, providerImpl]) => {
|
|
108
|
-
Lixa.CONFIGURED_PROVIDERS.set(key.toLowerCase(), providerImpl);
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Gets the list of registered provider names.
|
|
113
|
-
*
|
|
114
|
-
* @returns Array of registered provider names
|
|
115
|
-
*/
|
|
116
|
-
static getRegisteredProviders() {
|
|
117
|
-
return Array.from(Lixa.CONFIGURED_PROVIDERS.keys());
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Creates a type-safe configuration that only allows registered providers.
|
|
121
|
-
*
|
|
122
|
-
* @param config - Configuration object with providers that must be registered
|
|
123
|
-
* @returns The same configuration object, but with type safety for registered providers
|
|
124
|
-
*/
|
|
125
|
-
static createConfig(config) {
|
|
126
|
-
// Validate that all providers in config are registered
|
|
127
|
-
const configuredProviders = Object.keys(config.providers);
|
|
128
|
-
const registeredProviders = Lixa.getRegisteredProviders();
|
|
129
|
-
for (const provider of configuredProviders) {
|
|
130
|
-
if (!registeredProviders.includes(provider.toLowerCase())) {
|
|
131
|
-
throw new Error(`Provider '${provider}' is not registered. Please register it first using Lixa.registerProvider()`);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return config;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Generates a cryptographically secure random state parameter for OAuth flows.
|
|
138
|
-
*
|
|
139
|
-
* @returns A 32-character hexadecimal string
|
|
140
|
-
*
|
|
141
|
-
* @remarks
|
|
142
|
-
* The state parameter is used to prevent CSRF attacks in OAuth flows.
|
|
143
|
-
*/
|
|
144
|
-
static generateRandomState() {
|
|
145
|
-
return (0, crypto_1.randomBytes)(16).toString("hex");
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Generates a cryptographically secure code verifier for PKCE flows.
|
|
149
|
-
*
|
|
150
|
-
* @returns A 64-character hexadecimal string
|
|
151
|
-
*
|
|
152
|
-
* @remarks
|
|
153
|
-
* The code verifier is used in PKCE (Proof Key for Code Exchange) to enhance security.
|
|
154
|
-
*/
|
|
155
|
-
static generateCodeVerifier() {
|
|
156
|
-
return (0, crypto_1.randomBytes)(32).toString("hex");
|
|
157
|
-
}
|
|
158
|
-
static buildCodeChallenge(codeVerifier) {
|
|
159
|
-
const hash = crypto_2.default
|
|
160
|
-
.createHash("sha256")
|
|
161
|
-
.update(codeVerifier)
|
|
162
|
-
.digest("base64");
|
|
163
|
-
// Convert to base64url
|
|
164
|
-
return hash.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Generates the authorization URL for the specified provider.
|
|
168
|
-
*
|
|
169
|
-
* @param provider - The provider name (must be a configured provider key)
|
|
170
|
-
* @param state - The state parameter for CSRF protection
|
|
171
|
-
* @returns The complete authorization URL to redirect users to
|
|
172
|
-
*
|
|
173
|
-
* @throws Error when the provider is not configured
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* ```typescript
|
|
177
|
-
* const state = Lixa.generateRandomState();
|
|
178
|
-
* const authUrl = lixa.getAuthUrl('google', state);
|
|
179
|
-
* res.redirect(authUrl);
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
182
|
-
getAuthUrl(provider, state) {
|
|
183
|
-
const providerType = String(provider).toLowerCase();
|
|
184
|
-
const providerConfig = this.findProviderByType(providerType);
|
|
185
|
-
const providerImpl = Lixa.CONFIGURED_PROVIDERS.get(providerType);
|
|
186
|
-
if (!providerConfig || !providerImpl) {
|
|
187
|
-
throw new Error(`Provider ${providerType} not configured`);
|
|
188
|
-
}
|
|
189
|
-
const codeVerifier = Lixa.generateCodeVerifier();
|
|
190
|
-
const codeChallenge = Lixa.buildCodeChallenge(codeVerifier);
|
|
191
|
-
// Cache the state paramaeter with TTL of 5 minutes (300 seconds)
|
|
192
|
-
// We dont care about value. we are onl interested in key existence
|
|
193
|
-
this.stateDao.saveState(state, {
|
|
194
|
-
createdAt: Date.now(),
|
|
195
|
-
provider: providerType,
|
|
196
|
-
codeVerifier,
|
|
197
|
-
}, 300 // 5 minutes in seconds
|
|
198
|
-
);
|
|
199
|
-
const params = new URLSearchParams({
|
|
200
|
-
client_id: providerConfig.clientId,
|
|
201
|
-
redirect_uri: providerConfig.redirectUri,
|
|
202
|
-
scope: providerConfig.scopes.join(" "),
|
|
203
|
-
state,
|
|
204
|
-
response_type: "code",
|
|
205
|
-
code_challenge: codeChallenge,
|
|
206
|
-
code_challenge_method: "S256",
|
|
207
|
-
...providerConfig.extraConfig,
|
|
208
|
-
});
|
|
209
|
-
return `${providerImpl.authorizationEndpoint}?${params.toString()}`;
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Handles the OAuth callback and creates a user session.
|
|
213
|
-
*
|
|
214
|
-
* @param provider - The provider name (must be a configured provider key)
|
|
215
|
-
* @param code - The authorization code from the provider
|
|
216
|
-
* @param state - The state parameter for validation
|
|
217
|
-
* @returns A Promise that resolves to the session ID
|
|
218
|
-
*
|
|
219
|
-
* @throws Error when code or state is missing/invalid, or provider is not configured
|
|
220
|
-
*
|
|
221
|
-
* @example
|
|
222
|
-
* ```typescript
|
|
223
|
-
* const sessionId = await lixa.handleCallback({
|
|
224
|
-
* provider: 'google',
|
|
225
|
-
* code: req.query.code,
|
|
226
|
-
* state: req.query.state
|
|
227
|
-
* });
|
|
228
|
-
* ```
|
|
229
|
-
*/
|
|
230
|
-
async handleCallback({ provider, code, state, }) {
|
|
231
|
-
if (!code || code.trim() === "") {
|
|
232
|
-
throw new Error("Invalid or missing code in callback");
|
|
233
|
-
}
|
|
234
|
-
if (!state || state.trim() === "") {
|
|
235
|
-
throw new Error("Invalid or missing state in callback");
|
|
236
|
-
}
|
|
237
|
-
//Validate state here
|
|
238
|
-
const cachedState = await this.stateDao.getState(state);
|
|
239
|
-
if (!cachedState) {
|
|
240
|
-
throw new Error("Invalid or expired state");
|
|
241
|
-
}
|
|
242
|
-
// State is valid, remove it from cache to prevent reuse
|
|
243
|
-
await this.stateDao.deleteState(state);
|
|
244
|
-
//Get code verifier from cached state
|
|
245
|
-
const codeVerifier = cachedState.codeVerifier;
|
|
246
|
-
const providerType = String(provider).toLowerCase();
|
|
247
|
-
const providerConfig = this.findProviderByType(providerType);
|
|
248
|
-
const providerImpl = Lixa.CONFIGURED_PROVIDERS.get(providerType);
|
|
249
|
-
if (!providerConfig || !providerImpl) {
|
|
250
|
-
throw new Error(`Provider ${String(provider)} not configured`);
|
|
251
|
-
}
|
|
252
|
-
// Exchange code for tokens and fetch user info here.
|
|
253
|
-
const tokens = await this.exchangeCodeForToken(code, providerConfig, providerImpl, codeVerifier);
|
|
254
|
-
const session = await this.sessionStrategy.createSession(tokens);
|
|
255
|
-
// Generate unique session ID
|
|
256
|
-
const sessionId = (0, crypto_1.randomBytes)(32).toString("hex");
|
|
257
|
-
// Store session with 24 hour TTL (86400 seconds)
|
|
258
|
-
await this.sesionDao.saveSession(sessionId, session, 86400);
|
|
259
|
-
return sessionId;
|
|
260
|
-
}
|
|
261
|
-
fetchSessionInfo(sessionId) {
|
|
262
|
-
return this.sesionDao.getSession(sessionId);
|
|
263
|
-
}
|
|
264
|
-
async exchangeCodeForToken(code, providerConfig, providerImpl, codeVerifier) {
|
|
265
|
-
// Build the request body
|
|
266
|
-
const body = {
|
|
267
|
-
client_id: providerConfig.clientId,
|
|
268
|
-
client_secret: providerConfig.clientSecret,
|
|
269
|
-
code,
|
|
270
|
-
redirect_uri: providerConfig.redirectUri,
|
|
271
|
-
grant_type: "authorization_code",
|
|
272
|
-
};
|
|
273
|
-
if (codeVerifier) {
|
|
274
|
-
body.code_verifier = codeVerifier;
|
|
275
|
-
}
|
|
276
|
-
const params = new URLSearchParams(body);
|
|
277
|
-
const response = await fetch(providerImpl.tokenEndpoint, {
|
|
278
|
-
method: "POST",
|
|
279
|
-
headers: {
|
|
280
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
281
|
-
Accept: "application/json",
|
|
282
|
-
},
|
|
283
|
-
body: params.toString(),
|
|
284
|
-
});
|
|
285
|
-
if (!response.ok) {
|
|
286
|
-
throw new Error(`Token exchange failed: ${response.status} ${response.statusText}`);
|
|
287
|
-
}
|
|
288
|
-
return response.json();
|
|
289
|
-
}
|
|
290
|
-
findProviderByType(providerType) {
|
|
291
|
-
return this.config.providers[providerType];
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
exports.Lixa = Lixa;
|
|
295
|
-
//# sourceMappingURL=lixa.js.map
|