@vunexa/lixa 0.0.1-alpha.21 → 0.0.1-alpha.23

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.
@@ -1,3 +1,51 @@
1
+ /**
2
+ * OAuth 2.0 token response structure.
3
+ * Based on RFC 6749 Section 5.1 and OpenID Connect Core 1.0 Section 3.1.3.3
4
+ *
5
+ * @remarks
6
+ * This interface represents the standard OAuth 2.0 token response with
7
+ * optional OpenID Connect extensions. All OAuth providers should return
8
+ * at minimum the required fields (access_token, token_type).
9
+ *
10
+ * @public
11
+ */
12
+ export interface OAuthTokenResponse {
13
+ /**
14
+ * OAuth 2.0 access token (required).
15
+ * Used to access protected resources on behalf of the user.
16
+ */
17
+ access_token: string;
18
+ /**
19
+ * Token type (required).
20
+ * Typically "Bearer" for OAuth 2.0.
21
+ */
22
+ token_type: string;
23
+ /**
24
+ * Token expiration time in seconds (optional).
25
+ * Time until the access token expires.
26
+ */
27
+ expires_in?: number;
28
+ /**
29
+ * OAuth 2.0 refresh token (optional).
30
+ * Used to obtain new access tokens without re-authentication.
31
+ */
32
+ refresh_token?: string;
33
+ /**
34
+ * Granted OAuth scopes (optional).
35
+ * Space-separated list of scopes that were granted.
36
+ */
37
+ scope?: string;
38
+ /**
39
+ * OpenID Connect ID token (optional).
40
+ * JWT containing user identity claims (only present for OIDC providers).
41
+ */
42
+ id_token?: string;
43
+ /**
44
+ * Additional provider-specific fields.
45
+ * Some providers may include extra fields like user_id, account_id, etc.
46
+ */
47
+ [key: string]: unknown;
48
+ }
1
49
  /**
2
50
  * Represents a user session after successful OAuth authentication.
3
51
  *
@@ -10,7 +58,7 @@
10
58
  *
11
59
  * @public
12
60
  */
13
- export interface Session {
61
+ export interface Session<TRaw = OAuthTokenResponse> {
14
62
  /**
15
63
  * The session token or identifier.
16
64
  * This could be an access token, a session ID, a JWT, or any other identifier
@@ -30,7 +78,7 @@ export interface Session {
30
78
  * - id_token: OpenID Connect ID token (if using OIDC)
31
79
  * - scope: Granted scopes
32
80
  */
33
- raw: any;
81
+ raw: TRaw;
34
82
  }
35
83
  /**
36
84
  * Strategy interface for custom session creation.
@@ -50,10 +98,15 @@ export interface Session {
50
98
  * @example
51
99
  * Custom session strategy with database integration:
52
100
  * ```typescript
101
+ * interface CustomSessionData extends OAuthTokenResponse {
102
+ * userId: string;
103
+ * email: string;
104
+ * }
105
+ *
53
106
  * class DatabaseSessionStrategy implements SessionStrategy {
54
107
  * constructor(private db: Database) {}
55
108
  *
56
- * async createSession(tokenData: any): Promise<Session> {
109
+ * async createSession(tokenData: OAuthTokenResponse): Promise<Session<CustomSessionData>> {
57
110
  * // Decode ID token for OIDC providers
58
111
  * const idToken = tokenData.id_token;
59
112
  * const payload = decodeJwt(idToken);
@@ -74,7 +127,7 @@ export interface Session {
74
127
  * userId: user.id,
75
128
  * accessToken: tokenData.access_token,
76
129
  * refreshToken: tokenData.refresh_token,
77
- * expiresAt: new Date(Date.now() + tokenData.expires_in * 1000)
130
+ * expiresAt: new Date(Date.now() + (tokenData.expires_in || 3600) * 1000)
78
131
  * });
79
132
  *
80
133
  * return {
@@ -116,7 +169,7 @@ export interface SessionStrategy {
116
169
  * @example
117
170
  * Simple implementation:
118
171
  * ```typescript
119
- * async createSession(tokenData: any): Promise<Session> {
172
+ * async createSession(tokenData: OAuthTokenResponse): Promise<Session> {
120
173
  * return {
121
174
  * token: tokenData.access_token,
122
175
  * raw: tokenData
@@ -124,7 +177,7 @@ export interface SessionStrategy {
124
177
  * }
125
178
  * ```
126
179
  */
127
- createSession(tokenData: any): Promise<Session>;
180
+ createSession(tokenData: OAuthTokenResponse): Promise<Session>;
128
181
  }
129
182
  /**
130
183
  * Default session strategy that works with any OAuth provider.
@@ -140,6 +193,6 @@ export declare class DefaultSessionStrategy implements SessionStrategy {
140
193
  * @param tokenData - The token data received from the OAuth provider
141
194
  * @returns A Promise that resolves to a Session object
142
195
  */
143
- createSession(tokenData: any): Promise<Session>;
196
+ createSession(tokenData: OAuthTokenResponse): Promise<Session>;
144
197
  }
145
198
  //# sourceMappingURL=session.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/models/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,OAAO;IACtB;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;;;;;;;OAYG;IACH,GAAG,EAAE,GAAG,CAAC;CACV;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,aAAa,CAAC,SAAS,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACjD;AAED;;;;;GAKG;AACH,qBAAa,sBAAuB,YAAW,eAAe;IAC5D;;;;;;OAMG;IACG,aAAa,CAAC,SAAS,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;CAgBtD"}
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/models/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,OAAO,CAAC,IAAI,GAAG,kBAAkB;IAChD;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;;;;;;;OAYG;IACH,GAAG,EAAE,IAAI,CAAC;CACX;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,aAAa,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAChE;AAED;;;;;GAKG;AACH,qBAAa,sBAAuB,YAAW,eAAe;IAC5D;;;;;;OAMG;IACG,aAAa,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC;CAUrE"}
package/dist/types.d.ts CHANGED
@@ -3,6 +3,7 @@ import { SessionStrategy, Session } from "./models/session";
3
3
  import { IProvider } from "./providers/IProvider";
4
4
  export { SessionStrategy };
5
5
  export { Session };
6
+ export { OAuthTokenResponse } from "./models/session";
6
7
  export { IProvider };
7
8
  export { StateDao };
8
9
  export { SessionDao };
@@ -53,7 +54,7 @@ export type ProviderConfig = {
53
54
  /** Array of OAuth scopes to request */
54
55
  scopes: string[];
55
56
  /** Additional provider-specific configuration parameters */
56
- extraConfig?: Record<string, any>;
57
+ extraConfig?: Record<string, string>;
57
58
  } & ({
58
59
  provider?: never;
59
60
  } | {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGlD,OAAO,EAAE,eAAe,EAAE,CAAC;AAC3B,OAAO,EAAE,OAAO,EAAE,CAAC;AACnB,OAAO,EAAE,SAAS,EA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tB;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;IAElC;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IAExB;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,CAAC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,GAAG;IACvG,SAAS,EAAE,UAAU,CAAC;CACvB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vunexa/lixa",
3
- "version": "0.0.1-alpha.21",
3
+ "version": "0.0.1-alpha.23",
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",