binoauth 0.0.11 → 0.0.12
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 +359 -165
- package/dist/core/src/admin/client.d.ts +203 -0
- package/dist/core/src/admin/client.d.ts.map +1 -0
- package/dist/core/src/admin/client.js +391 -0
- package/dist/core/src/admin/client.js.map +1 -0
- package/dist/core/src/admin/index.d.ts +6 -0
- package/dist/core/src/admin/index.d.ts.map +1 -0
- package/dist/core/src/admin/index.js +5 -0
- package/dist/core/src/admin/index.js.map +1 -0
- package/dist/core/src/admin/types.d.ts +412 -0
- package/dist/core/src/admin/types.d.ts.map +1 -0
- package/dist/core/src/admin/types.js +5 -0
- package/dist/core/src/admin/types.js.map +1 -0
- package/dist/core/src/auth/client.d.ts +330 -0
- package/dist/core/src/auth/client.d.ts.map +1 -0
- package/dist/core/src/auth/client.js +408 -0
- package/dist/core/src/auth/client.js.map +1 -0
- package/dist/core/src/auth/error.d.ts +113 -0
- package/dist/core/src/auth/error.d.ts.map +1 -0
- package/dist/core/src/auth/error.js +257 -0
- package/dist/core/src/auth/error.js.map +1 -0
- package/dist/core/src/auth/flows/base-flow.d.ts +98 -0
- package/dist/core/src/auth/flows/base-flow.d.ts.map +1 -0
- package/dist/core/src/auth/flows/base-flow.js +182 -0
- package/dist/core/src/auth/flows/base-flow.js.map +1 -0
- package/dist/core/src/auth/flows/magic-link.d.ts +175 -0
- package/dist/core/src/auth/flows/magic-link.d.ts.map +1 -0
- package/dist/core/src/auth/flows/magic-link.js +228 -0
- package/dist/core/src/auth/flows/magic-link.js.map +1 -0
- package/dist/core/src/auth/flows/mfa.d.ts +81 -0
- package/dist/core/src/auth/flows/mfa.d.ts.map +1 -0
- package/dist/core/src/auth/flows/mfa.js +103 -0
- package/dist/core/src/auth/flows/mfa.js.map +1 -0
- package/dist/core/src/auth/flows/otp.d.ts +172 -0
- package/dist/core/src/auth/flows/otp.d.ts.map +1 -0
- package/dist/core/src/auth/flows/otp.js +222 -0
- package/dist/core/src/auth/flows/otp.js.map +1 -0
- package/dist/core/src/auth/flows/password.d.ts +242 -0
- package/dist/core/src/auth/flows/password.d.ts.map +1 -0
- package/dist/core/src/auth/flows/password.js +344 -0
- package/dist/core/src/auth/flows/password.js.map +1 -0
- package/dist/core/src/auth/flows/social.d.ts +209 -0
- package/dist/core/src/auth/flows/social.d.ts.map +1 -0
- package/dist/core/src/auth/flows/social.js +284 -0
- package/dist/core/src/auth/flows/social.js.map +1 -0
- package/dist/core/src/auth/index.d.ts +19 -0
- package/dist/core/src/auth/index.d.ts.map +1 -0
- package/dist/core/src/auth/index.js +32 -0
- package/dist/core/src/auth/index.js.map +1 -0
- package/dist/core/src/auth/types.d.ts +151 -0
- package/dist/core/src/auth/types.d.ts.map +1 -0
- package/dist/core/src/auth/types.js +7 -0
- package/dist/core/src/auth/types.js.map +1 -0
- package/dist/core/src/index.d.ts +53 -49
- package/dist/core/src/index.d.ts.map +1 -1
- package/dist/core/src/index.js +61 -343
- package/dist/core/src/index.js.map +1 -1
- package/dist/core/src/oauth/client.d.ts +322 -0
- package/dist/core/src/oauth/client.d.ts.map +1 -0
- package/dist/core/src/oauth/client.js +491 -0
- package/dist/core/src/oauth/client.js.map +1 -0
- package/dist/core/src/oauth/error.d.ts +18 -0
- package/dist/core/src/oauth/error.d.ts.map +1 -0
- package/dist/core/src/oauth/error.js +24 -0
- package/dist/core/src/oauth/error.js.map +1 -0
- package/dist/core/src/oauth/flows/authorization-code.d.ts +122 -0
- package/dist/core/src/oauth/flows/authorization-code.d.ts.map +1 -0
- package/dist/core/src/oauth/flows/authorization-code.js +278 -0
- package/dist/core/src/oauth/flows/authorization-code.js.map +1 -0
- package/dist/core/src/oauth/flows/base-flow.d.ts +17 -0
- package/dist/core/src/oauth/flows/base-flow.d.ts.map +1 -0
- package/dist/core/src/oauth/flows/base-flow.js +107 -0
- package/dist/core/src/oauth/flows/base-flow.js.map +1 -0
- package/dist/core/src/oauth/flows/client-credentials.d.ts +72 -0
- package/dist/core/src/oauth/flows/client-credentials.d.ts.map +1 -0
- package/dist/core/src/oauth/flows/client-credentials.js +100 -0
- package/dist/core/src/oauth/flows/client-credentials.js.map +1 -0
- package/dist/core/src/oauth/flows/device-code.d.ts +108 -0
- package/dist/core/src/oauth/flows/device-code.d.ts.map +1 -0
- package/dist/core/src/oauth/flows/device-code.js +193 -0
- package/dist/core/src/oauth/flows/device-code.js.map +1 -0
- package/dist/core/src/oauth/flows/refresh-token.d.ts +59 -0
- package/dist/core/src/oauth/flows/refresh-token.d.ts.map +1 -0
- package/dist/core/src/oauth/flows/refresh-token.js +105 -0
- package/dist/core/src/oauth/flows/refresh-token.js.map +1 -0
- package/dist/core/src/oauth/index.d.ts +12 -0
- package/dist/core/src/oauth/index.d.ts.map +1 -0
- package/dist/core/src/oauth/index.js +11 -0
- package/dist/core/src/oauth/index.js.map +1 -0
- package/dist/core/src/oauth/storage/encryption.d.ts +12 -0
- package/dist/core/src/oauth/storage/encryption.d.ts.map +1 -0
- package/dist/core/src/oauth/storage/encryption.js +76 -0
- package/dist/core/src/oauth/storage/encryption.js.map +1 -0
- package/dist/core/src/oauth/storage/index.d.ts +201 -0
- package/dist/core/src/oauth/storage/index.d.ts.map +1 -0
- package/dist/core/src/oauth/storage/index.js +322 -0
- package/dist/core/src/oauth/storage/index.js.map +1 -0
- package/dist/core/src/oauth/storage/strategies.d.ts +34 -0
- package/dist/core/src/oauth/storage/strategies.d.ts.map +1 -0
- package/dist/core/src/oauth/storage/strategies.js +100 -0
- package/dist/core/src/oauth/storage/strategies.js.map +1 -0
- package/dist/core/src/oauth/types.d.ts +261 -0
- package/dist/core/src/oauth/types.d.ts.map +1 -0
- package/dist/core/src/oauth/types.js +39 -0
- package/dist/core/src/oauth/types.js.map +1 -0
- package/dist/core/src/oauth/utils.d.ts +56 -0
- package/dist/core/src/oauth/utils.d.ts.map +1 -0
- package/dist/core/src/oauth/utils.js +140 -0
- package/dist/core/src/oauth/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
@@ -0,0 +1,257 @@
|
|
1
|
+
/**
|
2
|
+
* Authentication error codes and error handling
|
3
|
+
*/
|
4
|
+
/**
|
5
|
+
* Authentication error codes
|
6
|
+
*
|
7
|
+
* Standardized error codes for different authentication scenarios.
|
8
|
+
*/
|
9
|
+
export var AuthErrorCode;
|
10
|
+
(function (AuthErrorCode) {
|
11
|
+
// Credential errors
|
12
|
+
AuthErrorCode["INVALID_CREDENTIALS"] = "INVALID_CREDENTIALS";
|
13
|
+
AuthErrorCode["INVALID_EMAIL"] = "INVALID_EMAIL";
|
14
|
+
AuthErrorCode["INVALID_PASSWORD"] = "INVALID_PASSWORD";
|
15
|
+
AuthErrorCode["INVALID_OTP"] = "INVALID_OTP";
|
16
|
+
AuthErrorCode["EXPIRED_OTP"] = "EXPIRED_OTP";
|
17
|
+
AuthErrorCode["INVALID_TOKEN"] = "INVALID_TOKEN";
|
18
|
+
AuthErrorCode["EXPIRED_TOKEN"] = "EXPIRED_TOKEN";
|
19
|
+
// Account state errors
|
20
|
+
AuthErrorCode["ACCOUNT_NOT_FOUND"] = "ACCOUNT_NOT_FOUND";
|
21
|
+
AuthErrorCode["ACCOUNT_LOCKED"] = "ACCOUNT_LOCKED";
|
22
|
+
AuthErrorCode["ACCOUNT_DISABLED"] = "ACCOUNT_DISABLED";
|
23
|
+
AuthErrorCode["EMAIL_NOT_VERIFIED"] = "EMAIL_NOT_VERIFIED";
|
24
|
+
AuthErrorCode["PHONE_NOT_VERIFIED"] = "PHONE_NOT_VERIFIED";
|
25
|
+
// MFA errors
|
26
|
+
AuthErrorCode["MFA_REQUIRED"] = "MFA_REQUIRED";
|
27
|
+
AuthErrorCode["MFA_INVALID_METHOD"] = "MFA_INVALID_METHOD";
|
28
|
+
AuthErrorCode["MFA_CHALLENGE_EXPIRED"] = "MFA_CHALLENGE_EXPIRED";
|
29
|
+
// Rate limiting
|
30
|
+
AuthErrorCode["TOO_MANY_ATTEMPTS"] = "TOO_MANY_ATTEMPTS";
|
31
|
+
AuthErrorCode["RATE_LIMITED"] = "RATE_LIMITED";
|
32
|
+
// Registration errors
|
33
|
+
AuthErrorCode["EMAIL_ALREADY_EXISTS"] = "EMAIL_ALREADY_EXISTS";
|
34
|
+
AuthErrorCode["PHONE_ALREADY_EXISTS"] = "PHONE_ALREADY_EXISTS";
|
35
|
+
AuthErrorCode["WEAK_PASSWORD"] = "WEAK_PASSWORD";
|
36
|
+
AuthErrorCode["TERMS_NOT_ACCEPTED"] = "TERMS_NOT_ACCEPTED";
|
37
|
+
// System errors
|
38
|
+
AuthErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
|
39
|
+
AuthErrorCode["SERVER_ERROR"] = "SERVER_ERROR";
|
40
|
+
AuthErrorCode["INVALID_CONFIG"] = "INVALID_CONFIG";
|
41
|
+
AuthErrorCode["MISSING_REQUIRED_FIELD"] = "MISSING_REQUIRED_FIELD";
|
42
|
+
// OAuth specific
|
43
|
+
AuthErrorCode["OAUTH_ERROR"] = "OAUTH_ERROR";
|
44
|
+
AuthErrorCode["INVALID_GRANT"] = "INVALID_GRANT";
|
45
|
+
AuthErrorCode["INVALID_CLIENT"] = "INVALID_CLIENT";
|
46
|
+
AuthErrorCode["INVALID_SCOPE"] = "INVALID_SCOPE";
|
47
|
+
// Unknown
|
48
|
+
AuthErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
49
|
+
})(AuthErrorCode || (AuthErrorCode = {}));
|
50
|
+
/**
|
51
|
+
* Authentication error class
|
52
|
+
*
|
53
|
+
* Provides structured error information for authentication failures.
|
54
|
+
*
|
55
|
+
* @example
|
56
|
+
* ```typescript
|
57
|
+
* try {
|
58
|
+
* await authClient.login(email, password);
|
59
|
+
* } catch (error) {
|
60
|
+
* if (error instanceof AuthError) {
|
61
|
+
* switch (error.code) {
|
62
|
+
* case AuthErrorCode.INVALID_CREDENTIALS:
|
63
|
+
* console.log('Invalid email or password');
|
64
|
+
* break;
|
65
|
+
* case AuthErrorCode.MFA_REQUIRED:
|
66
|
+
* console.log('MFA required:', error.details);
|
67
|
+
* break;
|
68
|
+
* default:
|
69
|
+
* console.log('Auth error:', error.message);
|
70
|
+
* }
|
71
|
+
* }
|
72
|
+
* }
|
73
|
+
* ```
|
74
|
+
*/
|
75
|
+
export class AuthError extends Error {
|
76
|
+
code;
|
77
|
+
details;
|
78
|
+
originalError;
|
79
|
+
/**
|
80
|
+
* Creates a new authentication error
|
81
|
+
*
|
82
|
+
* @param code - Standardized error code
|
83
|
+
* @param message - Human-readable error message
|
84
|
+
* @param details - Additional error details
|
85
|
+
* @param originalError - Original error that caused this error
|
86
|
+
*/
|
87
|
+
constructor(code, message, details, originalError) {
|
88
|
+
super(message);
|
89
|
+
this.code = code;
|
90
|
+
this.details = details;
|
91
|
+
this.originalError = originalError;
|
92
|
+
this.name = 'AuthError';
|
93
|
+
// Maintain proper stack trace
|
94
|
+
if (Error.captureStackTrace) {
|
95
|
+
Error.captureStackTrace(this, AuthError);
|
96
|
+
}
|
97
|
+
}
|
98
|
+
/**
|
99
|
+
* Creates an AuthError from an unknown error
|
100
|
+
*
|
101
|
+
* @param error - Unknown error object
|
102
|
+
* @param defaultCode - Default error code if none can be determined
|
103
|
+
* @returns AuthError instance
|
104
|
+
*/
|
105
|
+
static fromError(error, defaultCode = AuthErrorCode.UNKNOWN_ERROR) {
|
106
|
+
if (error instanceof AuthError) {
|
107
|
+
return error;
|
108
|
+
}
|
109
|
+
// Extract error information
|
110
|
+
const message = error?.message || error?.error || 'An unknown error occurred';
|
111
|
+
const details = error?.response?.data || error?.details || error;
|
112
|
+
// Try to map common error patterns to codes
|
113
|
+
const code = mapErrorToCode(error, defaultCode);
|
114
|
+
return new AuthError(code, message, details, error);
|
115
|
+
}
|
116
|
+
/**
|
117
|
+
* Converts the error to a JSON-serializable object
|
118
|
+
*
|
119
|
+
* @returns Plain object representation of the error
|
120
|
+
*/
|
121
|
+
toJSON() {
|
122
|
+
return {
|
123
|
+
name: this.name,
|
124
|
+
code: this.code,
|
125
|
+
message: this.message,
|
126
|
+
details: this.details,
|
127
|
+
stack: this.stack
|
128
|
+
};
|
129
|
+
}
|
130
|
+
}
|
131
|
+
/**
|
132
|
+
* Maps common error patterns to standardized error codes
|
133
|
+
*
|
134
|
+
* @param error - Error object to analyze
|
135
|
+
* @param defaultCode - Default code if no mapping found
|
136
|
+
* @returns Mapped error code
|
137
|
+
*/
|
138
|
+
function mapErrorToCode(error, defaultCode) {
|
139
|
+
const message = (error?.message || error?.error || '').toLowerCase();
|
140
|
+
const statusCode = error?.response?.status || error?.status;
|
141
|
+
// HTTP status code mappings
|
142
|
+
switch (statusCode) {
|
143
|
+
case 401:
|
144
|
+
return AuthErrorCode.INVALID_CREDENTIALS;
|
145
|
+
case 403:
|
146
|
+
return AuthErrorCode.ACCOUNT_DISABLED;
|
147
|
+
case 404:
|
148
|
+
return AuthErrorCode.ACCOUNT_NOT_FOUND;
|
149
|
+
case 429:
|
150
|
+
return AuthErrorCode.RATE_LIMITED;
|
151
|
+
case 500:
|
152
|
+
case 502:
|
153
|
+
case 503:
|
154
|
+
case 504:
|
155
|
+
return AuthErrorCode.SERVER_ERROR;
|
156
|
+
}
|
157
|
+
// Message pattern mappings
|
158
|
+
if (message.includes('invalid credentials') || message.includes('unauthorized')) {
|
159
|
+
return AuthErrorCode.INVALID_CREDENTIALS;
|
160
|
+
}
|
161
|
+
if (message.includes('invalid email') || message.includes('email')) {
|
162
|
+
return AuthErrorCode.INVALID_EMAIL;
|
163
|
+
}
|
164
|
+
if (message.includes('invalid password') || message.includes('password')) {
|
165
|
+
return AuthErrorCode.INVALID_PASSWORD;
|
166
|
+
}
|
167
|
+
if (message.includes('invalid otp') || message.includes('invalid code')) {
|
168
|
+
return AuthErrorCode.INVALID_OTP;
|
169
|
+
}
|
170
|
+
if (message.includes('expired otp') || message.includes('expired code')) {
|
171
|
+
return AuthErrorCode.EXPIRED_OTP;
|
172
|
+
}
|
173
|
+
if (message.includes('mfa required') || message.includes('two-factor')) {
|
174
|
+
return AuthErrorCode.MFA_REQUIRED;
|
175
|
+
}
|
176
|
+
if (message.includes('account locked') || message.includes('locked')) {
|
177
|
+
return AuthErrorCode.ACCOUNT_LOCKED;
|
178
|
+
}
|
179
|
+
if (message.includes('account not found') || message.includes('user not found')) {
|
180
|
+
return AuthErrorCode.ACCOUNT_NOT_FOUND;
|
181
|
+
}
|
182
|
+
if (message.includes('email already exists') || message.includes('email taken')) {
|
183
|
+
return AuthErrorCode.EMAIL_ALREADY_EXISTS;
|
184
|
+
}
|
185
|
+
if (message.includes('too many attempts') || message.includes('rate limit')) {
|
186
|
+
return AuthErrorCode.TOO_MANY_ATTEMPTS;
|
187
|
+
}
|
188
|
+
if (message.includes('network') || message.includes('connection')) {
|
189
|
+
return AuthErrorCode.NETWORK_ERROR;
|
190
|
+
}
|
191
|
+
return defaultCode;
|
192
|
+
}
|
193
|
+
/**
|
194
|
+
* Creates user-friendly error messages for error codes
|
195
|
+
*
|
196
|
+
* @param code - Error code
|
197
|
+
* @returns User-friendly error message
|
198
|
+
*
|
199
|
+
* @example
|
200
|
+
* ```typescript
|
201
|
+
* const message = getErrorMessage(AuthErrorCode.INVALID_CREDENTIALS);
|
202
|
+
* console.log(message); // "Invalid email or password"
|
203
|
+
* ```
|
204
|
+
*/
|
205
|
+
export function getErrorMessage(code) {
|
206
|
+
switch (code) {
|
207
|
+
case AuthErrorCode.INVALID_CREDENTIALS:
|
208
|
+
return 'Invalid email or password';
|
209
|
+
case AuthErrorCode.INVALID_EMAIL:
|
210
|
+
return 'Please enter a valid email address';
|
211
|
+
case AuthErrorCode.INVALID_PASSWORD:
|
212
|
+
return 'Password is invalid';
|
213
|
+
case AuthErrorCode.INVALID_OTP:
|
214
|
+
return 'Invalid verification code';
|
215
|
+
case AuthErrorCode.EXPIRED_OTP:
|
216
|
+
return 'Verification code has expired';
|
217
|
+
case AuthErrorCode.INVALID_TOKEN:
|
218
|
+
return 'Invalid or expired token';
|
219
|
+
case AuthErrorCode.EXPIRED_TOKEN:
|
220
|
+
return 'Token has expired';
|
221
|
+
case AuthErrorCode.ACCOUNT_NOT_FOUND:
|
222
|
+
return 'Account not found';
|
223
|
+
case AuthErrorCode.ACCOUNT_LOCKED:
|
224
|
+
return 'Account is temporarily locked';
|
225
|
+
case AuthErrorCode.ACCOUNT_DISABLED:
|
226
|
+
return 'Account has been disabled';
|
227
|
+
case AuthErrorCode.EMAIL_NOT_VERIFIED:
|
228
|
+
return 'Please verify your email address';
|
229
|
+
case AuthErrorCode.PHONE_NOT_VERIFIED:
|
230
|
+
return 'Please verify your phone number';
|
231
|
+
case AuthErrorCode.MFA_REQUIRED:
|
232
|
+
return 'Multi-factor authentication required';
|
233
|
+
case AuthErrorCode.TOO_MANY_ATTEMPTS:
|
234
|
+
return 'Too many failed attempts. Please try again later';
|
235
|
+
case AuthErrorCode.RATE_LIMITED:
|
236
|
+
return 'Too many requests. Please try again later';
|
237
|
+
case AuthErrorCode.EMAIL_ALREADY_EXISTS:
|
238
|
+
return 'An account with this email already exists';
|
239
|
+
case AuthErrorCode.PHONE_ALREADY_EXISTS:
|
240
|
+
return 'An account with this phone number already exists';
|
241
|
+
case AuthErrorCode.WEAK_PASSWORD:
|
242
|
+
return 'Password is too weak';
|
243
|
+
case AuthErrorCode.TERMS_NOT_ACCEPTED:
|
244
|
+
return 'Please accept the terms and conditions';
|
245
|
+
case AuthErrorCode.NETWORK_ERROR:
|
246
|
+
return 'Network connection error';
|
247
|
+
case AuthErrorCode.SERVER_ERROR:
|
248
|
+
return 'Server error. Please try again later';
|
249
|
+
case AuthErrorCode.INVALID_CONFIG:
|
250
|
+
return 'Invalid configuration';
|
251
|
+
case AuthErrorCode.MISSING_REQUIRED_FIELD:
|
252
|
+
return 'Required field is missing';
|
253
|
+
default:
|
254
|
+
return 'An unexpected error occurred';
|
255
|
+
}
|
256
|
+
}
|
257
|
+
//# sourceMappingURL=error.js.map
|
@@ -0,0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
|
1
|
+
/**
|
2
|
+
* Base authentication flow class
|
3
|
+
*
|
4
|
+
* Provides common functionality for all authentication flows including
|
5
|
+
* API client setup, error handling, and response processing.
|
6
|
+
*/
|
7
|
+
import type { AuthenticationApi, OAuth2Api, UserProfileApi, ExternalAuthApi, Configuration as TenantConfiguration } from "@binoauth/tenant-sdk";
|
8
|
+
import type { BinoAuthConfig, AuthResult, User } from "../types";
|
9
|
+
import { AuthError, AuthErrorCode } from "../error";
|
10
|
+
/**
|
11
|
+
* Base class for all authentication flows
|
12
|
+
*
|
13
|
+
* Provides common functionality including API client management,
|
14
|
+
* error handling, and response processing using the actual tenant-sdk APIs.
|
15
|
+
*/
|
16
|
+
export declare abstract class BaseAuthFlow {
|
17
|
+
protected config: BinoAuthConfig;
|
18
|
+
protected tenantConfig: TenantConfiguration;
|
19
|
+
protected authApi: AuthenticationApi;
|
20
|
+
protected oauthApi: OAuth2Api;
|
21
|
+
protected userApi: UserProfileApi;
|
22
|
+
protected externalAuthApi: ExternalAuthApi;
|
23
|
+
/**
|
24
|
+
* Creates a new base authentication flow
|
25
|
+
*
|
26
|
+
* @param config - BinoAuth configuration
|
27
|
+
*/
|
28
|
+
constructor(config: BinoAuthConfig);
|
29
|
+
/**
|
30
|
+
* Validates the configuration
|
31
|
+
*
|
32
|
+
* @throws {AuthError} When required configuration is missing
|
33
|
+
*/
|
34
|
+
protected validateConfig(): void;
|
35
|
+
/**
|
36
|
+
* Initializes the API clients using the actual tenant-sdk
|
37
|
+
*/
|
38
|
+
protected initializeAPIs(): void;
|
39
|
+
/**
|
40
|
+
* Processes an API response into a standardized AuthResult
|
41
|
+
*
|
42
|
+
* @param response - Raw API response from tenant-sdk
|
43
|
+
* @param includeUserInfo - Whether to fetch user information
|
44
|
+
* @returns Processed auth result
|
45
|
+
*/
|
46
|
+
protected processAuthResponse(response: any, includeUserInfo?: boolean): Promise<AuthResult>;
|
47
|
+
/**
|
48
|
+
* Fetches user information using an access token with the actual UserProfileApi
|
49
|
+
*
|
50
|
+
* @param accessToken - Access token
|
51
|
+
* @returns User information
|
52
|
+
*/
|
53
|
+
protected fetchUserInfo(accessToken: string): Promise<User>;
|
54
|
+
/**
|
55
|
+
* Handles API errors and converts them to AuthErrors
|
56
|
+
*
|
57
|
+
* @param error - Raw error from tenant-sdk API
|
58
|
+
* @param defaultCode - Default error code if mapping fails
|
59
|
+
* @returns AuthError instance
|
60
|
+
*/
|
61
|
+
protected handleError(error: any, defaultCode?: AuthErrorCode): AuthError;
|
62
|
+
/**
|
63
|
+
* Makes a safe API call with error handling
|
64
|
+
*
|
65
|
+
* @param apiCall - Function that makes the tenant-sdk API call
|
66
|
+
* @param errorCode - Default error code for failures
|
67
|
+
* @returns Promise with the API response
|
68
|
+
*/
|
69
|
+
protected safeApiCall<T>(apiCall: () => Promise<T>, errorCode?: AuthErrorCode): Promise<T>;
|
70
|
+
/**
|
71
|
+
* Validates email format
|
72
|
+
*
|
73
|
+
* @param email - Email to validate
|
74
|
+
* @throws {AuthError} When email is invalid
|
75
|
+
*/
|
76
|
+
protected validateEmail(email: string): void;
|
77
|
+
/**
|
78
|
+
* Validates phone number format
|
79
|
+
*
|
80
|
+
* @param phone - Phone number to validate
|
81
|
+
* @throws {AuthError} When phone number is invalid
|
82
|
+
*/
|
83
|
+
protected validatePhone(phone: string): void;
|
84
|
+
/**
|
85
|
+
* Validates password strength
|
86
|
+
*
|
87
|
+
* @param password - Password to validate
|
88
|
+
* @throws {AuthError} When password is too weak
|
89
|
+
*/
|
90
|
+
protected validatePassword(password: string): void;
|
91
|
+
/**
|
92
|
+
* Gets the tenant identifier from config
|
93
|
+
*
|
94
|
+
* @returns Tenant identifier
|
95
|
+
*/
|
96
|
+
protected getTenant(): string;
|
97
|
+
}
|
98
|
+
//# sourceMappingURL=base-flow.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"base-flow.d.ts","sourceRoot":"","sources":["../../../../../src/auth/flows/base-flow.ts"],"names":[],"mappings":"AAA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;IAU5C;;;;;OAKG;IACH,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAW5C;;;;;OAKG;IACH,SAAS,CAAC,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IASlD;;;;OAIG;IACH,SAAS,CAAC,SAAS,IAAI,MAAM;CAG9B"}
|
@@ -0,0 +1,182 @@
|
|
1
|
+
/**
|
2
|
+
* Base authentication flow class
|
3
|
+
*
|
4
|
+
* Provides common functionality for all authentication flows including
|
5
|
+
* API client setup, error handling, and response processing.
|
6
|
+
*/
|
7
|
+
import { AuthError, AuthErrorCode } from "../error";
|
8
|
+
/**
|
9
|
+
* Base class for all authentication flows
|
10
|
+
*
|
11
|
+
* Provides common functionality including API client management,
|
12
|
+
* error handling, and response processing using the actual tenant-sdk APIs.
|
13
|
+
*/
|
14
|
+
export class BaseAuthFlow {
|
15
|
+
config;
|
16
|
+
tenantConfig;
|
17
|
+
authApi;
|
18
|
+
oauthApi;
|
19
|
+
userApi;
|
20
|
+
externalAuthApi;
|
21
|
+
/**
|
22
|
+
* Creates a new base authentication flow
|
23
|
+
*
|
24
|
+
* @param config - BinoAuth configuration
|
25
|
+
*/
|
26
|
+
constructor(config) {
|
27
|
+
this.config = config;
|
28
|
+
this.validateConfig();
|
29
|
+
this.initializeAPIs();
|
30
|
+
}
|
31
|
+
/**
|
32
|
+
* Validates the configuration
|
33
|
+
*
|
34
|
+
* @throws {AuthError} When required configuration is missing
|
35
|
+
*/
|
36
|
+
validateConfig() {
|
37
|
+
if (!this.config.issuer && !this.config.baseUrl) {
|
38
|
+
throw new AuthError(AuthErrorCode.INVALID_CONFIG, 'Either issuer or baseUrl must be provided');
|
39
|
+
}
|
40
|
+
if (!this.config.clientId) {
|
41
|
+
throw new AuthError(AuthErrorCode.INVALID_CONFIG, 'clientId is required');
|
42
|
+
}
|
43
|
+
}
|
44
|
+
/**
|
45
|
+
* Initializes the API clients using the actual tenant-sdk
|
46
|
+
*/
|
47
|
+
initializeAPIs() {
|
48
|
+
const baseUrl = this.config.baseUrl || this.config.issuer;
|
49
|
+
// Configure tenant SDK
|
50
|
+
this.tenantConfig = new (require("@binoauth/tenant-sdk").Configuration)({
|
51
|
+
basePath: baseUrl,
|
52
|
+
headers: this.config.apiKey ? {
|
53
|
+
"X-API-Key": this.config.apiKey,
|
54
|
+
} : undefined,
|
55
|
+
});
|
56
|
+
// Initialize all available APIs from tenant-sdk
|
57
|
+
const { AuthenticationApi, OAuth2Api, UserProfileApi, ExternalAuthApi } = require("@binoauth/tenant-sdk");
|
58
|
+
this.authApi = new AuthenticationApi(this.tenantConfig);
|
59
|
+
this.oauthApi = new OAuth2Api(this.tenantConfig);
|
60
|
+
this.userApi = new UserProfileApi(this.tenantConfig);
|
61
|
+
this.externalAuthApi = new ExternalAuthApi(this.tenantConfig);
|
62
|
+
}
|
63
|
+
/**
|
64
|
+
* Processes an API response into a standardized AuthResult
|
65
|
+
*
|
66
|
+
* @param response - Raw API response from tenant-sdk
|
67
|
+
* @param includeUserInfo - Whether to fetch user information
|
68
|
+
* @returns Processed auth result
|
69
|
+
*/
|
70
|
+
async processAuthResponse(response, includeUserInfo = true) {
|
71
|
+
try {
|
72
|
+
// Handle different response formats from tenant-sdk
|
73
|
+
const result = {
|
74
|
+
accessToken: response.accessToken || response.access_token,
|
75
|
+
refreshToken: response.refreshToken || response.refresh_token,
|
76
|
+
tokenType: response.tokenType || 'Bearer',
|
77
|
+
accessTokenExpires: response.accessTokenExpires || response.expiresIn || response.expires_in,
|
78
|
+
refreshTokenExpires: response.refreshTokenExpires,
|
79
|
+
requiresMfa: response.requiresMfa,
|
80
|
+
};
|
81
|
+
// Note: User info is typically included in the response or fetched separately
|
82
|
+
// The LoginResponse type doesn't include a user field by default
|
83
|
+
return result;
|
84
|
+
}
|
85
|
+
catch (error) {
|
86
|
+
throw AuthError.fromError(error, AuthErrorCode.SERVER_ERROR);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
/**
|
90
|
+
* Fetches user information using an access token with the actual UserProfileApi
|
91
|
+
*
|
92
|
+
* @param accessToken - Access token
|
93
|
+
* @returns User information
|
94
|
+
*/
|
95
|
+
async fetchUserInfo(accessToken) {
|
96
|
+
try {
|
97
|
+
// Create a temporary config with the access token
|
98
|
+
const authConfig = new (require("@binoauth/tenant-sdk").Configuration)({
|
99
|
+
basePath: this.config.baseUrl || this.config.issuer,
|
100
|
+
accessToken: accessToken,
|
101
|
+
});
|
102
|
+
const userApi = new (require("@binoauth/tenant-sdk").UserProfileApi)(authConfig);
|
103
|
+
const response = await userApi.getCurrentUserApiV1AuthUserinfoGet();
|
104
|
+
// Return the response directly as it matches UserInfoResponse (User type)
|
105
|
+
return response;
|
106
|
+
}
|
107
|
+
catch (error) {
|
108
|
+
throw AuthError.fromError(error, AuthErrorCode.SERVER_ERROR);
|
109
|
+
}
|
110
|
+
}
|
111
|
+
/**
|
112
|
+
* Handles API errors and converts them to AuthErrors
|
113
|
+
*
|
114
|
+
* @param error - Raw error from tenant-sdk API
|
115
|
+
* @param defaultCode - Default error code if mapping fails
|
116
|
+
* @returns AuthError instance
|
117
|
+
*/
|
118
|
+
handleError(error, defaultCode = AuthErrorCode.SERVER_ERROR) {
|
119
|
+
return AuthError.fromError(error, defaultCode);
|
120
|
+
}
|
121
|
+
/**
|
122
|
+
* Makes a safe API call with error handling
|
123
|
+
*
|
124
|
+
* @param apiCall - Function that makes the tenant-sdk API call
|
125
|
+
* @param errorCode - Default error code for failures
|
126
|
+
* @returns Promise with the API response
|
127
|
+
*/
|
128
|
+
async safeApiCall(apiCall, errorCode = AuthErrorCode.SERVER_ERROR) {
|
129
|
+
try {
|
130
|
+
return await apiCall();
|
131
|
+
}
|
132
|
+
catch (error) {
|
133
|
+
throw this.handleError(error, errorCode);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
/**
|
137
|
+
* Validates email format
|
138
|
+
*
|
139
|
+
* @param email - Email to validate
|
140
|
+
* @throws {AuthError} When email is invalid
|
141
|
+
*/
|
142
|
+
validateEmail(email) {
|
143
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
144
|
+
if (!emailRegex.test(email)) {
|
145
|
+
throw new AuthError(AuthErrorCode.INVALID_EMAIL, 'Invalid email format');
|
146
|
+
}
|
147
|
+
}
|
148
|
+
/**
|
149
|
+
* Validates phone number format
|
150
|
+
*
|
151
|
+
* @param phone - Phone number to validate
|
152
|
+
* @throws {AuthError} When phone number is invalid
|
153
|
+
*/
|
154
|
+
validatePhone(phone) {
|
155
|
+
// Basic phone validation - can be enhanced based on requirements
|
156
|
+
const phoneRegex = /^\+?[\d\s\-\(\)]{10,}$/;
|
157
|
+
if (!phoneRegex.test(phone)) {
|
158
|
+
throw new AuthError(AuthErrorCode.INVALID_EMAIL, // Reusing email error for now
|
159
|
+
'Invalid phone number format');
|
160
|
+
}
|
161
|
+
}
|
162
|
+
/**
|
163
|
+
* Validates password strength
|
164
|
+
*
|
165
|
+
* @param password - Password to validate
|
166
|
+
* @throws {AuthError} When password is too weak
|
167
|
+
*/
|
168
|
+
validatePassword(password) {
|
169
|
+
if (password.length < 8) {
|
170
|
+
throw new AuthError(AuthErrorCode.WEAK_PASSWORD, 'Password must be at least 8 characters long');
|
171
|
+
}
|
172
|
+
}
|
173
|
+
/**
|
174
|
+
* Gets the tenant identifier from config
|
175
|
+
*
|
176
|
+
* @returns Tenant identifier
|
177
|
+
*/
|
178
|
+
getTenant() {
|
179
|
+
return this.config.tenant || 'default';
|
180
|
+
}
|
181
|
+
}
|
182
|
+
//# sourceMappingURL=base-flow.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"base-flow.js","sourceRoot":"","sources":["../../../../../src/auth/flows/base-flow.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,OAAgB,YAAY;IAYV;IAXZ,YAAY,CAA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