@vunexa/lixa 0.0.1-alpha.8 → 0.1.0
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 +263 -143
- package/dist/dao/session-cache.d.ts +11 -0
- package/dist/dao/session-cache.d.ts.map +1 -0
- package/dist/dao/state-cache.d.ts +8 -6
- package/dist/dao/state-cache.d.ts.map +1 -1
- package/dist/dao/types.d.ts +376 -3
- package/dist/dao/types.d.ts.map +1 -1
- package/dist/export-types/index.d.ts +1397 -0
- package/dist/export-types/tsdoc-metadata.json +11 -0
- package/dist/index.cjs +1035 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1361 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +992 -9
- package/dist/index.js.map +1 -1
- package/dist/lixa.d.ts +286 -19
- package/dist/lixa.d.ts.map +1 -1
- package/dist/models/session.d.ts +316 -0
- package/dist/models/session.d.ts.map +1 -0
- package/dist/providers/IProvider.d.ts +127 -4
- package/dist/providers/IProvider.d.ts.map +1 -1
- package/dist/providers/index.d.ts +0 -2
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/types.d.ts +195 -24
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/user-info.d.ts +82 -0
- package/dist/utils/user-info.d.ts.map +1 -0
- package/package.json +15 -10
- package/dist/dao/state-cache.js +0 -18
- package/dist/dao/state-cache.js.map +0 -1
- package/dist/dao/types.js +0 -2
- package/dist/dao/types.js.map +0 -1
- package/dist/lixa.js +0 -248
- package/dist/lixa.js.map +0 -1
- package/dist/providers/IProvider.js +0 -2
- package/dist/providers/IProvider.js.map +0 -1
- package/dist/providers/github.d.ts +0 -9
- package/dist/providers/github.d.ts.map +0 -1
- package/dist/providers/github.js +0 -8
- package/dist/providers/github.js.map +0 -1
- package/dist/providers/google.d.ts +0 -9
- package/dist/providers/google.d.ts.map +0 -1
- package/dist/providers/google.js +0 -8
- package/dist/providers/google.js.map +0 -1
- package/dist/providers/index.js +0 -3
- package/dist/providers/index.js.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/utils/constants.js +0 -4
- package/dist/utils/constants.js.map +0 -1
- package/index.d.ts +0 -227
|
@@ -0,0 +1,316 @@
|
|
|
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]: string | number | boolean | undefined;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Represents a linked provider account within a user's session.
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export interface LinkedAccount {
|
|
55
|
+
/** The provider identifier (e.g. 'github', 'google') */
|
|
56
|
+
provider: string;
|
|
57
|
+
/** Provider user ID if available */
|
|
58
|
+
providerUserId?: string | undefined;
|
|
59
|
+
/** User email for this provider */
|
|
60
|
+
email?: string | undefined;
|
|
61
|
+
/** OAuth access token for this provider */
|
|
62
|
+
accessToken: string;
|
|
63
|
+
/** Full raw token response from provider */
|
|
64
|
+
raw: OAuthTokenResponse;
|
|
65
|
+
/** Unix timestamp in milliseconds when account was linked */
|
|
66
|
+
linkedAt: number;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Represents a connected resource provider token (e.g. GitHub Repo access, Google Drive)
|
|
70
|
+
* obtained post-authentication via Lixa's Resource Connection API.
|
|
71
|
+
*
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
export interface ConnectedResource {
|
|
75
|
+
/** The provider identifier (e.g. 'github', 'google', 'slack') */
|
|
76
|
+
provider: string;
|
|
77
|
+
/** Resource access token */
|
|
78
|
+
accessToken: string;
|
|
79
|
+
/** Optional refresh token for offline resource access */
|
|
80
|
+
refreshToken?: string | undefined;
|
|
81
|
+
/** Resource scopes granted by the user */
|
|
82
|
+
scopes: string[];
|
|
83
|
+
/** Full raw token response from provider */
|
|
84
|
+
raw: OAuthTokenResponse;
|
|
85
|
+
/** Unix timestamp in milliseconds when resource was connected */
|
|
86
|
+
connectedAt: number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Represents a user session after successful OAuth authentication.
|
|
90
|
+
*
|
|
91
|
+
* @remarks
|
|
92
|
+
* The Session object is returned by SessionStrategy.createSession() and contains
|
|
93
|
+
* the session identifier and any additional data needed for your application.
|
|
94
|
+
*
|
|
95
|
+
* The structure is intentionally flexible to support various session management
|
|
96
|
+
* approaches (JWT tokens, session IDs, multi-SSO account linking, connected resources, etc.).
|
|
97
|
+
*
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
export interface Session<TRaw = OAuthTokenResponse> {
|
|
101
|
+
/**
|
|
102
|
+
* Unique session ID generated by Lixa upon authentication.
|
|
103
|
+
*/
|
|
104
|
+
id?: string;
|
|
105
|
+
/**
|
|
106
|
+
* The primary access token or session token identifier.
|
|
107
|
+
*/
|
|
108
|
+
token: string;
|
|
109
|
+
/** Unique unified user ID across linked accounts */
|
|
110
|
+
userId?: string;
|
|
111
|
+
/** Primary user email */
|
|
112
|
+
email?: string;
|
|
113
|
+
/** Current active auth provider for this session turn */
|
|
114
|
+
provider?: string;
|
|
115
|
+
/** Linked SSO provider accounts keyed by provider name */
|
|
116
|
+
accounts?: Record<string, LinkedAccount>;
|
|
117
|
+
/** Connected third-party resource provider tokens keyed by provider name */
|
|
118
|
+
resources?: Record<string, ConnectedResource>;
|
|
119
|
+
/**
|
|
120
|
+
* Raw session data.
|
|
121
|
+
* Contains the complete OAuth token response and any additional data
|
|
122
|
+
* your SessionStrategy adds (user info, database IDs, etc.).
|
|
123
|
+
*/
|
|
124
|
+
raw: TRaw;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Provider metadata passed to session strategy.
|
|
128
|
+
* Contains provider name and endpoints for user info extraction.
|
|
129
|
+
*
|
|
130
|
+
* @public
|
|
131
|
+
*/
|
|
132
|
+
export interface ProviderMetadata {
|
|
133
|
+
/** The provider name (e.g., 'google', 'github') */
|
|
134
|
+
name: string;
|
|
135
|
+
/** Provider endpoints */
|
|
136
|
+
endpoints: {
|
|
137
|
+
/** Authorization endpoint URL */
|
|
138
|
+
authorization: string;
|
|
139
|
+
/** Token endpoint URL */
|
|
140
|
+
token: string;
|
|
141
|
+
/** UserInfo endpoint URL */
|
|
142
|
+
userInfo: string;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Strategy interface for custom session creation.
|
|
147
|
+
*
|
|
148
|
+
* @remarks
|
|
149
|
+
* Implement this interface to customize how OAuth tokens are converted into
|
|
150
|
+
* application sessions. This is where you typically:
|
|
151
|
+
* - Decode ID tokens (for OpenID Connect)
|
|
152
|
+
* - Look up or create users in your database
|
|
153
|
+
* - Generate session identifiers
|
|
154
|
+
* - Store session data
|
|
155
|
+
* - Add custom claims or metadata
|
|
156
|
+
*
|
|
157
|
+
* The default implementation (DefaultSessionStrategy) simply extracts the
|
|
158
|
+
* access token and returns it as the session token.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* Custom session strategy with database integration:
|
|
162
|
+
* ```typescript
|
|
163
|
+
* interface CustomSessionData {
|
|
164
|
+
* userId: string;
|
|
165
|
+
* email: string;
|
|
166
|
+
* provider: string;
|
|
167
|
+
* accessToken: string;
|
|
168
|
+
* refreshToken?: string;
|
|
169
|
+
* expiresAt: number;
|
|
170
|
+
* }
|
|
171
|
+
*
|
|
172
|
+
* class DatabaseSessionStrategy implements SessionStrategy {
|
|
173
|
+
* constructor(private db: Database) {}
|
|
174
|
+
*
|
|
175
|
+
* async createSession(oauthContext: OAuthContext): Promise<Session<CustomSessionData>> {
|
|
176
|
+
* // User info is already extracted by Lixa!
|
|
177
|
+
* const { userInfo, provider, tokenData } = oauthContext;
|
|
178
|
+
*
|
|
179
|
+
* // Create or update user in database
|
|
180
|
+
* const user = await this.db.users.upsert({
|
|
181
|
+
* email: userInfo.email,
|
|
182
|
+
* name: userInfo.name,
|
|
183
|
+
* picture: userInfo.picture
|
|
184
|
+
* });
|
|
185
|
+
*
|
|
186
|
+
* // Generate session ID
|
|
187
|
+
* const sessionId = generateSecureId();
|
|
188
|
+
*
|
|
189
|
+
* // Store session with tokens
|
|
190
|
+
* await this.db.sessions.create({
|
|
191
|
+
* id: sessionId,
|
|
192
|
+
* userId: user.id,
|
|
193
|
+
* accessToken: tokenData.access_token,
|
|
194
|
+
* refreshToken: tokenData.refresh_token,
|
|
195
|
+
* expiresAt: new Date(Date.now() + (tokenData.expires_in || 3600) * 1000)
|
|
196
|
+
* });
|
|
197
|
+
*
|
|
198
|
+
* return {
|
|
199
|
+
* token: sessionId,
|
|
200
|
+
* raw: {
|
|
201
|
+
* userId: user.id,
|
|
202
|
+
* email: user.email,
|
|
203
|
+
* provider,
|
|
204
|
+
* accessToken: tokenData.access_token,
|
|
205
|
+
* refreshToken: tokenData.refresh_token,
|
|
206
|
+
* expiresAt: Date.now() + (tokenData.expires_in || 3600) * 1000
|
|
207
|
+
* }
|
|
208
|
+
* };
|
|
209
|
+
* }
|
|
210
|
+
* }
|
|
211
|
+
* ```
|
|
212
|
+
*
|
|
213
|
+
* @public
|
|
214
|
+
*/
|
|
215
|
+
export interface SessionStrategy {
|
|
216
|
+
/**
|
|
217
|
+
* Creates a session from OAuth token data.
|
|
218
|
+
*
|
|
219
|
+
* @param tokenData - The token data received from the OAuth provider's token endpoint
|
|
220
|
+
* @param providerMetadata - Provider metadata including name and endpoints
|
|
221
|
+
* @returns A Promise that resolves to a Session object
|
|
222
|
+
*
|
|
223
|
+
* @remarks
|
|
224
|
+
* This method is called after successfully exchanging the authorization code
|
|
225
|
+
* for tokens. You receive:
|
|
226
|
+
*
|
|
227
|
+
* Token Data:
|
|
228
|
+
* - access_token: OAuth access token
|
|
229
|
+
* - refresh_token: OAuth refresh token (optional)
|
|
230
|
+
* - expires_in: Token expiration time in seconds
|
|
231
|
+
* - token_type: Token type (usually "Bearer")
|
|
232
|
+
* - id_token: OpenID Connect ID token (for OIDC providers)
|
|
233
|
+
* - scope: Granted scopes
|
|
234
|
+
*
|
|
235
|
+
* Provider Metadata:
|
|
236
|
+
* - name: The provider name (e.g., 'google', 'github')
|
|
237
|
+
* - endpoints: Provider endpoints (authorization, token, userInfo)
|
|
238
|
+
*
|
|
239
|
+
* The providerMetadata.endpoints.userInfo can be used with extractUserInfo():
|
|
240
|
+
* ```typescript
|
|
241
|
+
* import { extractUserInfo } from '@vunexa/lixa';
|
|
242
|
+
*
|
|
243
|
+
* const { userInfo } = await extractUserInfo(
|
|
244
|
+
* tokenData,
|
|
245
|
+
* providerMetadata.endpoints.userInfo,
|
|
246
|
+
* providerMetadata.name
|
|
247
|
+
* );
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* Your session strategy should:
|
|
251
|
+
* 1. Extract user info (using extractUserInfo or decode ID token)
|
|
252
|
+
* 2. Create or lookup users in your database
|
|
253
|
+
* 3. Generate session identifiers
|
|
254
|
+
* 4. Store session data as needed
|
|
255
|
+
* 5. Return a Session object with token and raw data
|
|
256
|
+
*
|
|
257
|
+
* @throws \{Error\} If session creation fails (e.g., database error, invalid token)
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* Simple implementation:
|
|
261
|
+
* ```typescript
|
|
262
|
+
* async createSession(tokenData: OAuthTokenResponse): Promise<Session> {
|
|
263
|
+
* return {
|
|
264
|
+
* token: tokenData.access_token,
|
|
265
|
+
* raw: tokenData
|
|
266
|
+
* };
|
|
267
|
+
* }
|
|
268
|
+
* ```
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* Database integration with user info extraction:
|
|
272
|
+
* ```typescript
|
|
273
|
+
* async createSession(
|
|
274
|
+
* tokenData: OAuthTokenResponse,
|
|
275
|
+
* providerMetadata: ProviderMetadata
|
|
276
|
+
* ): Promise<Session> {
|
|
277
|
+
* // Extract user info from token or userinfo endpoint
|
|
278
|
+
* const { userInfo } = await extractUserInfo(
|
|
279
|
+
* tokenData,
|
|
280
|
+
* providerMetadata.endpoints.userInfo,
|
|
281
|
+
* providerMetadata.name
|
|
282
|
+
* );
|
|
283
|
+
*
|
|
284
|
+
* // Create or update user in database
|
|
285
|
+
* const user = await db.users.upsert({
|
|
286
|
+
* email: userInfo.email,
|
|
287
|
+
* name: userInfo.name
|
|
288
|
+
* });
|
|
289
|
+
*
|
|
290
|
+
* return {
|
|
291
|
+
* token: generateSessionId(),
|
|
292
|
+
* raw: { userId: user.id, provider: providerMetadata.name, ...tokenData }
|
|
293
|
+
* };
|
|
294
|
+
* }
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
createSession(tokenData: OAuthTokenResponse, providerMetadata: ProviderMetadata): Promise<Session>;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Default session strategy that works with any OAuth provider.
|
|
301
|
+
* Extracts common token information and creates a standardized session.
|
|
302
|
+
*
|
|
303
|
+
* @public
|
|
304
|
+
*/
|
|
305
|
+
export declare class DefaultSessionStrategy implements SessionStrategy {
|
|
306
|
+
/**
|
|
307
|
+
* Creates a session from OAuth token data.
|
|
308
|
+
* Handles common OAuth token formats and extracts the access token.
|
|
309
|
+
*
|
|
310
|
+
* @param tokenData - The token data received from the OAuth provider
|
|
311
|
+
* @param providerMetadata - Provider metadata (not used in default implementation)
|
|
312
|
+
* @returns A Promise that resolves to a Session object
|
|
313
|
+
*/
|
|
314
|
+
createSession(tokenData: OAuthTokenResponse, providerMetadata: ProviderMetadata): Promise<Session>;
|
|
315
|
+
}
|
|
316
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/models/session.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,18 +1,141 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Interface for OAuth provider implementations.
|
|
2
|
+
* Interface for OAuth 2.0 and OpenID Connect provider implementations.
|
|
3
3
|
*
|
|
4
4
|
* @remarks
|
|
5
5
|
* Implement this interface to add support for custom OAuth providers.
|
|
6
|
+
* Each provider defines the three core endpoints required for the OAuth 2.0
|
|
7
|
+
* authorization code flow with PKCE.
|
|
8
|
+
*
|
|
9
|
+
* Built-in providers (Google, GitHub) are available in the \@vunexa/lixa-providers package.
|
|
10
|
+
*
|
|
11
|
+
* All implementations must comply with:
|
|
12
|
+
* - RFC 6749 (OAuth 2.0)
|
|
13
|
+
* - RFC 7636 (PKCE)
|
|
14
|
+
* - OpenID Connect Core 1.0 (for OIDC providers)
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* Custom provider implementation:
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { IProvider } from '@vunexa/lixa';
|
|
20
|
+
*
|
|
21
|
+
* class CustomProvider implements IProvider {
|
|
22
|
+
* authorizationEndpoint = 'https://auth.example.com/oauth/authorize';
|
|
23
|
+
* tokenEndpoint = 'https://auth.example.com/oauth/token';
|
|
24
|
+
* userInfoEndpoint = 'https://api.example.com/user';
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* // Use in configuration
|
|
28
|
+
* const lixa = new Lixa({
|
|
29
|
+
* providers: {
|
|
30
|
+
* custom: {
|
|
31
|
+
* provider: new CustomProvider(),
|
|
32
|
+
* clientId: 'your-client-id',
|
|
33
|
+
* clientSecret: 'your-client-secret',
|
|
34
|
+
* redirectUri: 'https://app.com/callback',
|
|
35
|
+
* scopes: ['read:user']
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* Object literal provider:
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const customProvider: IProvider = {
|
|
45
|
+
* authorizationEndpoint: 'https://auth.example.com/oauth/authorize',
|
|
46
|
+
* tokenEndpoint: 'https://auth.example.com/oauth/token',
|
|
47
|
+
* userInfoEndpoint: 'https://api.example.com/user'
|
|
48
|
+
* };
|
|
49
|
+
* ```
|
|
6
50
|
*
|
|
7
51
|
* @public
|
|
8
52
|
*/
|
|
9
53
|
interface IProvider {
|
|
10
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* The OAuth 2.0 authorization endpoint URL.
|
|
56
|
+
*
|
|
57
|
+
* @remarks
|
|
58
|
+
* This is the URL where users are redirected to authenticate and authorize your application.
|
|
59
|
+
* The endpoint must support the OAuth 2.0 authorization code flow with PKCE.
|
|
60
|
+
*
|
|
61
|
+
* Standard query parameters sent to this endpoint:
|
|
62
|
+
* - client_id: Your application's client ID
|
|
63
|
+
* - redirect_uri: Where to redirect after authorization
|
|
64
|
+
* - response_type: Always "code" for authorization code flow
|
|
65
|
+
* - scope: Space-separated list of requested scopes
|
|
66
|
+
* - state: Random string for CSRF protection
|
|
67
|
+
* - code_challenge: PKCE code challenge (SHA-256 hash)
|
|
68
|
+
* - code_challenge_method: Always "S256" for SHA-256
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* authorizationEndpoint = 'https://accounts.google.com/o/oauth2/v2/auth'
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
11
75
|
authorizationEndpoint: string;
|
|
12
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* The OAuth 2.0 token endpoint URL.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* This is the URL where authorization codes are exchanged for access tokens.
|
|
81
|
+
* The endpoint must support the OAuth 2.0 token exchange with PKCE.
|
|
82
|
+
*
|
|
83
|
+
* Standard parameters sent to this endpoint (POST request):
|
|
84
|
+
* - grant_type: Always "authorization_code"
|
|
85
|
+
* - code: The authorization code from the callback
|
|
86
|
+
* - redirect_uri: Must match the authorization request
|
|
87
|
+
* - client_id: Your application's client ID
|
|
88
|
+
* - client_secret: Your application's client secret
|
|
89
|
+
* - code_verifier: PKCE code verifier (original random string)
|
|
90
|
+
*
|
|
91
|
+
* Expected response:
|
|
92
|
+
* - access_token: OAuth access token
|
|
93
|
+
* - token_type: Token type (usually "Bearer")
|
|
94
|
+
* - expires_in: Token expiration time in seconds
|
|
95
|
+
* - refresh_token: Refresh token (optional)
|
|
96
|
+
* - id_token: OpenID Connect ID token (for OIDC providers)
|
|
97
|
+
* - scope: Granted scopes
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* tokenEndpoint = 'https://oauth2.googleapis.com/token'
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
13
104
|
tokenEndpoint: string;
|
|
14
|
-
/**
|
|
105
|
+
/**
|
|
106
|
+
* The user information endpoint URL.
|
|
107
|
+
*
|
|
108
|
+
* @remarks
|
|
109
|
+
* This is the URL where user profile information can be retrieved using the access token.
|
|
110
|
+
* For OpenID Connect providers, this is the UserInfo endpoint.
|
|
111
|
+
*
|
|
112
|
+
* The endpoint is called with the access token in the Authorization header:
|
|
113
|
+
* ```
|
|
114
|
+
* Authorization: Bearer <access_token>
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* Common response fields:
|
|
118
|
+
* - sub: Subject identifier (user ID)
|
|
119
|
+
* - email: User's email address
|
|
120
|
+
* - name: User's full name
|
|
121
|
+
* - picture: User's profile picture URL
|
|
122
|
+
* - email_verified: Whether email is verified
|
|
123
|
+
*
|
|
124
|
+
* Note: This endpoint is not called automatically by Lixa. Your SessionStrategy
|
|
125
|
+
* can call it if needed to fetch user profile information.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* userInfoEndpoint = 'https://www.googleapis.com/oauth2/v2/userinfo'
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
15
132
|
userInfoEndpoint: string;
|
|
133
|
+
/**
|
|
134
|
+
* Minimal authentication scopes required for identity verification (AuthN).
|
|
135
|
+
*
|
|
136
|
+
* @example ['openid', 'email', 'profile'] or ['read:user', 'user:email']
|
|
137
|
+
*/
|
|
138
|
+
authScopes?: string[];
|
|
16
139
|
}
|
|
17
140
|
export { IProvider };
|
|
18
141
|
//# sourceMappingURL=IProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IProvider.d.ts","sourceRoot":"","sources":["../../src/providers/IProvider.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"IProvider.d.ts","sourceRoot":"","sources":["../../src/providers/IProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,UAAU,SAAS;IACjB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,qBAAqB,EAAE,MAAM,CAAC;IAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
|