@vunexa/lixa 0.0.1-alpha.26 → 0.0.1-alpha.28
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 +194 -0
- package/dist/export-types/index.d.ts +182 -14
- package/dist/index.cjs +116 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +178 -15
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +111 -3
- package/dist/index.js.map +1 -1
- package/dist/lixa.d.ts.map +1 -1
- package/dist/models/session.d.ts +89 -14
- package/dist/models/session.d.ts.map +1 -1
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/user-info.d.ts +89 -0
- package/dist/utils/user-info.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { OAuthTokenResponse } from "../models/session";
|
|
2
|
+
/**
|
|
3
|
+
* User information extracted from OAuth provider
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface UserInfo {
|
|
8
|
+
email: string;
|
|
9
|
+
id?: string | undefined;
|
|
10
|
+
sub?: string | undefined;
|
|
11
|
+
given_name?: string | undefined;
|
|
12
|
+
family_name?: string | undefined;
|
|
13
|
+
name?: string | undefined;
|
|
14
|
+
picture?: string | undefined;
|
|
15
|
+
email_verified?: boolean | undefined;
|
|
16
|
+
iss?: string | undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Decode JWT ID token to extract user information
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export declare function decodeIdToken(idToken: string): UserInfo;
|
|
24
|
+
/**
|
|
25
|
+
* Determine OAuth provider from ID token issuer
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export declare function determineProviderFromIssuer(userInfo: UserInfo): string | null;
|
|
30
|
+
/**
|
|
31
|
+
* Fetch user info from OAuth provider's userinfo endpoint
|
|
32
|
+
*
|
|
33
|
+
* @param accessToken - OAuth access token
|
|
34
|
+
* @param userInfoEndpoint - The provider's userinfo endpoint URL
|
|
35
|
+
* @param providerName - Provider name for error messages (optional)
|
|
36
|
+
* @returns User information from the provider
|
|
37
|
+
*
|
|
38
|
+
* @throws Error if the request fails or response is invalid
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export declare function fetchUserInfo(accessToken: string, userInfoEndpoint: string, providerName?: string): Promise<UserInfo>;
|
|
43
|
+
/**
|
|
44
|
+
* Extract user info from OAuth token data
|
|
45
|
+
*
|
|
46
|
+
* @param tokenData - OAuth token response from provider
|
|
47
|
+
* @param userInfoEndpoint - Optional userinfo endpoint URL (required if no ID token)
|
|
48
|
+
* @param providerName - Optional provider name for error messages
|
|
49
|
+
* @returns User info and detected provider name
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* This function attempts to extract user information in the following order:
|
|
53
|
+
* 1. Decode ID token if present (preferred method)
|
|
54
|
+
* 2. Fetch from userinfo endpoint using access token (requires userInfoEndpoint parameter)
|
|
55
|
+
*
|
|
56
|
+
* Provider detection:
|
|
57
|
+
* - Primary: Extract from ID token issuer field
|
|
58
|
+
* - Fallback: Use provider field in token data (if present)
|
|
59
|
+
* - Fallback: Use providerName parameter
|
|
60
|
+
* - Throws error if provider cannot be determined
|
|
61
|
+
*
|
|
62
|
+
* @throws Error if no ID token or access token is available
|
|
63
|
+
* @throws Error if provider cannot be determined
|
|
64
|
+
* @throws Error if userInfoEndpoint is required but not provided
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* With ID token (provider auto-detected):
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const { userInfo, provider } = await extractUserInfo(tokenData);
|
|
70
|
+
* console.log(`User ${userInfo.email} authenticated via ${provider}`);
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* Without ID token (requires userInfoEndpoint):
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const { userInfo, provider } = await extractUserInfo(
|
|
77
|
+
* tokenData,
|
|
78
|
+
* 'https://api.example.com/user',
|
|
79
|
+
* 'custom'
|
|
80
|
+
* );
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
export declare function extractUserInfo(tokenData: OAuthTokenResponse, userInfoEndpoint?: string, providerName?: string): Promise<{
|
|
86
|
+
userInfo: UserInfo;
|
|
87
|
+
provider: string;
|
|
88
|
+
}>;
|
|
89
|
+
//# sourceMappingURL=user-info.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-info.d.ts","sourceRoot":"","sources":["../../src/utils/user-info.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,cAAc,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACrC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,CAiBvD;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,CAiB7E;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CACjC,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,MAAM,EACxB,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,QAAQ,CAAC,CA8BnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAsB,eAAe,CACnC,SAAS,EAAE,kBAAkB,EAC7B,gBAAgB,CAAC,EAAE,MAAM,EACzB,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAoDnD"}
|
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.28",
|
|
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",
|