@leancodepl/login-manager 8.5.0 → 8.5.1

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/index.esm.js ADDED
@@ -0,0 +1,545 @@
1
+ import { Buffer } from 'buffer';
2
+
3
+ function _extends() {
4
+ _extends = Object.assign || function assign(target) {
5
+ for(var i = 1; i < arguments.length; i++){
6
+ var source = arguments[i];
7
+ for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
8
+ }
9
+ return target;
10
+ };
11
+ return _extends.apply(this, arguments);
12
+ }
13
+
14
+ class BaseLoginManager {
15
+ trySignIn(username, password) {
16
+ return this.acquireToken(this.buildSignInRequest(username, password));
17
+ }
18
+ trySignInWithFacebook(accessToken) {
19
+ return this.acquireToken(this.buildSignInWithFacebookRequest(accessToken));
20
+ }
21
+ trySignInWithOneTimeToken(token) {
22
+ return this.acquireToken(this.buildSignInWithOneTimeTokenRequest(token));
23
+ }
24
+ trySignInWithGoogle(accessToken) {
25
+ return this.acquireToken(this.buildSignInWithGoogleRequest(accessToken));
26
+ }
27
+ trySignInWithLinkedIn(accessToken) {
28
+ return this.acquireToken(this.buildSignInWithLinkedInRequest(accessToken));
29
+ }
30
+ async tryRefreshToken() {
31
+ const token = await this.storage.getToken();
32
+ if (token !== null) {
33
+ return await this.tryRefreshTokenInternal(token);
34
+ } else {
35
+ return null;
36
+ }
37
+ }
38
+ tryRefreshTokenInternal(token) {
39
+ if (!this.isRefreshingToken) {
40
+ this.isRefreshingToken = true;
41
+ this.acquireToken(this.buildRefreshRequest(token)).then((result)=>{
42
+ this.isRefreshingToken = false;
43
+ this.refreshTokenCallbacks.forEach((c)=>c(result.type === "success"));
44
+ this.refreshTokenCallbacks = [];
45
+ });
46
+ }
47
+ return new Promise((resolve)=>{
48
+ this.refreshTokenCallbacks.push(resolve);
49
+ });
50
+ }
51
+ onChange(callback) {
52
+ this.callbacks.push(callback);
53
+ }
54
+ removeOnChange(callback) {
55
+ const idx = this.callbacks.indexOf(callback);
56
+ if (idx !== -1) {
57
+ this.callbacks.splice(idx, 1);
58
+ }
59
+ }
60
+ async acquireToken(init) {
61
+ try {
62
+ const result = await fetch(this.endpoint + "/connect/token", init);
63
+ if (!result.ok) {
64
+ if (result.status === 400) {
65
+ await this.signOut();
66
+ }
67
+ return {
68
+ type: "failure"
69
+ };
70
+ }
71
+ const tokenResult = await result.json();
72
+ const expDate = new Date();
73
+ expDate.setSeconds(new Date().getSeconds() + tokenResult.expires_in);
74
+ await this.storage.storeToken({
75
+ token: tokenResult.access_token,
76
+ refreshToken: tokenResult.refresh_token,
77
+ expirationDate: expDate
78
+ });
79
+ this.notify(true);
80
+ return {
81
+ type: "success"
82
+ };
83
+ } catch (e) {
84
+ console.warn("Cannot call Auth server, error: ", e);
85
+ return {
86
+ type: "networkError"
87
+ };
88
+ }
89
+ }
90
+ buildSignInRequest(username, password) {
91
+ const data = _extends({
92
+ grant_type: "password",
93
+ scope: this.scopes,
94
+ username: username,
95
+ password: password
96
+ }, this.additionalParams);
97
+ return {
98
+ method: "POST",
99
+ headers: this.prepareHeaders(),
100
+ body: new URLSearchParams(data)
101
+ };
102
+ }
103
+ buildSignInWithFacebookRequest(accessToken) {
104
+ const data = _extends({
105
+ grant_type: "facebook",
106
+ scope: this.scopes,
107
+ assertion: accessToken
108
+ }, this.additionalParams);
109
+ return {
110
+ method: "POST",
111
+ headers: this.prepareHeaders(),
112
+ body: new URLSearchParams(data)
113
+ };
114
+ }
115
+ buildSignInWithOneTimeTokenRequest(token) {
116
+ const data = _extends({
117
+ grant_type: "onetime",
118
+ scope: this.scopes,
119
+ token
120
+ }, this.additionalParams);
121
+ return {
122
+ method: "POST",
123
+ headers: this.prepareHeaders(),
124
+ body: new URLSearchParams(data)
125
+ };
126
+ }
127
+ buildSignInWithGoogleRequest(accessToken) {
128
+ const data = _extends({
129
+ grant_type: "google",
130
+ scope: this.scopes,
131
+ assertion: accessToken
132
+ }, this.additionalParams);
133
+ return {
134
+ method: "POST",
135
+ headers: this.prepareHeaders(),
136
+ body: new URLSearchParams(data)
137
+ };
138
+ }
139
+ buildSignInWithLinkedInRequest(accessToken) {
140
+ const data = _extends({
141
+ grant_type: "linkedin",
142
+ scope: this.scopes,
143
+ assertion: accessToken
144
+ }, this.additionalParams);
145
+ return {
146
+ method: "POST",
147
+ headers: this.prepareHeaders(),
148
+ body: new URLSearchParams(data)
149
+ };
150
+ }
151
+ buildRefreshRequest(token) {
152
+ const data = _extends({
153
+ grant_type: "refresh_token",
154
+ scope: this.scopes,
155
+ refresh_token: token.refreshToken || ""
156
+ }, this.additionalParams);
157
+ return {
158
+ method: "POST",
159
+ headers: this.prepareHeaders(),
160
+ body: new URLSearchParams(data)
161
+ };
162
+ }
163
+ prepareHeaders() {
164
+ const headers = new Headers();
165
+ if (this.clientSecret) {
166
+ const sec = Buffer.from(`${this.clientId}:${this.clientSecret}`, "binary").toString("base64");
167
+ headers.append("Authorization", "Basic " + sec);
168
+ }
169
+ headers.append("Content-Type", "application/x-www-form-urlencoded");
170
+ return headers;
171
+ }
172
+ notify(isSignedIn) {
173
+ for (const c of this.callbacks){
174
+ c(isSignedIn);
175
+ }
176
+ }
177
+ /* eslint-disable-next-line max-params */ constructor(storage, endpoint, clientSecret, clientId, scopes, additionalParams){
178
+ this.storage = storage;
179
+ this.endpoint = endpoint;
180
+ this.clientSecret = clientSecret;
181
+ this.clientId = clientId;
182
+ this.scopes = scopes;
183
+ this.additionalParams = additionalParams;
184
+ this.callbacks = [];
185
+ this.refreshTokenCallbacks = [];
186
+ this.isRefreshingToken = false;
187
+ if (!clientSecret) {
188
+ this.additionalParams = _extends({}, additionalParams, {
189
+ client_id: clientId
190
+ });
191
+ }
192
+ }
193
+ }
194
+
195
+ /**
196
+ * Error thrown when token refresh fails.
197
+ *
198
+ * Indicates that the refresh token is invalid or expired, requiring user to sign in again.
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * try {
203
+ * const token = await loginManager.getToken();
204
+ * } catch (error) {
205
+ * if (error instanceof CannotRefreshToken) {
206
+ * console.log('User needs to sign in again');
207
+ * }
208
+ * }
209
+ * ```
210
+ */ class CannotRefreshToken extends Error {
211
+ constructor(m){
212
+ super(m);
213
+ Object.setPrototypeOf(this, CannotRefreshToken.prototype);
214
+ }
215
+ }
216
+
217
+ /**
218
+ * Manages OAuth2 authentication with asynchronous token storage.
219
+ *
220
+ * Extends BaseLoginManager to work with async storage implementations like IndexedDB or remote storage.
221
+ * Handles token refresh, expiration, and authentication state management.
222
+ *
223
+ * @param storage - Token storage implementation
224
+ * @param endpoint - OAuth2 server endpoint
225
+ * @param clientSecret - Client secret for authentication
226
+ * @param clientId - OAuth2 client identifier
227
+ * @param scopes - Space-separated OAuth2 scopes
228
+ * @param additionalParams - Additional OAuth2 parameters
229
+ * @example
230
+ * ```typescript
231
+ * const tokenStorage = new CustomAsyncStorage();
232
+ * const loginManager = new AsyncLoginManager(
233
+ * tokenStorage,
234
+ * 'https://api.example.com',
235
+ * 'client_secret',
236
+ * 'client_id',
237
+ * 'openid profile'
238
+ * );
239
+ * ```
240
+ */ class AsyncLoginManager extends BaseLoginManager {
241
+ async signOut() {
242
+ await this.storage.resetToken();
243
+ this.notify(false);
244
+ }
245
+ async isSigned() {
246
+ return await this.storage.getToken() !== null;
247
+ }
248
+ async getToken() {
249
+ const token = await this.storage.getToken();
250
+ if (token === null) {
251
+ return null;
252
+ } else if (token.expirationDate < new Date()) {
253
+ if (await this.tryRefreshTokenInternal(token)) {
254
+ var _this;
255
+ var _token;
256
+ return (_token = (_this = await this.storage.getToken()) == null ? void 0 : _this.token) != null ? _token : null;
257
+ } else {
258
+ throw new CannotRefreshToken("Cannot refresh access token after it has expired");
259
+ }
260
+ } else {
261
+ return token.token;
262
+ }
263
+ }
264
+ async load() {
265
+ const isSignedIn = await this.isSigned();
266
+ this.notify(isSignedIn);
267
+ }
268
+ }
269
+
270
+ /// <reference types="facebook-js-sdk" />
271
+ /**
272
+ * Integrates Facebook Login SDK for web applications.
273
+ *
274
+ * Handles Facebook authentication flow and provides access tokens for OAuth2 sign-in.
275
+ * Automatically loads Facebook SDK and manages login state.
276
+ *
277
+ * @param facebookAppId - Facebook App ID
278
+ * @param facebookPermissions - Comma-separated Facebook permissions
279
+ * @example
280
+ * ```typescript
281
+ * const facebookClient = new FacebookClient('your-app-id', 'email,public_profile');
282
+ * facebookClient.setup();
283
+ * facebookClient.login((accessToken) => {
284
+ * return loginManager.trySignInWithFacebook(accessToken);
285
+ * });
286
+ * ```
287
+ */ class FacebookClient {
288
+ get accessToken() {
289
+ return this.token;
290
+ }
291
+ setup(loginCallback) {
292
+ const ref = document.getElementsByTagName("script")[0];
293
+ const id = "facebook-jssdk";
294
+ if (document.getElementById(id)) {
295
+ this.initializeSDK();
296
+ this.getLoginStatus(loginCallback);
297
+ return;
298
+ }
299
+ const js = document.createElement("script");
300
+ js.id = id;
301
+ js.async = true;
302
+ js.src = "//connect.facebook.net/pl_PL/sdk.js";
303
+ if (ref.parentNode != null) {
304
+ ref.parentNode.insertBefore(js, ref);
305
+ }
306
+ js.onload = ()=>{
307
+ this.initializeSDK();
308
+ this.getLoginStatus(loginCallback);
309
+ };
310
+ }
311
+ login(callback) {
312
+ FB.login((response)=>{
313
+ if (response.status === "connected") {
314
+ this.isSignedIn = true;
315
+ this.token = response.authResponse.accessToken;
316
+ if (callback) {
317
+ callback(response.authResponse.accessToken);
318
+ }
319
+ } else {
320
+ this.isSignedIn = false;
321
+ }
322
+ }, {
323
+ scope: this.facebookPermissions
324
+ });
325
+ }
326
+ getLoginStatus(callback) {
327
+ FB.getLoginStatus((response)=>{
328
+ if (response.status === "connected") {
329
+ this.isSignedIn = true;
330
+ this.token = response.authResponse.accessToken;
331
+ if (callback) {
332
+ callback(response.authResponse.accessToken);
333
+ }
334
+ } else {
335
+ this.isSignedIn = false;
336
+ }
337
+ });
338
+ }
339
+ initializeSDK() {
340
+ FB.init({
341
+ appId: this.facebookAppId,
342
+ xfbml: true,
343
+ version: "v2.9"
344
+ });
345
+ }
346
+ constructor(facebookAppId, facebookPermissions){
347
+ this.facebookAppId = facebookAppId;
348
+ this.facebookPermissions = facebookPermissions;
349
+ this.isSignedIn = undefined;
350
+ this.token = "";
351
+ }
352
+ }
353
+
354
+ /**
355
+ * Stores OAuth2 tokens in browser localStorage.
356
+ *
357
+ * Provides persistent token storage that survives browser sessions.
358
+ * Implements SyncTokenStorage interface for synchronous operations.
359
+ *
360
+ * @param tokenKey - localStorage key for access token (default: "token")
361
+ * @param refreshKey - localStorage key for refresh token (default: "refresh_token")
362
+ * @param expiryKey - localStorage key for expiry date (default: "expiration_date")
363
+ * @example
364
+ * ```typescript
365
+ * const storage = new LocalTokenStorage();
366
+ * const loginManager = new SyncLoginManager(storage, endpoint, secret, clientId, scopes);
367
+ * ```
368
+ */ class LocalTokenStorage {
369
+ getToken() {
370
+ if (this.hasValue(this.tokenKey)) {
371
+ return {
372
+ token: this.getValue(this.tokenKey),
373
+ refreshToken: this.getValue(this.refreshKey),
374
+ expirationDate: new Date(Number(this.getValue(this.expiryKey)))
375
+ };
376
+ } else {
377
+ return null;
378
+ }
379
+ }
380
+ storeToken(token) {
381
+ this.setValue(this.tokenKey, token.token);
382
+ this.setValue(this.refreshKey, token.refreshToken);
383
+ this.setValue(this.expiryKey, token.expirationDate.getTime().toString());
384
+ }
385
+ resetToken() {
386
+ this.remove(this.tokenKey);
387
+ this.remove(this.refreshKey);
388
+ this.remove(this.expiryKey);
389
+ }
390
+ hasValue(key) {
391
+ return localStorage.getItem(key) !== null;
392
+ }
393
+ getValue(key) {
394
+ return localStorage.getItem(key);
395
+ }
396
+ setValue(key, val) {
397
+ localStorage.setItem(key, val);
398
+ }
399
+ remove(key) {
400
+ localStorage.removeItem(key);
401
+ }
402
+ constructor(tokenKey = "token", refreshKey = "refresh_token", expiryKey = "expiration_date"){
403
+ this.tokenKey = tokenKey;
404
+ this.refreshKey = refreshKey;
405
+ this.expiryKey = expiryKey;
406
+ }
407
+ }
408
+
409
+ /**
410
+ * Stores OAuth2 tokens in memory.
411
+ *
412
+ * Provides temporary token storage that clears when the page is refreshed.
413
+ * Implements SyncTokenStorage interface for synchronous operations.
414
+ *
415
+ * @example
416
+ * ```typescript
417
+ * const storage = new MemoryTokenStorage();
418
+ * const loginManager = new SyncLoginManager(storage, endpoint, secret, clientId, scopes);
419
+ * ```
420
+ */ class MemoryTokenStorage {
421
+ getToken() {
422
+ return this.token;
423
+ }
424
+ storeToken(token) {
425
+ this.token = {
426
+ token: token.token,
427
+ refreshToken: token.refreshToken,
428
+ expirationDate: token.expirationDate
429
+ };
430
+ return Promise.resolve();
431
+ }
432
+ resetToken() {
433
+ this.token = null;
434
+ return Promise.resolve();
435
+ }
436
+ constructor(){
437
+ this.token = null;
438
+ }
439
+ }
440
+
441
+ /**
442
+ * Stores OAuth2 tokens in browser sessionStorage.
443
+ *
444
+ * Provides session-based token storage that clears when the browser tab is closed.
445
+ * Implements SyncTokenStorage interface for synchronous operations.
446
+ *
447
+ * @param tokenKey - sessionStorage key for access token (default: "token")
448
+ * @param refreshKey - sessionStorage key for refresh token (default: "refresh_token")
449
+ * @param expiryKey - sessionStorage key for expiry date (default: "expiration_date")
450
+ * @example
451
+ * ```typescript
452
+ * const storage = new SessionTokenStorage();
453
+ * const loginManager = new SyncLoginManager(storage, endpoint, secret, clientId, scopes);
454
+ * ```
455
+ */ class SessionTokenStorage {
456
+ getToken() {
457
+ if (this.hasValue(this.tokenKey)) {
458
+ return {
459
+ token: this.getValue(this.tokenKey),
460
+ refreshToken: this.getValue(this.refreshKey),
461
+ expirationDate: new Date(Number(this.getValue(this.expiryKey)))
462
+ };
463
+ } else {
464
+ return null;
465
+ }
466
+ }
467
+ storeToken(token) {
468
+ this.setValue(this.tokenKey, token.token);
469
+ this.setValue(this.refreshKey, token.refreshToken);
470
+ this.setValue(this.expiryKey, token.expirationDate.getTime().toString());
471
+ }
472
+ resetToken() {
473
+ this.remove(this.tokenKey);
474
+ this.remove(this.refreshKey);
475
+ this.remove(this.expiryKey);
476
+ }
477
+ hasValue(key) {
478
+ return sessionStorage.getItem(key) !== null;
479
+ }
480
+ getValue(key) {
481
+ return sessionStorage.getItem(key);
482
+ }
483
+ setValue(key, val) {
484
+ sessionStorage.setItem(key, val);
485
+ }
486
+ remove(key) {
487
+ sessionStorage.removeItem(key);
488
+ }
489
+ constructor(tokenKey = "token", refreshKey = "refresh_token", expiryKey = "expiration_date"){
490
+ this.tokenKey = tokenKey;
491
+ this.refreshKey = refreshKey;
492
+ this.expiryKey = expiryKey;
493
+ }
494
+ }
495
+
496
+ /**
497
+ * Manages OAuth2 authentication with synchronous token storage.
498
+ *
499
+ * Extends BaseLoginManager to work with sync storage implementations like localStorage or sessionStorage.
500
+ * Handles token refresh, expiration, and authentication state management.
501
+ *
502
+ * @param storage - Token storage implementation
503
+ * @param endpoint - OAuth2 server endpoint
504
+ * @param clientSecret - Client secret for authentication
505
+ * @param clientId - OAuth2 client identifier
506
+ * @param scopes - Space-separated OAuth2 scopes
507
+ * @param additionalParams - Additional OAuth2 parameters
508
+ * @example
509
+ * ```typescript
510
+ * const tokenStorage = new LocalTokenStorage();
511
+ * const loginManager = new SyncLoginManager(
512
+ * tokenStorage,
513
+ * 'https://api.example.com',
514
+ * 'client_secret',
515
+ * 'client_id',
516
+ * 'openid profile'
517
+ * );
518
+ * ```
519
+ */ class SyncLoginManager extends BaseLoginManager {
520
+ signOut() {
521
+ this.storage.resetToken();
522
+ this.notify(false);
523
+ }
524
+ isSigned() {
525
+ return this.storage.getToken() !== null;
526
+ }
527
+ async getToken() {
528
+ const token = this.storage.getToken();
529
+ if (token === null) {
530
+ return null;
531
+ } else if (token.expirationDate < new Date()) {
532
+ if (await this.tryRefreshTokenInternal(token)) {
533
+ var _this_storage_getToken;
534
+ var _this_storage_getToken_token;
535
+ return (_this_storage_getToken_token = (_this_storage_getToken = this.storage.getToken()) == null ? void 0 : _this_storage_getToken.token) != null ? _this_storage_getToken_token : null;
536
+ } else {
537
+ throw new CannotRefreshToken("Cannot refresh access token after it has expired");
538
+ }
539
+ } else {
540
+ return token.token;
541
+ }
542
+ }
543
+ }
544
+
545
+ export { AsyncLoginManager, BaseLoginManager, CannotRefreshToken, FacebookClient, LocalTokenStorage, MemoryTokenStorage, SessionTokenStorage, SyncLoginManager };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leancodepl/login-manager",
3
- "version": "8.5.0",
3
+ "version": "8.5.1",
4
4
  "license": "Apache-2.0",
5
5
  "dependencies": {
6
6
  "buffer": ">=6.0.0"
@@ -36,11 +36,6 @@
36
36
  "name": "LeanCode",
37
37
  "url": "https://leancode.co"
38
38
  },
39
- "files": [
40
- "dist",
41
- "README.md",
42
- "CHANGELOG.md"
43
- ],
44
39
  "sideEffects": false,
45
40
  "exports": {
46
41
  "./package.json": "./package.json",
package/src/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export * from "./lib/asyncLoginManager";
2
+ export * from "./lib/baseLoginManager";
3
+ export * from "./lib/cannotRefreshToken";
4
+ export * from "./lib/facebookClient";
5
+ export * from "./lib/localTokenStorage";
6
+ export * from "./lib/memoryTokenStorage";
7
+ export * from "./lib/sessionTokenStorage";
8
+ export * from "./lib/syncLoginManager";
9
+ export * from "./lib/tokenStorage";
@@ -0,0 +1,32 @@
1
+ import { BaseLoginManager, LoginManager } from "./baseLoginManager";
2
+ import { AsyncTokenStorage } from "./tokenStorage";
3
+ /**
4
+ * Manages OAuth2 authentication with asynchronous token storage.
5
+ *
6
+ * Extends BaseLoginManager to work with async storage implementations like IndexedDB or remote storage.
7
+ * Handles token refresh, expiration, and authentication state management.
8
+ *
9
+ * @param storage - Token storage implementation
10
+ * @param endpoint - OAuth2 server endpoint
11
+ * @param clientSecret - Client secret for authentication
12
+ * @param clientId - OAuth2 client identifier
13
+ * @param scopes - Space-separated OAuth2 scopes
14
+ * @param additionalParams - Additional OAuth2 parameters
15
+ * @example
16
+ * ```typescript
17
+ * const tokenStorage = new CustomAsyncStorage();
18
+ * const loginManager = new AsyncLoginManager(
19
+ * tokenStorage,
20
+ * 'https://api.example.com',
21
+ * 'client_secret',
22
+ * 'client_id',
23
+ * 'openid profile'
24
+ * );
25
+ * ```
26
+ */
27
+ export declare class AsyncLoginManager extends BaseLoginManager<AsyncTokenStorage> implements LoginManager {
28
+ signOut(): Promise<void>;
29
+ isSigned(): Promise<boolean>;
30
+ getToken(): Promise<string | null>;
31
+ load(): Promise<void>;
32
+ }
@@ -0,0 +1,46 @@
1
+ import { AsyncTokenStorage, Token, TokenStorage } from "./tokenStorage";
2
+ export interface LoginSuccess {
3
+ readonly type: "success";
4
+ }
5
+ export interface LoginFailure {
6
+ readonly type: "failure";
7
+ }
8
+ export interface LoginNetworkError {
9
+ readonly type: "networkError";
10
+ }
11
+ export type LoginResult = LoginFailure | LoginNetworkError | LoginSuccess;
12
+ export interface LoginManager extends BaseLoginManager<TokenStorage> {
13
+ }
14
+ export declare abstract class BaseLoginManager<TStorage extends TokenStorage> {
15
+ protected storage: TStorage;
16
+ private endpoint;
17
+ private clientSecret;
18
+ private clientId;
19
+ private scopes;
20
+ private additionalParams?;
21
+ private callbacks;
22
+ private refreshTokenCallbacks;
23
+ private isRefreshingToken;
24
+ constructor(storage: TStorage, endpoint: string, clientSecret: string | undefined, clientId: string, scopes: string, additionalParams?: Record<string, string> | undefined);
25
+ abstract signOut(): TStorage extends AsyncTokenStorage ? Promise<void> : void;
26
+ abstract isSigned(): TStorage extends AsyncTokenStorage ? Promise<boolean> : boolean;
27
+ abstract getToken(): Promise<string | null>;
28
+ trySignIn(username: string, password: string): Promise<LoginResult>;
29
+ trySignInWithFacebook(accessToken: string): Promise<LoginResult>;
30
+ trySignInWithOneTimeToken(token: string): Promise<LoginResult>;
31
+ trySignInWithGoogle(accessToken: string): Promise<LoginResult>;
32
+ trySignInWithLinkedIn(accessToken: string): Promise<LoginResult>;
33
+ tryRefreshToken(): Promise<boolean | null>;
34
+ protected tryRefreshTokenInternal(token: Token): Promise<boolean>;
35
+ onChange(callback: (isSignedIn: boolean) => void): void;
36
+ removeOnChange(callback: (isSignedIn: boolean) => void): void;
37
+ acquireToken(init: RequestInit): Promise<LoginResult>;
38
+ buildSignInRequest(username: string, password: string): RequestInit;
39
+ private buildSignInWithFacebookRequest;
40
+ private buildSignInWithOneTimeTokenRequest;
41
+ private buildSignInWithGoogleRequest;
42
+ private buildSignInWithLinkedInRequest;
43
+ private buildRefreshRequest;
44
+ private prepareHeaders;
45
+ protected notify(isSignedIn: boolean): void;
46
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Error thrown when token refresh fails.
3
+ *
4
+ * Indicates that the refresh token is invalid or expired, requiring user to sign in again.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * try {
9
+ * const token = await loginManager.getToken();
10
+ * } catch (error) {
11
+ * if (error instanceof CannotRefreshToken) {
12
+ * console.log('User needs to sign in again');
13
+ * }
14
+ * }
15
+ * ```
16
+ */
17
+ export declare class CannotRefreshToken extends Error {
18
+ constructor(m: string);
19
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Integrates Facebook Login SDK for web applications.
3
+ *
4
+ * Handles Facebook authentication flow and provides access tokens for OAuth2 sign-in.
5
+ * Automatically loads Facebook SDK and manages login state.
6
+ *
7
+ * @param facebookAppId - Facebook App ID
8
+ * @param facebookPermissions - Comma-separated Facebook permissions
9
+ * @example
10
+ * ```typescript
11
+ * const facebookClient = new FacebookClient('your-app-id', 'email,public_profile');
12
+ * facebookClient.setup();
13
+ * facebookClient.login((accessToken) => {
14
+ * return loginManager.trySignInWithFacebook(accessToken);
15
+ * });
16
+ * ```
17
+ */
18
+ export declare class FacebookClient {
19
+ private facebookAppId;
20
+ private facebookPermissions;
21
+ isSignedIn?: boolean;
22
+ private token;
23
+ constructor(facebookAppId: string, facebookPermissions: string);
24
+ get accessToken(): string;
25
+ setup(loginCallback?: (accessToken: string) => Promise<void>): void;
26
+ login(callback?: (accessToken: string) => Promise<void>): void;
27
+ private getLoginStatus;
28
+ private initializeSDK;
29
+ }