binoauth 0.0.11 → 0.0.13

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.
Files changed (111) hide show
  1. package/README.md +359 -165
  2. package/dist/core/src/admin/client.d.ts +203 -0
  3. package/dist/core/src/admin/client.d.ts.map +1 -0
  4. package/dist/core/src/admin/client.js +391 -0
  5. package/dist/core/src/admin/client.js.map +1 -0
  6. package/dist/core/src/admin/index.d.ts +6 -0
  7. package/dist/core/src/admin/index.d.ts.map +1 -0
  8. package/dist/core/src/admin/index.js +5 -0
  9. package/dist/core/src/admin/index.js.map +1 -0
  10. package/dist/core/src/admin/types.d.ts +412 -0
  11. package/dist/core/src/admin/types.d.ts.map +1 -0
  12. package/dist/core/src/admin/types.js +5 -0
  13. package/dist/core/src/admin/types.js.map +1 -0
  14. package/dist/core/src/auth/client.d.ts +330 -0
  15. package/dist/core/src/auth/client.d.ts.map +1 -0
  16. package/dist/core/src/auth/client.js +408 -0
  17. package/dist/core/src/auth/client.js.map +1 -0
  18. package/dist/core/src/auth/error.d.ts +113 -0
  19. package/dist/core/src/auth/error.d.ts.map +1 -0
  20. package/dist/core/src/auth/error.js +257 -0
  21. package/dist/core/src/auth/error.js.map +1 -0
  22. package/dist/core/src/auth/flows/base-flow.d.ts +98 -0
  23. package/dist/core/src/auth/flows/base-flow.d.ts.map +1 -0
  24. package/dist/core/src/auth/flows/base-flow.js +182 -0
  25. package/dist/core/src/auth/flows/base-flow.js.map +1 -0
  26. package/dist/core/src/auth/flows/magic-link.d.ts +175 -0
  27. package/dist/core/src/auth/flows/magic-link.d.ts.map +1 -0
  28. package/dist/core/src/auth/flows/magic-link.js +228 -0
  29. package/dist/core/src/auth/flows/magic-link.js.map +1 -0
  30. package/dist/core/src/auth/flows/mfa.d.ts +81 -0
  31. package/dist/core/src/auth/flows/mfa.d.ts.map +1 -0
  32. package/dist/core/src/auth/flows/mfa.js +103 -0
  33. package/dist/core/src/auth/flows/mfa.js.map +1 -0
  34. package/dist/core/src/auth/flows/otp.d.ts +172 -0
  35. package/dist/core/src/auth/flows/otp.d.ts.map +1 -0
  36. package/dist/core/src/auth/flows/otp.js +222 -0
  37. package/dist/core/src/auth/flows/otp.js.map +1 -0
  38. package/dist/core/src/auth/flows/password.d.ts +242 -0
  39. package/dist/core/src/auth/flows/password.d.ts.map +1 -0
  40. package/dist/core/src/auth/flows/password.js +344 -0
  41. package/dist/core/src/auth/flows/password.js.map +1 -0
  42. package/dist/core/src/auth/flows/social.d.ts +209 -0
  43. package/dist/core/src/auth/flows/social.d.ts.map +1 -0
  44. package/dist/core/src/auth/flows/social.js +284 -0
  45. package/dist/core/src/auth/flows/social.js.map +1 -0
  46. package/dist/core/src/auth/index.d.ts +19 -0
  47. package/dist/core/src/auth/index.d.ts.map +1 -0
  48. package/dist/core/src/auth/index.js +32 -0
  49. package/dist/core/src/auth/index.js.map +1 -0
  50. package/dist/core/src/auth/types.d.ts +151 -0
  51. package/dist/core/src/auth/types.d.ts.map +1 -0
  52. package/dist/core/src/auth/types.js +7 -0
  53. package/dist/core/src/auth/types.js.map +1 -0
  54. package/dist/core/src/index.d.ts +53 -49
  55. package/dist/core/src/index.d.ts.map +1 -1
  56. package/dist/core/src/index.js +61 -343
  57. package/dist/core/src/index.js.map +1 -1
  58. package/dist/core/src/oauth/client.d.ts +322 -0
  59. package/dist/core/src/oauth/client.d.ts.map +1 -0
  60. package/dist/core/src/oauth/client.js +491 -0
  61. package/dist/core/src/oauth/client.js.map +1 -0
  62. package/dist/core/src/oauth/error.d.ts +18 -0
  63. package/dist/core/src/oauth/error.d.ts.map +1 -0
  64. package/dist/core/src/oauth/error.js +24 -0
  65. package/dist/core/src/oauth/error.js.map +1 -0
  66. package/dist/core/src/oauth/flows/authorization-code.d.ts +122 -0
  67. package/dist/core/src/oauth/flows/authorization-code.d.ts.map +1 -0
  68. package/dist/core/src/oauth/flows/authorization-code.js +278 -0
  69. package/dist/core/src/oauth/flows/authorization-code.js.map +1 -0
  70. package/dist/core/src/oauth/flows/base-flow.d.ts +17 -0
  71. package/dist/core/src/oauth/flows/base-flow.d.ts.map +1 -0
  72. package/dist/core/src/oauth/flows/base-flow.js +107 -0
  73. package/dist/core/src/oauth/flows/base-flow.js.map +1 -0
  74. package/dist/core/src/oauth/flows/client-credentials.d.ts +72 -0
  75. package/dist/core/src/oauth/flows/client-credentials.d.ts.map +1 -0
  76. package/dist/core/src/oauth/flows/client-credentials.js +100 -0
  77. package/dist/core/src/oauth/flows/client-credentials.js.map +1 -0
  78. package/dist/core/src/oauth/flows/device-code.d.ts +108 -0
  79. package/dist/core/src/oauth/flows/device-code.d.ts.map +1 -0
  80. package/dist/core/src/oauth/flows/device-code.js +193 -0
  81. package/dist/core/src/oauth/flows/device-code.js.map +1 -0
  82. package/dist/core/src/oauth/flows/refresh-token.d.ts +59 -0
  83. package/dist/core/src/oauth/flows/refresh-token.d.ts.map +1 -0
  84. package/dist/core/src/oauth/flows/refresh-token.js +105 -0
  85. package/dist/core/src/oauth/flows/refresh-token.js.map +1 -0
  86. package/dist/core/src/oauth/index.d.ts +12 -0
  87. package/dist/core/src/oauth/index.d.ts.map +1 -0
  88. package/dist/core/src/oauth/index.js +11 -0
  89. package/dist/core/src/oauth/index.js.map +1 -0
  90. package/dist/core/src/oauth/storage/encryption.d.ts +12 -0
  91. package/dist/core/src/oauth/storage/encryption.d.ts.map +1 -0
  92. package/dist/core/src/oauth/storage/encryption.js +76 -0
  93. package/dist/core/src/oauth/storage/encryption.js.map +1 -0
  94. package/dist/core/src/oauth/storage/index.d.ts +201 -0
  95. package/dist/core/src/oauth/storage/index.d.ts.map +1 -0
  96. package/dist/core/src/oauth/storage/index.js +322 -0
  97. package/dist/core/src/oauth/storage/index.js.map +1 -0
  98. package/dist/core/src/oauth/storage/strategies.d.ts +34 -0
  99. package/dist/core/src/oauth/storage/strategies.d.ts.map +1 -0
  100. package/dist/core/src/oauth/storage/strategies.js +100 -0
  101. package/dist/core/src/oauth/storage/strategies.js.map +1 -0
  102. package/dist/core/src/oauth/types.d.ts +261 -0
  103. package/dist/core/src/oauth/types.d.ts.map +1 -0
  104. package/dist/core/src/oauth/types.js +39 -0
  105. package/dist/core/src/oauth/types.js.map +1 -0
  106. package/dist/core/src/oauth/utils.d.ts +56 -0
  107. package/dist/core/src/oauth/utils.d.ts.map +1 -0
  108. package/dist/core/src/oauth/utils.js +140 -0
  109. package/dist/core/src/oauth/utils.js.map +1 -0
  110. package/dist/tsconfig.tsbuildinfo +1 -1
  111. package/package.json +1 -1
@@ -0,0 +1,344 @@
1
+ /**
2
+ * Password-based authentication flow
3
+ *
4
+ * Handles email/password login, registration using the actual tenant-sdk APIs.
5
+ */
6
+ import { AuthError, AuthErrorCode } from "../error";
7
+ import { BaseAuthFlow } from "./base-flow";
8
+ /**
9
+ * Password authentication flow
10
+ *
11
+ * Provides email/password authentication using the actual tenant-sdk AuthenticationApi.
12
+ * All methods use the real API endpoints available in the tenant-sdk.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const passwordFlow = new PasswordFlow(config);
17
+ *
18
+ * // Login with email and password
19
+ * try {
20
+ * const result = await passwordFlow.login('user@example.com', 'password123');
21
+ * if (result.success) {
22
+ * console.log('Login successful:', result.user);
23
+ * console.log('Access token:', result.accessToken);
24
+ * }
25
+ * } catch (error) {
26
+ * if (error instanceof AuthError) {
27
+ * console.log('Login failed:', error.message);
28
+ * }
29
+ * }
30
+ *
31
+ * // Register new user
32
+ * const userData = {
33
+ * email: 'newuser@example.com',
34
+ * password: 'securepassword',
35
+ * name: 'John Doe',
36
+ * acceptTerms: true
37
+ * };
38
+ *
39
+ * const registerResult = await passwordFlow.register(userData);
40
+ * ```
41
+ */
42
+ export class PasswordFlow extends BaseAuthFlow {
43
+ constructor(config) {
44
+ super(config);
45
+ }
46
+ /**
47
+ * Authenticates a user with email and password using tenant-sdk AuthenticationApi.loginApiV1AuthLoginPost
48
+ *
49
+ * @param email - User's email address
50
+ * @param password - User's password
51
+ * @param rememberMe - Whether to remember the user (longer token expiry)
52
+ * @returns Promise resolving to authentication result
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * try {
57
+ * const result = await passwordFlow.login('user@example.com', 'password123');
58
+ * if (result.success) {
59
+ * localStorage.setItem('accessToken', result.accessToken);
60
+ * console.log('Welcome,', result.user.name);
61
+ * }
62
+ * } catch (error) {
63
+ * if (error.code === AuthErrorCode.INVALID_CREDENTIALS) {
64
+ * console.log('Invalid email or password');
65
+ * } else if (error.code === AuthErrorCode.MFA_REQUIRED) {
66
+ * console.log('MFA required:', error.details);
67
+ * }
68
+ * }
69
+ * ```
70
+ *
71
+ * @throws {AuthError} When credentials are invalid or authentication fails
72
+ */
73
+ async login(email, password, rememberMe = false) {
74
+ // Validate inputs
75
+ this.validateEmail(email);
76
+ if (!password) {
77
+ throw new AuthError(AuthErrorCode.MISSING_REQUIRED_FIELD, 'Password is required');
78
+ }
79
+ return this.safeApiCall(async () => {
80
+ // Use the actual tenant-sdk AuthenticationApi.loginApiV1AuthLoginPost method
81
+ const response = await this.authApi.loginApiV1AuthLoginPost({
82
+ loginRequest: {
83
+ email,
84
+ password,
85
+ rememberMe,
86
+ },
87
+ });
88
+ return this.processAuthResponse(response);
89
+ }, AuthErrorCode.INVALID_CREDENTIALS);
90
+ }
91
+ /**
92
+ * Authenticates a user with credentials object using tenant-sdk LoginRequest
93
+ *
94
+ * @param credentials - Login credentials from tenant-sdk
95
+ * @returns Promise resolving to authentication result
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * const credentials: LoginRequest = {
100
+ * email: 'user@example.com',
101
+ * password: 'password123',
102
+ * rememberMe: true
103
+ * };
104
+ *
105
+ * const result = await passwordFlow.loginWithCredentials(credentials);
106
+ * ```
107
+ */
108
+ async loginWithCredentials(credentials) {
109
+ if (!credentials.email || !credentials.password) {
110
+ throw new AuthError(AuthErrorCode.MISSING_REQUIRED_FIELD, 'Email and password are required');
111
+ }
112
+ return this.login(credentials.email, credentials.password, credentials.rememberMe);
113
+ }
114
+ /**
115
+ * Registers a new user account using tenant-sdk AuthenticationApi.signupApiV1AuthSignupPost
116
+ *
117
+ * @param userData - User registration data using tenant-sdk SignupRequest
118
+ * @returns Promise resolving to authentication result
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * const userData: SignupRequest = {
123
+ * email: 'newuser@example.com',
124
+ * password: 'securepassword123',
125
+ * confirmPassword: 'securepassword123',
126
+ * name: 'John Doe',
127
+ * returnTo: 'https://myapp.com/welcome'
128
+ * };
129
+ *
130
+ * try {
131
+ * const result = await passwordFlow.register(userData);
132
+ * console.log('Registration successful:', result);
133
+ * } catch (error) {
134
+ * if (error.code === AuthErrorCode.EMAIL_ALREADY_EXISTS) {
135
+ * console.log('Account with this email already exists');
136
+ * } else if (error.code === AuthErrorCode.WEAK_PASSWORD) {
137
+ * console.log('Password is too weak');
138
+ * }
139
+ * }
140
+ * ```
141
+ *
142
+ * @throws {AuthError} When registration fails
143
+ */
144
+ async register(userData) {
145
+ // Validate required fields
146
+ this.validateEmail(userData.email);
147
+ this.validatePassword(userData.password);
148
+ if (userData.password !== userData.confirmPassword) {
149
+ throw new AuthError(AuthErrorCode.INVALID_PASSWORD, 'Password and confirm password must match');
150
+ }
151
+ return this.safeApiCall(async () => {
152
+ // Use the actual tenant-sdk AuthenticationApi.signupApiV1AuthSignupPost method
153
+ const response = await this.authApi.signupApiV1AuthSignupPost({
154
+ signupRequest: userData,
155
+ });
156
+ return this.processAuthResponse(response);
157
+ }, AuthErrorCode.EMAIL_ALREADY_EXISTS);
158
+ }
159
+ /**
160
+ * Requests email verification resend using tenant-sdk AuthenticationApi.resendVerificationApiV1AuthResendVerificationPost
161
+ *
162
+ * @param email - User's email address
163
+ * @returns Promise resolving when verification email is sent
164
+ *
165
+ * @example
166
+ * ```typescript
167
+ * await passwordFlow.resendEmailVerification('user@example.com');
168
+ * console.log('Verification email sent');
169
+ * ```
170
+ *
171
+ * @throws {AuthError} When resend request fails
172
+ */
173
+ async resendEmailVerification(email) {
174
+ this.validateEmail(email);
175
+ await this.safeApiCall(async () => {
176
+ // Use the actual tenant-sdk AuthenticationApi.resendVerificationApiV1AuthResendVerificationPost method
177
+ await this.authApi.resendVerificationApiV1AuthResendVerificationPost({
178
+ resendEmailVerificationRequest: {
179
+ email,
180
+ },
181
+ });
182
+ }, AuthErrorCode.ACCOUNT_NOT_FOUND);
183
+ }
184
+ /**
185
+ * Verifies email address using tenant-sdk AuthenticationApi.verifyEmailApiV1AuthVerifyEmailPost
186
+ *
187
+ * @param token - Email verification token
188
+ * @returns Promise resolving to authentication result
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * // Token comes from email link
193
+ * const result = await passwordFlow.verifyEmail(token);
194
+ * if (result.success) {
195
+ * console.log('Email verified successfully');
196
+ * }
197
+ * ```
198
+ *
199
+ * @throws {AuthError} When email verification fails
200
+ */
201
+ async verifyEmail(token) {
202
+ if (!token) {
203
+ throw new AuthError(AuthErrorCode.MISSING_REQUIRED_FIELD, 'Verification token is required');
204
+ }
205
+ return this.safeApiCall(async () => {
206
+ // Use the actual tenant-sdk AuthenticationApi.verifyEmailApiV1AuthVerifyEmailPost method
207
+ const response = await this.authApi.verifyEmailApiV1AuthVerifyEmailPost({
208
+ emailVerificationRequest: {
209
+ token,
210
+ },
211
+ });
212
+ return this.processAuthResponse(response);
213
+ }, AuthErrorCode.INVALID_TOKEN);
214
+ }
215
+ /**
216
+ * Logs out the current user using tenant-sdk AuthenticationApi.logoutApiV1AuthLogoutPost
217
+ *
218
+ * @returns Promise resolving when logout is complete
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * await passwordFlow.logout();
223
+ * console.log('Logged out successfully');
224
+ * ```
225
+ *
226
+ * @throws {AuthError} When logout fails
227
+ */
228
+ async logout() {
229
+ await this.safeApiCall(async () => {
230
+ // Use the actual tenant-sdk AuthenticationApi.logoutApiV1AuthLogoutPost method
231
+ await this.authApi.logoutApiV1AuthLogoutPost();
232
+ }, AuthErrorCode.SERVER_ERROR);
233
+ }
234
+ /**
235
+ * Gets current user information using tenant-sdk UserProfileApi.getCurrentUserApiV1AuthUserinfoGet
236
+ *
237
+ * @returns Promise resolving to user information
238
+ *
239
+ * @example
240
+ * ```typescript
241
+ * const user = await passwordFlow.getCurrentUser();
242
+ * console.log('Current user:', user.name, user.email);
243
+ * ```
244
+ *
245
+ * @throws {AuthError} When user info fetch fails
246
+ */
247
+ async getCurrentUser() {
248
+ return this.safeApiCall(async () => {
249
+ // Use the actual tenant-sdk UserProfileApi.getCurrentUserApiV1AuthUserinfoGet method
250
+ const response = await this.userApi.getCurrentUserApiV1AuthUserinfoGet();
251
+ // Return the response directly as it matches UserInfoResponse (User type)
252
+ return response;
253
+ }, AuthErrorCode.INVALID_TOKEN);
254
+ }
255
+ /**
256
+ * Note: Password reset functionality depends on magic link flow
257
+ * The tenant-sdk doesn't have dedicated password reset endpoints,
258
+ * instead it uses magic links for password reset flows.
259
+ *
260
+ * For password reset, use the MagicLinkFlow class which uses:
261
+ * - AuthenticationApi.requestMagicLinkApiV1AuthMlPost for reset request
262
+ * - AuthenticationApi.verifyMagicLinkApiV1AuthMlVerifyPost for reset verification
263
+ */
264
+ /**
265
+ * Initiates password reset process using magic link
266
+ *
267
+ * @param request - Password reset request
268
+ * @returns Promise resolving when reset email is sent
269
+ *
270
+ * @example
271
+ * ```typescript
272
+ * await passwordFlow.requestPasswordReset({
273
+ * email: 'user@example.com',
274
+ * returnTo: 'https://myapp.com/reset-complete'
275
+ * });
276
+ *
277
+ * console.log('Password reset email sent');
278
+ * ```
279
+ *
280
+ * @throws {AuthError} When reset request fails
281
+ */
282
+ async requestPasswordReset(request) {
283
+ this.validateEmail(request.email);
284
+ await this.safeApiCall(async () => {
285
+ // Use magic link API for password reset
286
+ await this.authApi.requestMagicLinkApiV1AuthMlPost({
287
+ magicLinkRequest: {
288
+ email: request.email,
289
+ returnTo: request.returnTo || 'https://example.com/reset-complete',
290
+ },
291
+ });
292
+ }, AuthErrorCode.ACCOUNT_NOT_FOUND);
293
+ }
294
+ /**
295
+ * Completes password reset with magic link token
296
+ *
297
+ * @param resetData - Password reset completion data
298
+ * @returns Promise resolving to authentication result
299
+ *
300
+ * @example
301
+ * ```typescript
302
+ * // Token comes from magic link
303
+ * const resetData = {
304
+ * token: 'magic_link_token_from_email',
305
+ * newPassword: 'newsecurepassword123',
306
+ * confirmPassword: 'newsecurepassword123'
307
+ * };
308
+ *
309
+ * try {
310
+ * const result = await passwordFlow.resetPassword(resetData);
311
+ * if (result.success) {
312
+ * console.log('Password reset successful');
313
+ * // User is automatically logged in after password reset
314
+ * }
315
+ * } catch (error) {
316
+ * if (error.code === AuthErrorCode.INVALID_TOKEN) {
317
+ * console.log('Reset token is invalid or expired');
318
+ * }
319
+ * }
320
+ * ```
321
+ *
322
+ * @throws {AuthError} When password reset fails
323
+ */
324
+ async resetPassword(resetData) {
325
+ // Validate inputs
326
+ if (!resetData.token) {
327
+ throw new AuthError(AuthErrorCode.MISSING_REQUIRED_FIELD, 'Reset token is required');
328
+ }
329
+ this.validatePassword(resetData.newPassword);
330
+ if (resetData.newPassword !== resetData.confirmPassword) {
331
+ throw new AuthError(AuthErrorCode.INVALID_PASSWORD, 'Passwords do not match');
332
+ }
333
+ return this.safeApiCall(async () => {
334
+ // Use magic link verification for password reset
335
+ const response = await this.authApi.verifyMagicLinkApiV1AuthMlVerifyPost({
336
+ verifyMagicLinkTokenRequest: {
337
+ token: resetData.token,
338
+ },
339
+ });
340
+ return this.processAuthResponse(response);
341
+ }, AuthErrorCode.INVALID_TOKEN);
342
+ }
343
+ }
344
+ //# sourceMappingURL=password.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password.js","sourceRoot":"","sources":["../../../../../src/auth/flows/password.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;OA6BG;IACH,KAAK,CAAC,aAAa,CAAC,SAA4B;QAC9C,kBAAkB;QAClB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;YACrB,MAAM,IAAI,SAAS,CACjB,aAAa,CAAC,sBAAsB,EACpC,yBAAyB,CAC1B,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAE7C,IAAI,SAAS,CAAC,WAAW,KAAK,SAAS,CAAC,eAAe,EAAE,CAAC;YACxD,MAAM,IAAI,SAAS,CACjB,aAAa,CAAC,gBAAgB,EAC9B,wBAAwB,CACzB,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,IAAI,EAAE;YACjC,iDAAiD;YACjD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,oCAAoC,CAAC;gBACvE,2BAA2B,EAAE;oBAC3B,KAAK,EAAE,SAAS,CAAC,KAAK;iBACvB;aACF,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;QAC5C,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;IAClC,CAAC;CACF"}
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Social authentication flow
3
+ *
4
+ * Handles OAuth authentication with social providers using actual tenant-sdk ExternalAuthApi.
5
+ */
6
+ import type { SocialProvider, ProviderResponse, AuthResult, BinoAuthConfig } from "../types";
7
+ import { BaseAuthFlow } from "./base-flow";
8
+ /**
9
+ * Social authentication flow
10
+ *
11
+ * Provides OAuth authentication with social providers using actual tenant-sdk APIs.
12
+ * Uses ExternalAuthApi.getActiveProvidersApiV1AuthExternalActiveProvidersGet and
13
+ * ExternalAuthApi.socialCallbackApiV1AuthExternalCallbackProviderGet.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const socialFlow = new SocialFlow(config);
18
+ *
19
+ * // Get available providers and their auth URLs
20
+ * const providers = await socialFlow.getActiveProviders('https://myapp.com/dashboard');
21
+ * const googleProvider = providers.find(p => p.provider === 'google');
22
+ *
23
+ * // Redirect user to Google
24
+ * if (googleProvider) {
25
+ * window.location.href = googleProvider.authUrl;
26
+ * }
27
+ *
28
+ * // Handle callback after user returns from Google
29
+ * const urlParams = new URLSearchParams(window.location.search);
30
+ * const code = urlParams.get('code');
31
+ * const state = urlParams.get('state');
32
+ *
33
+ * if (code && state) {
34
+ * const result = await socialFlow.handleCallback('google', code, state);
35
+ * if (result.success) {
36
+ * console.log('Social login successful:', result.user);
37
+ * }
38
+ * }
39
+ * ```
40
+ */
41
+ export declare class SocialFlow extends BaseAuthFlow {
42
+ constructor(config: BinoAuthConfig);
43
+ /**
44
+ * Gets active social providers and their authorization URLs using tenant-sdk ExternalAuthApi.getActiveProvidersApiV1AuthExternalActiveProvidersGet
45
+ *
46
+ * @param returnTo - Final destination URL after successful authentication
47
+ * @param redirectUri - Optional redirect path (relative to tenant domain)
48
+ * @returns Promise resolving to array of active providers with auth URLs
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * // Get all active providers with auth URLs
53
+ * const providers = await socialFlow.getActiveProviders('https://myapp.com/dashboard');
54
+ *
55
+ * providers.forEach(provider => {
56
+ * console.log(`${provider.name}: ${provider.authUrl}`);
57
+ * // Create login button that redirects to provider.authUrl
58
+ * });
59
+ *
60
+ * // Find specific provider
61
+ * const googleProvider = providers.find(p => p.provider === 'google');
62
+ * if (googleProvider) {
63
+ * window.location.href = googleProvider.authUrl;
64
+ * }
65
+ * ```
66
+ *
67
+ * @throws {AuthError} When fetching active providers fails
68
+ */
69
+ getActiveProviders(returnTo: string, redirectUri?: string): Promise<ProviderResponse[]>;
70
+ /**
71
+ * Gets authorization URL for a specific provider
72
+ *
73
+ * @param provider - Social provider name
74
+ * @param returnTo - Final destination URL after successful authentication
75
+ * @param redirectUri - Optional redirect path
76
+ * @returns Promise resolving to authorization URL
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const googleUrl = await socialFlow.getAuthUrl('google', 'https://myapp.com/dashboard');
81
+ * window.location.href = googleUrl;
82
+ * ```
83
+ */
84
+ getAuthUrl(provider: SocialProvider, returnTo: string, redirectUri?: string): Promise<string>;
85
+ /**
86
+ * Handles the OAuth callback from a social provider using tenant-sdk ExternalAuthApi.socialCallbackApiV1AuthExternalCallbackProviderGet
87
+ *
88
+ * @param provider - Social provider that initiated the callback
89
+ * @param code - Authorization code from provider
90
+ * @param state - State parameter for CSRF protection
91
+ * @param link - Optional flag to link account instead of login
92
+ * @returns Promise resolving to authentication result
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * // Extract parameters from callback URL
97
+ * const urlParams = new URLSearchParams(window.location.search);
98
+ * const code = urlParams.get('code');
99
+ * const state = urlParams.get('state');
100
+ *
101
+ * if (code && state) {
102
+ * try {
103
+ * const result = await socialFlow.handleCallback('google', code, state);
104
+ * if (result.success) {
105
+ * console.log('Welcome,', result.user.name);
106
+ * localStorage.setItem('accessToken', result.accessToken);
107
+ *
108
+ * // Redirect to dashboard
109
+ * window.location.href = '/dashboard';
110
+ * }
111
+ * } catch (error) {
112
+ * if (error.code === AuthErrorCode.INVALID_GRANT) {
113
+ * console.log('Social login was cancelled or failed');
114
+ * }
115
+ * }
116
+ * }
117
+ * ```
118
+ *
119
+ * @throws {AuthError} When callback handling fails
120
+ */
121
+ handleCallback(provider: SocialProvider, code: string, state: string, link?: boolean): Promise<AuthResult>;
122
+ /**
123
+ * Gets URL for linking a social account to an existing user account
124
+ *
125
+ * This uses the same flow as regular authentication but with the link flag set to true in the callback.
126
+ * The user must be authenticated (provide access token via Authorization header) to link accounts.
127
+ *
128
+ * @param provider - Social provider to link
129
+ * @param returnTo - Return URL after linking is complete
130
+ * @param redirectUri - Optional redirect path
131
+ * @returns Promise resolving to link URL
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * // Get URL to link Google account (user must be authenticated)
136
+ * const linkUrl = await socialFlow.getLinkUrl('google', 'https://myapp.com/settings');
137
+ *
138
+ * // Redirect user to complete linking
139
+ * window.location.href = linkUrl;
140
+ *
141
+ * // Handle callback with link=true flag
142
+ * const result = await socialFlow.handleCallback('google', code, state, true);
143
+ * ```
144
+ *
145
+ * @throws {AuthError} When getting link URL fails
146
+ */
147
+ getLinkUrl(provider: SocialProvider, returnTo: string, redirectUri?: string): Promise<string>;
148
+ /**
149
+ * Note: Account unlinking and linked account retrieval functionality is not available
150
+ * in the current tenant-sdk. The ExternalAuthApi only provides authentication and
151
+ * account linking capabilities.
152
+ *
153
+ * These features must be handled through other means (admin SDK or backend API).
154
+ */
155
+ /**
156
+ * Gets all supported social providers using tenant-sdk ExternalAuthApi.getProvidersApiV1AuthExternalProvidersGet
157
+ *
158
+ * This returns all supported providers regardless of whether they are configured for the current tenant.
159
+ * Use getActiveProviders() to get only the providers that are actually configured and enabled.
160
+ *
161
+ * @returns Promise resolving to array of all supported providers
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * const allProviders = await socialFlow.getAllProviders();
166
+ * console.log('All supported providers:', allProviders);
167
+ *
168
+ * // Get only active/configured providers
169
+ * const activeProviders = await socialFlow.getActiveProviders('https://myapp.com/dashboard');
170
+ * console.log('Active providers:', activeProviders.map(p => p.provider));
171
+ * ```
172
+ */
173
+ getAllProviders(): Promise<any>;
174
+ /**
175
+ * Checks if a social provider is supported based on tenant-sdk ProviderType
176
+ *
177
+ * @param provider - Provider to check
178
+ * @returns True if provider is supported, false otherwise
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * if (socialFlow.isSupportedProvider('google')) {
183
+ * // Show Google login button
184
+ * }
185
+ * ```
186
+ */
187
+ isSupportedProvider(provider: string): provider is SocialProvider;
188
+ /**
189
+ * Gets provider-specific information (display name, icon, etc.)
190
+ *
191
+ * Based on the actual tenant-sdk supported providers: google, github, microsoft, facebook, apple
192
+ *
193
+ * @param provider - Social provider
194
+ * @returns Provider information
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * const info = socialFlow.getProviderInfo('google');
199
+ * console.log(info.displayName); // "Google"
200
+ * console.log(info.primaryColor); // "#4285f4"
201
+ * ```
202
+ */
203
+ getProviderInfo(provider: SocialProvider): {
204
+ displayName: string;
205
+ iconUrl?: string;
206
+ primaryColor?: string;
207
+ };
208
+ }
209
+ //# sourceMappingURL=social.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"social.d.ts","sourceRoot":"","sources":["../../../../../src/auth/flows/social.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE7F,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAAa,UAAW,SAAQ,YAAY;gBAE9B,MAAM,EAAE,cAAc;IAIlC;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACG,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAmB7F;;;;;;;;;;;;;OAaG;IACG,UAAU,CAAC,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAcnG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACG,cAAc,CAClB,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,OAAO,GACb,OAAO,CAAC,UAAU,CAAC;IAmCtB;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,UAAU,CACd,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,MAAM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