@vunexa/lixa 0.0.1-alpha.5 → 0.0.1-alpha.8
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/lixa.d.ts +20 -6
- package/dist/lixa.d.ts.map +1 -1
- package/dist/lixa.js +37 -7
- package/dist/lixa.js.map +1 -1
- package/index.d.ts +21 -6
- package/package.json +2 -2
package/dist/lixa.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { type LixaConfig, type Session } from "./types";
|
|
2
2
|
import { IProvider } from "./providers";
|
|
3
|
+
/**
|
|
4
|
+
* Type representing the keys of configured providers
|
|
5
|
+
*/
|
|
6
|
+
type ConfiguredProviderKey<T extends LixaConfig> = keyof T['providers'];
|
|
3
7
|
/**
|
|
4
8
|
* A flexible, provider-agnostic OAuth 2.0 and OpenID Connect (OIDC) client library.
|
|
5
9
|
*
|
|
@@ -22,7 +26,7 @@ import { IProvider } from "./providers";
|
|
|
22
26
|
*
|
|
23
27
|
* @public
|
|
24
28
|
*/
|
|
25
|
-
declare class Lixa {
|
|
29
|
+
declare class Lixa<TConfig extends LixaConfig = LixaConfig> {
|
|
26
30
|
private static CONFIGURED_PROVIDERS;
|
|
27
31
|
private static LOCAL_STATE_CACHE;
|
|
28
32
|
private config;
|
|
@@ -32,7 +36,7 @@ declare class Lixa {
|
|
|
32
36
|
*
|
|
33
37
|
* @param config - The configuration object containing provider settings and optional session strategy
|
|
34
38
|
*/
|
|
35
|
-
constructor(config:
|
|
39
|
+
constructor(config: TConfig);
|
|
36
40
|
/**
|
|
37
41
|
* Checks if a provider is registered and available for use.
|
|
38
42
|
*
|
|
@@ -75,10 +79,20 @@ declare class Lixa {
|
|
|
75
79
|
* The state parameter is used to prevent CSRF attacks in OAuth flows.
|
|
76
80
|
*/
|
|
77
81
|
static generateRandomState(): string;
|
|
82
|
+
/**
|
|
83
|
+
* Generates a cryptographically secure code verifier for PKCE flows.
|
|
84
|
+
*
|
|
85
|
+
* @returns A 64-character hexadecimal string
|
|
86
|
+
*
|
|
87
|
+
* @remarks
|
|
88
|
+
* The code verifier is used in PKCE (Proof Key for Code Exchange) to enhance security.
|
|
89
|
+
*/
|
|
90
|
+
private static generateCodeVerifier;
|
|
91
|
+
private static buildCodeChallenge;
|
|
78
92
|
/**
|
|
79
93
|
* Generates the authorization URL for the specified provider.
|
|
80
94
|
*
|
|
81
|
-
* @param provider - The provider name (
|
|
95
|
+
* @param provider - The provider name (must be a configured provider key)
|
|
82
96
|
* @param state - The state parameter for CSRF protection
|
|
83
97
|
* @returns The complete authorization URL to redirect users to
|
|
84
98
|
*
|
|
@@ -91,11 +105,11 @@ declare class Lixa {
|
|
|
91
105
|
* res.redirect(authUrl);
|
|
92
106
|
* ```
|
|
93
107
|
*/
|
|
94
|
-
getAuthUrl(provider:
|
|
108
|
+
getAuthUrl(provider: ConfiguredProviderKey<TConfig>, state: string): string;
|
|
95
109
|
/**
|
|
96
110
|
* Handles the OAuth callback and creates a user session.
|
|
97
111
|
*
|
|
98
|
-
* @param provider - The provider name
|
|
112
|
+
* @param provider - The provider name (must be a configured provider key)
|
|
99
113
|
* @param code - The authorization code from the provider
|
|
100
114
|
* @param state - The state parameter for validation
|
|
101
115
|
* @returns A Promise that resolves to a Session object
|
|
@@ -112,7 +126,7 @@ declare class Lixa {
|
|
|
112
126
|
* ```
|
|
113
127
|
*/
|
|
114
128
|
handleCallback({ provider, code, state, }: {
|
|
115
|
-
provider:
|
|
129
|
+
provider: ConfiguredProviderKey<TConfig>;
|
|
116
130
|
code: string;
|
|
117
131
|
state?: string;
|
|
118
132
|
}): Promise<Session>;
|
package/dist/lixa.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lixa.d.ts","sourceRoot":"","sources":["../src/lixa.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAuB,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,E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AC,CAAC;QACzC,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GAAG,OAAO,CAAC,OAAO,CAAC;YAmDN,oBAAoB;IAsClC,OAAO,CAAC,kBAAkB;CAG3B;AAED,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
package/dist/lixa.js
CHANGED
|
@@ -2,6 +2,7 @@ import { randomBytes } from "crypto";
|
|
|
2
2
|
import { GithubProvider, GoogleProvider } from "./providers";
|
|
3
3
|
import { GITHUB, GOOGLE } from "./utils/constants";
|
|
4
4
|
import { LocalStateCache } from "./dao/state-cache";
|
|
5
|
+
import crypto from "crypto";
|
|
5
6
|
/**
|
|
6
7
|
* A flexible, provider-agnostic OAuth 2.0 and OpenID Connect (OIDC) client library.
|
|
7
8
|
*
|
|
@@ -94,10 +95,29 @@ class Lixa {
|
|
|
94
95
|
static generateRandomState() {
|
|
95
96
|
return randomBytes(16).toString("hex");
|
|
96
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Generates a cryptographically secure code verifier for PKCE flows.
|
|
100
|
+
*
|
|
101
|
+
* @returns A 64-character hexadecimal string
|
|
102
|
+
*
|
|
103
|
+
* @remarks
|
|
104
|
+
* The code verifier is used in PKCE (Proof Key for Code Exchange) to enhance security.
|
|
105
|
+
*/
|
|
106
|
+
static generateCodeVerifier() {
|
|
107
|
+
return randomBytes(32).toString("hex");
|
|
108
|
+
}
|
|
109
|
+
static buildCodeChallenge(codeVerifier) {
|
|
110
|
+
const hash = crypto
|
|
111
|
+
.createHash("sha256")
|
|
112
|
+
.update(codeVerifier)
|
|
113
|
+
.digest("base64");
|
|
114
|
+
// Convert to base64url
|
|
115
|
+
return hash.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
116
|
+
}
|
|
97
117
|
/**
|
|
98
118
|
* Generates the authorization URL for the specified provider.
|
|
99
119
|
*
|
|
100
|
-
* @param provider - The provider name (
|
|
120
|
+
* @param provider - The provider name (must be a configured provider key)
|
|
101
121
|
* @param state - The state parameter for CSRF protection
|
|
102
122
|
* @returns The complete authorization URL to redirect users to
|
|
103
123
|
*
|
|
@@ -111,15 +131,21 @@ class Lixa {
|
|
|
111
131
|
* ```
|
|
112
132
|
*/
|
|
113
133
|
getAuthUrl(provider, state) {
|
|
114
|
-
const providerType = provider.toLowerCase();
|
|
134
|
+
const providerType = String(provider).toLowerCase();
|
|
115
135
|
const providerConfig = this.findProviderByType(providerType);
|
|
116
136
|
const providerImpl = Lixa.CONFIGURED_PROVIDERS.get(providerType);
|
|
117
137
|
if (!providerConfig || !providerImpl) {
|
|
118
138
|
throw new Error(`Provider ${providerType} not configured`);
|
|
119
139
|
}
|
|
140
|
+
const codeVerifier = Lixa.generateCodeVerifier();
|
|
141
|
+
const codeChallenge = Lixa.buildCodeChallenge(codeVerifier);
|
|
120
142
|
// Cache the state paramaeter with TTL of 5 minutes (300 seconds)
|
|
121
143
|
// We dont care about value. we are onl interested in key existence
|
|
122
|
-
this.stateDao.saveState(state,
|
|
144
|
+
this.stateDao.saveState(state, {
|
|
145
|
+
createdAt: Date.now(),
|
|
146
|
+
provider: providerType,
|
|
147
|
+
codeVerifier,
|
|
148
|
+
}, 300 // 5 minutes in seconds
|
|
123
149
|
);
|
|
124
150
|
const params = new URLSearchParams({
|
|
125
151
|
client_id: providerConfig.clientId,
|
|
@@ -127,6 +153,8 @@ class Lixa {
|
|
|
127
153
|
scope: providerConfig.scopes.join(" "),
|
|
128
154
|
state,
|
|
129
155
|
response_type: "code",
|
|
156
|
+
code_challenge: codeChallenge,
|
|
157
|
+
code_challenge_method: "S256",
|
|
130
158
|
...providerConfig.extraConfig,
|
|
131
159
|
});
|
|
132
160
|
return `${providerImpl.authorizationEndpoint}?${params.toString()}`;
|
|
@@ -134,7 +162,7 @@ class Lixa {
|
|
|
134
162
|
/**
|
|
135
163
|
* Handles the OAuth callback and creates a user session.
|
|
136
164
|
*
|
|
137
|
-
* @param provider - The provider name
|
|
165
|
+
* @param provider - The provider name (must be a configured provider key)
|
|
138
166
|
* @param code - The authorization code from the provider
|
|
139
167
|
* @param state - The state parameter for validation
|
|
140
168
|
* @returns A Promise that resolves to a Session object
|
|
@@ -164,14 +192,16 @@ class Lixa {
|
|
|
164
192
|
}
|
|
165
193
|
// State is valid, remove it from cache to prevent reuse
|
|
166
194
|
await this.stateDao.deleteState(state);
|
|
167
|
-
|
|
195
|
+
//Get code verifier from cached state
|
|
196
|
+
const codeVerifier = cachedState.codeVerifier;
|
|
197
|
+
const providerType = String(provider).toLowerCase();
|
|
168
198
|
const providerConfig = this.findProviderByType(providerType);
|
|
169
199
|
const providerImpl = Lixa.CONFIGURED_PROVIDERS.get(providerType);
|
|
170
200
|
if (!providerConfig || !providerImpl) {
|
|
171
|
-
throw new Error(`Provider ${provider} not configured`);
|
|
201
|
+
throw new Error(`Provider ${String(provider)} not configured`);
|
|
172
202
|
}
|
|
173
203
|
// Exchange code for tokens and fetch user info here.
|
|
174
|
-
const tokens = await this.exchangeCodeForToken(code, providerConfig, providerImpl);
|
|
204
|
+
const tokens = await this.exchangeCodeForToken(code, providerConfig, providerImpl, codeVerifier);
|
|
175
205
|
// For simplicity, we'll just return the tokens as the session.
|
|
176
206
|
// In a real implementation, you'd fetch user info and create a session.
|
|
177
207
|
const session = {
|
package/dist/lixa.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lixa.js","sourceRoot":"","sources":["../src/lixa.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAa,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"lixa.js","sourceRoot":"","sources":["../src/lixa.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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SAAS,EAAE,cAAc,CAAC,QAAQ;YAClC,aAAa,EAAE,cAAc,CAAC,YAAY;YAC1C,IAAI;YACJ,YAAY,EAAE,cAAc,CAAC,WAAW;YACxC,UAAU,EAAE,oBAAoB;SACjC,CAAC;QAEF,IAAI,YAAY,EAAE,CAAC;YACjB,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QACpC,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;QAEzC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,YAAY,CAAC,aAAa,EAAE;YACvD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,mCAAmC;gBACnD,MAAM,EAAE,kBAAkB;aAC3B;YACD,IAAI,EAAE,MAAM,CAAC,QAAQ,EAAE;SACxB,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,0BAA0B,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CACnE,CAAC;QACJ,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;IAEO,kBAAkB,CAAC,YAAoB;QAC7C,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;IAC7C,CAAC;;AAGH,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
package/index.d.ts
CHANGED
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
* @packageDocumentation
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Type representing the keys of configured providers
|
|
12
|
+
*/
|
|
13
|
+
declare type ConfiguredProviderKey<T extends LixaConfig> = keyof T['providers'];
|
|
14
|
+
|
|
10
15
|
/**
|
|
11
16
|
* Interface for OAuth provider implementations.
|
|
12
17
|
*
|
|
@@ -46,7 +51,7 @@ export declare interface IProvider {
|
|
|
46
51
|
*
|
|
47
52
|
* @public
|
|
48
53
|
*/
|
|
49
|
-
export declare class Lixa {
|
|
54
|
+
export declare class Lixa<TConfig extends LixaConfig = LixaConfig> {
|
|
50
55
|
private static CONFIGURED_PROVIDERS;
|
|
51
56
|
private static LOCAL_STATE_CACHE;
|
|
52
57
|
private config;
|
|
@@ -56,7 +61,7 @@ export declare class Lixa {
|
|
|
56
61
|
*
|
|
57
62
|
* @param config - The configuration object containing provider settings and optional session strategy
|
|
58
63
|
*/
|
|
59
|
-
constructor(config:
|
|
64
|
+
constructor(config: TConfig);
|
|
60
65
|
/**
|
|
61
66
|
* Checks if a provider is registered and available for use.
|
|
62
67
|
*
|
|
@@ -99,10 +104,20 @@ export declare class Lixa {
|
|
|
99
104
|
* The state parameter is used to prevent CSRF attacks in OAuth flows.
|
|
100
105
|
*/
|
|
101
106
|
static generateRandomState(): string;
|
|
107
|
+
/**
|
|
108
|
+
* Generates a cryptographically secure code verifier for PKCE flows.
|
|
109
|
+
*
|
|
110
|
+
* @returns A 64-character hexadecimal string
|
|
111
|
+
*
|
|
112
|
+
* @remarks
|
|
113
|
+
* The code verifier is used in PKCE (Proof Key for Code Exchange) to enhance security.
|
|
114
|
+
*/
|
|
115
|
+
private static generateCodeVerifier;
|
|
116
|
+
private static buildCodeChallenge;
|
|
102
117
|
/**
|
|
103
118
|
* Generates the authorization URL for the specified provider.
|
|
104
119
|
*
|
|
105
|
-
* @param provider - The provider name (
|
|
120
|
+
* @param provider - The provider name (must be a configured provider key)
|
|
106
121
|
* @param state - The state parameter for CSRF protection
|
|
107
122
|
* @returns The complete authorization URL to redirect users to
|
|
108
123
|
*
|
|
@@ -115,11 +130,11 @@ export declare class Lixa {
|
|
|
115
130
|
* res.redirect(authUrl);
|
|
116
131
|
* ```
|
|
117
132
|
*/
|
|
118
|
-
getAuthUrl(provider:
|
|
133
|
+
getAuthUrl(provider: ConfiguredProviderKey<TConfig>, state: string): string;
|
|
119
134
|
/**
|
|
120
135
|
* Handles the OAuth callback and creates a user session.
|
|
121
136
|
*
|
|
122
|
-
* @param provider - The provider name
|
|
137
|
+
* @param provider - The provider name (must be a configured provider key)
|
|
123
138
|
* @param code - The authorization code from the provider
|
|
124
139
|
* @param state - The state parameter for validation
|
|
125
140
|
* @returns A Promise that resolves to a Session object
|
|
@@ -136,7 +151,7 @@ export declare class Lixa {
|
|
|
136
151
|
* ```
|
|
137
152
|
*/
|
|
138
153
|
handleCallback({ provider, code, state, }: {
|
|
139
|
-
provider:
|
|
154
|
+
provider: ConfiguredProviderKey<TConfig>;
|
|
140
155
|
code: string;
|
|
141
156
|
state?: string;
|
|
142
157
|
}): Promise<Session>;
|
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.8",
|
|
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",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"test:watch": "jest --watch",
|
|
28
28
|
"test:coverage": "jest --coverage",
|
|
29
29
|
"api-extractor": "api-extractor run --local --verbose",
|
|
30
|
-
"docs:api": "npm run build && api-documenter markdown --input temp --output docs/api",
|
|
30
|
+
"docs:api": "npm run build && api-documenter markdown --input temp --output ./docs/api",
|
|
31
31
|
"publish:alpha": "npm run build && npm version prerelease --preid=alpha && npm publish --tag alpha",
|
|
32
32
|
"publish:beta": "npm run build && npm version prerelease --preid=beta && npm publish --tag beta",
|
|
33
33
|
"publish:stable": "npm run build && npm version patch && npm publish --tag latest"
|