@capgo/capacitor-social-login 8.5.2 → 8.5.4

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 (33) hide show
  1. package/README.md +176 -24
  2. package/android/src/main/java/ee/forgr/capacitor/social/login/OAuth2LoginActivity.java +7 -0
  3. package/android/src/main/java/ee/forgr/capacitor/social/login/SocialLoginPlugin.java +31 -1
  4. package/android/src/main/java/ee/forgr/capacitor/social/login/TelegramProvider.java +352 -0
  5. package/android/src/main/java/ee/forgr/capacitor/social/login/helpers/DependencyAvailabilityChecker.java +21 -1
  6. package/dist/docs.json +299 -13
  7. package/dist/esm/auth-connect.js +2 -2
  8. package/dist/esm/auth-connect.js.map +1 -1
  9. package/dist/esm/definitions.d.ts +154 -10
  10. package/dist/esm/definitions.js.map +1 -1
  11. package/dist/esm/linkedin-provider.d.ts +17 -0
  12. package/dist/esm/linkedin-provider.js +54 -0
  13. package/dist/esm/linkedin-provider.js.map +1 -0
  14. package/dist/esm/oauth-popup-bridge.js +17 -7
  15. package/dist/esm/oauth-popup-bridge.js.map +1 -1
  16. package/dist/esm/oauth-popup-redirect.js +5 -0
  17. package/dist/esm/oauth-popup-redirect.js.map +1 -1
  18. package/dist/esm/social-login.d.ts +4 -8
  19. package/dist/esm/social-login.js +50 -3
  20. package/dist/esm/social-login.js.map +1 -1
  21. package/dist/esm/telegram-provider.d.ts +37 -0
  22. package/dist/esm/telegram-provider.js +292 -0
  23. package/dist/esm/telegram-provider.js.map +1 -0
  24. package/dist/esm/web.d.ts +4 -8
  25. package/dist/esm/web.js +52 -4
  26. package/dist/esm/web.js.map +1 -1
  27. package/dist/plugin.cjs.js +498 -51
  28. package/dist/plugin.cjs.js.map +1 -1
  29. package/dist/plugin.js +3181 -2734
  30. package/dist/plugin.js.map +1 -1
  31. package/ios/Sources/SocialLoginPlugin/SocialLoginPlugin.swift +67 -1
  32. package/ios/Sources/SocialLoginPlugin/TelegramProvider.swift +260 -0
  33. package/package.json +1 -1
@@ -2,6 +2,40 @@
2
2
 
3
3
  var core = require('@capacitor/core');
4
4
 
5
+ /******************************************************************************
6
+ Copyright (c) Microsoft Corporation.
7
+
8
+ Permission to use, copy, modify, and/or distribute this software for any
9
+ purpose with or without fee is hereby granted.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ ***************************************************************************** */
19
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
20
+
21
+
22
+ function __rest(s, e) {
23
+ var t = {};
24
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
25
+ t[p] = s[p];
26
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
27
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
28
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
29
+ t[p[i]] = s[p[i]];
30
+ }
31
+ return t;
32
+ }
33
+
34
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
35
+ var e = new Error(message);
36
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
37
+ };
38
+
5
39
  const USER_CANCELLED_CODE = 'USER_CANCELLED';
6
40
  const CANCELLED_PATTERNS = [
7
41
  'access_denied',
@@ -73,7 +107,13 @@ const OAUTH_STATE_KEY = 'social_login_oauth_pending';
73
107
  const OAUTH_POPUP_SESSION_KEY = 'social_login_oauth_popup';
74
108
  const OAUTH_RESULT_KEY_PREFIX = 'social_login_oauth_result_';
75
109
  const OAUTH_DELIVERED_KEY = 'social_login_oauth_delivered';
76
- const POPUP_WINDOW_NAMES = new Set(['OAuth2Login', 'XLogin', 'Google Sign In', 'Authorization']);
110
+ const POPUP_WINDOW_NAMES = new Set([
111
+ 'OAuth2Login',
112
+ 'XLogin',
113
+ 'Google Sign In',
114
+ 'Authorization',
115
+ 'TelegramLogin',
116
+ ]);
77
117
  function getOAuthResultKey(nonce) {
78
118
  return `${OAUTH_RESULT_KEY_PREFIX}${nonce}`;
79
119
  }
@@ -82,6 +122,8 @@ function getBroadcastChannelName(provider, nonceOrState) {
82
122
  return `oauth2_${nonceOrState}`;
83
123
  if (provider === 'twitter')
84
124
  return `twitter_oauth_${nonceOrState}`;
125
+ if (provider === 'telegram')
126
+ return `telegram_oauth_${nonceOrState}`;
85
127
  return `google_oauth_${nonceOrState}`;
86
128
  }
87
129
  function markOAuthPopup(nonce) {
@@ -102,12 +144,14 @@ function clearOAuthPopupMarker() {
102
144
  }
103
145
  }
104
146
  function hasOAuthRedirectParams() {
105
- const { search, hash } = window.location;
106
- return (search.includes('code=') ||
107
- search.includes('error=') ||
108
- hash.includes('access_token=') ||
109
- hash.includes('id_token=') ||
110
- hash.includes('error='));
147
+ const search = new URLSearchParams(window.location.search);
148
+ const hash = new URLSearchParams(window.location.hash.replace(/^#/, ''));
149
+ return (search.has('code') ||
150
+ search.has('error') ||
151
+ (search.has('hash') && search.has('auth_date')) ||
152
+ hash.has('access_token') ||
153
+ hash.has('id_token') ||
154
+ hash.has('error'));
111
155
  }
112
156
  function isOAuthPopupContext() {
113
157
  if (typeof window === 'undefined')
@@ -670,40 +714,6 @@ class GoogleSocialLogin extends BaseSocialLogin {
670
714
  }
671
715
  }
672
716
 
673
- /******************************************************************************
674
- Copyright (c) Microsoft Corporation.
675
-
676
- Permission to use, copy, modify, and/or distribute this software for any
677
- purpose with or without fee is hereby granted.
678
-
679
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
680
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
681
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
682
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
683
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
684
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
685
- PERFORMANCE OF THIS SOFTWARE.
686
- ***************************************************************************** */
687
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
688
-
689
-
690
- function __rest(s, e) {
691
- var t = {};
692
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
693
- t[p] = s[p];
694
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
695
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
696
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
697
- t[p[i]] = s[p[i]];
698
- }
699
- return t;
700
- }
701
-
702
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
703
- var e = new Error(message);
704
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
705
- };
706
-
707
717
  /**
708
718
  * OAuth2 Social Login Manager
709
719
  * Supports multiple OAuth2 provider configurations
@@ -1411,6 +1421,294 @@ class OAuth2SocialLogin extends BaseSocialLogin {
1411
1421
  }
1412
1422
  }
1413
1423
 
1424
+ class TelegramSocialLogin extends BaseSocialLogin {
1425
+ constructor() {
1426
+ super(...arguments);
1427
+ this.botId = null;
1428
+ this.redirectUrl = null;
1429
+ this.origin = null;
1430
+ this.requestAccess = 'write';
1431
+ this.languageCode = null;
1432
+ this.TOKENS_KEY = 'capgo_social_login_telegram_session_v1';
1433
+ this.STATE_PREFIX = 'capgo_social_login_telegram_state_';
1434
+ this.SESSION_TTL_MS = 24 * 60 * 60 * 1000; // 24h session window based on Telegram auth_date
1435
+ }
1436
+ initialize(botId, requestAccess, redirectUrl, origin, languageCode) {
1437
+ this.botId = botId;
1438
+ this.requestAccess = requestAccess !== null && requestAccess !== void 0 ? requestAccess : 'write';
1439
+ this.redirectUrl = redirectUrl !== null && redirectUrl !== void 0 ? redirectUrl : null;
1440
+ this.origin = origin !== null && origin !== void 0 ? origin : null;
1441
+ this.languageCode = languageCode !== null && languageCode !== void 0 ? languageCode : null;
1442
+ }
1443
+ async login(options) {
1444
+ var _a, _b, _c, _d, _e;
1445
+ if (!this.botId) {
1446
+ throw new Error('Telegram botId is not configured. Call initialize() first.');
1447
+ }
1448
+ const redirectUri = (_b = (_a = options.redirectUrl) !== null && _a !== void 0 ? _a : this.redirectUrl) !== null && _b !== void 0 ? _b : window.location.origin + window.location.pathname;
1449
+ const state = (_c = options.state) !== null && _c !== void 0 ? _c : this.generateState();
1450
+ const requestAccess = (_d = options.requestAccess) !== null && _d !== void 0 ? _d : this.requestAccess;
1451
+ const origin = (_e = this.origin) !== null && _e !== void 0 ? _e : this.getOriginFromRedirect(redirectUri);
1452
+ if (!this.isHttpOrigin(origin)) {
1453
+ throw new Error('Telegram origin must be a valid http(s) URL registered with BotFather. Pass origin when redirectUrl is not http(s).');
1454
+ }
1455
+ const returnTo = this.appendStateToRedirect(redirectUri, state);
1456
+ this.persistPendingLogin(state, {
1457
+ redirectUri,
1458
+ requestAccess,
1459
+ });
1460
+ localStorage.setItem(BaseSocialLogin.OAUTH_STATE_KEY, JSON.stringify({ provider: 'telegram', state }));
1461
+ const authUrl = this.buildAuthUrl(origin, requestAccess, returnTo);
1462
+ const popup = this.openPopup(authUrl);
1463
+ return new Promise((resolve, reject) => {
1464
+ if (!popup) {
1465
+ this.clearPendingTelegramState(state);
1466
+ reject(new Error('Unable to open login window. Please allow popups.'));
1467
+ return;
1468
+ }
1469
+ let settled = false;
1470
+ let timeoutHandle = 0;
1471
+ let popupClosedInterval = 0;
1472
+ let removeOAuthListener = null;
1473
+ const cleanup = (shouldClose = false) => {
1474
+ clearTimeout(timeoutHandle);
1475
+ clearInterval(popupClosedInterval);
1476
+ if (removeOAuthListener) {
1477
+ removeOAuthListener();
1478
+ removeOAuthListener = null;
1479
+ }
1480
+ this.clearPendingTelegramState(state);
1481
+ if (shouldClose) {
1482
+ try {
1483
+ popup.close();
1484
+ }
1485
+ catch (_a) {
1486
+ // ignore if already closed
1487
+ }
1488
+ }
1489
+ };
1490
+ const settle = (shouldClose, action) => {
1491
+ if (settled)
1492
+ return;
1493
+ settled = true;
1494
+ cleanup(shouldClose);
1495
+ action();
1496
+ };
1497
+ removeOAuthListener = listenForOAuthResult('telegram', state, {
1498
+ onResponse: (data) => {
1499
+ if ((data === null || data === void 0 ? void 0 : data.provider) && data.provider !== 'telegram') {
1500
+ return;
1501
+ }
1502
+ const _a = data, { provider: _ignoredProvider, type: _ignoredType, _ts: _ignoredTs } = _a, payload = __rest(_a, ["provider", "type", "_ts"]);
1503
+ settle(true, () => {
1504
+ resolve({
1505
+ provider: 'telegram',
1506
+ result: payload,
1507
+ });
1508
+ });
1509
+ },
1510
+ onError: (error, code) => {
1511
+ const message = error || 'Telegram login was cancelled.';
1512
+ settle(true, () => {
1513
+ reject(code === 'USER_CANCELLED' ? createUserCancelledError(message) : inferUserCancelledError(message));
1514
+ });
1515
+ },
1516
+ });
1517
+ timeoutHandle = window.setTimeout(() => {
1518
+ settle(true, () => {
1519
+ reject(new Error('Telegram login timed out.'));
1520
+ });
1521
+ }, 300000);
1522
+ popupClosedInterval = window.setInterval(() => {
1523
+ try {
1524
+ if (popup.closed) {
1525
+ settle(false, () => {
1526
+ reject(createUserCancelledError('Telegram login window was closed.'));
1527
+ });
1528
+ }
1529
+ }
1530
+ catch (_a) {
1531
+ clearInterval(popupClosedInterval);
1532
+ }
1533
+ }, 1000);
1534
+ });
1535
+ }
1536
+ async logout() {
1537
+ localStorage.removeItem(this.TOKENS_KEY);
1538
+ }
1539
+ async isLoggedIn() {
1540
+ const session = this.getStoredSession();
1541
+ if (!session) {
1542
+ return { isLoggedIn: false };
1543
+ }
1544
+ const isValid = session.expiresAt > Date.now();
1545
+ if (!isValid) {
1546
+ localStorage.removeItem(this.TOKENS_KEY);
1547
+ }
1548
+ return { isLoggedIn: isValid };
1549
+ }
1550
+ async getAuthorizationCode() {
1551
+ throw new Error('getAuthorizationCode is not available for Telegram.');
1552
+ }
1553
+ async refresh() {
1554
+ throw new Error('Telegram refresh is not supported. Call login() again.');
1555
+ }
1556
+ async handleOAuthRedirect(url, expectedState) {
1557
+ var _a;
1558
+ const params = url.searchParams;
1559
+ const stateFromUrl = params.get('state');
1560
+ if (!stateFromUrl) {
1561
+ return null;
1562
+ }
1563
+ if (expectedState && expectedState !== stateFromUrl) {
1564
+ return { error: 'Telegram login session expired or state mismatch.' };
1565
+ }
1566
+ const pending = this.consumePendingLogin(stateFromUrl);
1567
+ if (!pending) {
1568
+ localStorage.removeItem(BaseSocialLogin.OAUTH_STATE_KEY);
1569
+ return { error: 'Telegram login session expired or state mismatch.' };
1570
+ }
1571
+ const error = params.get('error');
1572
+ if (error) {
1573
+ localStorage.removeItem(BaseSocialLogin.OAUTH_STATE_KEY);
1574
+ return { error: params.get('error_description') || error };
1575
+ }
1576
+ const id = params.get('id');
1577
+ const authDateRaw = params.get('auth_date');
1578
+ const hash = params.get('hash');
1579
+ if (!id || !authDateRaw || !hash) {
1580
+ localStorage.removeItem(BaseSocialLogin.OAUTH_STATE_KEY);
1581
+ return { error: 'Telegram login payload is incomplete.' };
1582
+ }
1583
+ const profile = {
1584
+ id,
1585
+ firstName: (_a = params.get('first_name')) !== null && _a !== void 0 ? _a : '',
1586
+ lastName: params.get('last_name'),
1587
+ username: params.get('username'),
1588
+ photoUrl: params.get('photo_url'),
1589
+ };
1590
+ const authDate = Number(authDateRaw);
1591
+ if (!Number.isInteger(authDate)) {
1592
+ localStorage.removeItem(BaseSocialLogin.OAUTH_STATE_KEY);
1593
+ return { error: 'Telegram auth_date is invalid.' };
1594
+ }
1595
+ const result = {
1596
+ profile,
1597
+ authDate,
1598
+ hash,
1599
+ requestAccess: pending.requestAccess,
1600
+ };
1601
+ this.persistSession({
1602
+ expiresAt: authDate * 1000 + this.SESSION_TTL_MS,
1603
+ });
1604
+ localStorage.removeItem(BaseSocialLogin.OAUTH_STATE_KEY);
1605
+ return {
1606
+ provider: 'telegram',
1607
+ result,
1608
+ };
1609
+ }
1610
+ buildAuthUrl(origin, requestAccess, returnTo) {
1611
+ var _a;
1612
+ const params = new URLSearchParams({
1613
+ bot_id: (_a = this.botId) !== null && _a !== void 0 ? _a : '',
1614
+ origin,
1615
+ request_access: requestAccess,
1616
+ return_to: returnTo,
1617
+ embed: '1',
1618
+ mobile: '1',
1619
+ });
1620
+ if (this.languageCode) {
1621
+ params.set('lang', this.languageCode);
1622
+ }
1623
+ return `https://oauth.telegram.org/auth?${params.toString()}`;
1624
+ }
1625
+ openPopup(authUrl) {
1626
+ const width = 500;
1627
+ const height = 650;
1628
+ const left = window.screenX + (window.outerWidth - width) / 2;
1629
+ const top = window.screenY + (window.outerHeight - height) / 2;
1630
+ return window.open(authUrl, 'TelegramLogin', `width=${width},height=${height},left=${left},top=${top},popup=1`);
1631
+ }
1632
+ appendStateToRedirect(redirectUri, state) {
1633
+ try {
1634
+ const redirect = new URL(redirectUri);
1635
+ redirect.searchParams.set('state', state);
1636
+ return redirect.toString();
1637
+ }
1638
+ catch (_a) {
1639
+ return redirectUri;
1640
+ }
1641
+ }
1642
+ isHttpOrigin(value) {
1643
+ if (!value) {
1644
+ return false;
1645
+ }
1646
+ try {
1647
+ const url = new URL(value);
1648
+ return url.protocol === 'http:' || url.protocol === 'https:';
1649
+ }
1650
+ catch (_a) {
1651
+ return false;
1652
+ }
1653
+ }
1654
+ getOriginFromRedirect(redirectUri) {
1655
+ return this.isHttpOrigin(redirectUri) ? new URL(redirectUri).origin : undefined;
1656
+ }
1657
+ persistSession(session) {
1658
+ localStorage.setItem(this.TOKENS_KEY, JSON.stringify(session));
1659
+ }
1660
+ getStoredSession() {
1661
+ const raw = localStorage.getItem(this.TOKENS_KEY);
1662
+ if (!raw) {
1663
+ return null;
1664
+ }
1665
+ try {
1666
+ return JSON.parse(raw);
1667
+ }
1668
+ catch (err) {
1669
+ console.warn('Failed to parse stored Telegram session', err);
1670
+ return null;
1671
+ }
1672
+ }
1673
+ persistPendingLogin(state, payload) {
1674
+ localStorage.setItem(`${this.STATE_PREFIX}${state}`, JSON.stringify(payload));
1675
+ }
1676
+ consumePendingLogin(state) {
1677
+ const key = `${this.STATE_PREFIX}${state}`;
1678
+ const raw = localStorage.getItem(key);
1679
+ localStorage.removeItem(key);
1680
+ if (!raw) {
1681
+ return null;
1682
+ }
1683
+ try {
1684
+ return JSON.parse(raw);
1685
+ }
1686
+ catch (err) {
1687
+ console.warn('Failed to parse pending Telegram login payload', err);
1688
+ return null;
1689
+ }
1690
+ }
1691
+ clearPendingTelegramState(state) {
1692
+ try {
1693
+ localStorage.removeItem(`${this.STATE_PREFIX}${state}`);
1694
+ const raw = localStorage.getItem(BaseSocialLogin.OAUTH_STATE_KEY);
1695
+ if (!raw) {
1696
+ return;
1697
+ }
1698
+ const parsed = JSON.parse(raw);
1699
+ if (parsed.provider === 'telegram' && parsed.state === state) {
1700
+ localStorage.removeItem(BaseSocialLogin.OAUTH_STATE_KEY);
1701
+ }
1702
+ }
1703
+ catch (_a) {
1704
+ // ignore storage errors
1705
+ }
1706
+ }
1707
+ generateState() {
1708
+ return [...crypto.getRandomValues(new Uint8Array(16))].map((b) => b.toString(16).padStart(2, '0')).join('');
1709
+ }
1710
+ }
1711
+
1414
1712
  class TwitterSocialLogin extends BaseSocialLogin {
1415
1713
  constructor() {
1416
1714
  super(...arguments);
@@ -1802,11 +2100,15 @@ async function parseRedirectResult() {
1802
2100
  const googleProvider = new GoogleSocialLogin();
1803
2101
  const oauth2Provider = new OAuth2SocialLogin();
1804
2102
  const twitterProvider = new TwitterSocialLogin();
2103
+ const telegramProvider = new TelegramSocialLogin();
1805
2104
  let result = null;
1806
2105
  switch (provider) {
1807
2106
  case 'twitter':
1808
2107
  result = await twitterProvider.handleOAuthRedirect(url, state);
1809
2108
  break;
2109
+ case 'telegram':
2110
+ result = await telegramProvider.handleOAuthRedirect(url, state);
2111
+ break;
1810
2112
  case 'oauth2':
1811
2113
  result = await oauth2Provider.handleOAuthRedirect(url, state);
1812
2114
  break;
@@ -1878,39 +2180,138 @@ function initOAuthPopupRedirectHandler() {
1878
2180
  // Auto-run on import so popup windows finish OAuth even before plugin lazy-load
1879
2181
  initOAuthPopupRedirectHandler();
1880
2182
 
2183
+ const LINKEDIN_PROVIDER_ID = 'linkedin';
2184
+ const LINKEDIN_REDIRECT_PENDING_KEY = 'capgo_social_login_linkedin_redirect';
2185
+ const LINKEDIN_AUTH_URL = 'https://www.linkedin.com/oauth/v2/authorization';
2186
+ const LINKEDIN_TOKEN_URL = 'https://www.linkedin.com/oauth/v2/accessToken';
2187
+ const LINKEDIN_RESOURCE_URL = 'https://api.linkedin.com/v2/userinfo';
2188
+ const LINKEDIN_DEFAULT_SCOPE = 'openid profile email';
2189
+ const normalizeScope = (scope) => {
2190
+ if (!scope)
2191
+ return LINKEDIN_DEFAULT_SCOPE;
2192
+ if (Array.isArray(scope)) {
2193
+ return scope.filter(Boolean).join(' ');
2194
+ }
2195
+ return scope;
2196
+ };
2197
+ const buildLinkedInOAuthConfig = (config) => {
2198
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
2199
+ const scope = normalizeScope((_a = config.scope) !== null && _a !== void 0 ? _a : config.scopes);
2200
+ return Object.assign(Object.assign({}, config), { appId: (_b = config.appId) !== null && _b !== void 0 ? _b : config.clientId, clientSecret: config.clientSecret, authorizationBaseUrl: (_d = (_c = config.authorizationBaseUrl) !== null && _c !== void 0 ? _c : config.authorizationEndpoint) !== null && _d !== void 0 ? _d : LINKEDIN_AUTH_URL, accessTokenEndpoint: (_f = (_e = config.accessTokenEndpoint) !== null && _e !== void 0 ? _e : config.tokenEndpoint) !== null && _f !== void 0 ? _f : LINKEDIN_TOKEN_URL, resourceUrl: (_g = config.resourceUrl) !== null && _g !== void 0 ? _g : LINKEDIN_RESOURCE_URL, responseType: (_h = config.responseType) !== null && _h !== void 0 ? _h : 'code', pkceEnabled: (_j = config.pkceEnabled) !== null && _j !== void 0 ? _j : true, scope });
2201
+ };
2202
+ const createOAuthState = () => [...crypto.getRandomValues(new Uint8Array(16))].map((b) => b.toString(16).padStart(2, '0')).join('');
2203
+ const buildLinkedInLoginOptions = (options = {}) => {
2204
+ var _a;
2205
+ const scope = (_a = options.scope) !== null && _a !== void 0 ? _a : options.scopes;
2206
+ const loginOptions = Object.assign(Object.assign(Object.assign({}, options), { providerId: LINKEDIN_PROVIDER_ID }), (scope === undefined ? {} : { scope }));
2207
+ // Bind convenience-redirect remapping to this OAuth state, not a generic sentinel.
2208
+ if (loginOptions.flow === 'redirect' && !loginOptions.state) {
2209
+ loginOptions.state = createOAuthState();
2210
+ }
2211
+ return loginOptions;
2212
+ };
2213
+ const isLinkedInOAuthResult = (result) => result.provider === 'oauth2' && result.result.providerId === LINKEDIN_PROVIDER_ID;
2214
+ const asLinkedInLoginResult = (result) => ({
2215
+ provider: 'linkedin',
2216
+ result: result.result,
2217
+ });
2218
+ const markLinkedInRedirectPending = (state) => {
2219
+ try {
2220
+ sessionStorage.setItem(LINKEDIN_REDIRECT_PENDING_KEY, state);
2221
+ }
2222
+ catch (_a) {
2223
+ // sessionStorage may be unavailable
2224
+ }
2225
+ };
2226
+ const consumeLinkedInRedirectPending = (state) => {
2227
+ try {
2228
+ const pending = sessionStorage.getItem(LINKEDIN_REDIRECT_PENDING_KEY);
2229
+ sessionStorage.removeItem(LINKEDIN_REDIRECT_PENDING_KEY);
2230
+ return Boolean(pending && state && pending === state);
2231
+ }
2232
+ catch (_a) {
2233
+ return false;
2234
+ }
2235
+ };
2236
+
1881
2237
  const GOOGLE_OFFLINE_REFRESH_MESSAGE = "Google refresh() is not available when using offline mode. Offline mode only returns serverAuthCode for backend token exchange. Send serverAuthCode to your backend and refresh tokens there, or switch google.mode to 'online' for client-side refresh.";
1882
2238
  const rawSocialLogin = core.registerPlugin('SocialLogin', {
1883
2239
  web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.SocialLoginWeb()),
1884
2240
  });
1885
2241
  class SocialLoginClient {
2242
+ normalizeInitializeOptions(options) {
2243
+ var _a;
2244
+ if (!options.linkedin) {
2245
+ return options;
2246
+ }
2247
+ const { linkedin, oauth2 } = options, rest = __rest(options, ["linkedin", "oauth2"]);
2248
+ return Object.assign(Object.assign({}, rest), { linkedin, oauth2: Object.assign(Object.assign({}, (oauth2 !== null && oauth2 !== void 0 ? oauth2 : {})), { [LINKEDIN_PROVIDER_ID]: (_a = oauth2 === null || oauth2 === void 0 ? void 0 : oauth2[LINKEDIN_PROVIDER_ID]) !== null && _a !== void 0 ? _a : buildLinkedInOAuthConfig(linkedin) }) });
2249
+ }
1886
2250
  constructor() {
1887
2251
  this.initialize = this.initialize.bind(this);
1888
2252
  this.refresh = this.refresh.bind(this);
1889
2253
  }
1890
2254
  async initialize(options) {
1891
- await rawSocialLogin.initialize(options);
1892
- this.initializeOptions = options;
2255
+ const normalized = this.normalizeInitializeOptions(options);
2256
+ await rawSocialLogin.initialize(normalized);
2257
+ this.initializeOptions = normalized;
1893
2258
  }
1894
2259
  async login(options) {
2260
+ var _a;
2261
+ if (options.provider === 'linkedin') {
2262
+ const linkedInOptions = (_a = options.options) !== null && _a !== void 0 ? _a : {};
2263
+ const oauthOptions = buildLinkedInLoginOptions(linkedInOptions);
2264
+ if (oauthOptions.flow === 'redirect' && oauthOptions.state) {
2265
+ markLinkedInRedirectPending(oauthOptions.state);
2266
+ }
2267
+ const response = await rawSocialLogin.login({
2268
+ provider: 'oauth2',
2269
+ options: oauthOptions,
2270
+ });
2271
+ return asLinkedInLoginResult(response);
2272
+ }
1895
2273
  return rawSocialLogin.login(options);
1896
2274
  }
1897
2275
  async logout(options) {
2276
+ if (options.provider === 'linkedin') {
2277
+ return rawSocialLogin.logout({ provider: 'oauth2', providerId: LINKEDIN_PROVIDER_ID });
2278
+ }
1898
2279
  return rawSocialLogin.logout(options);
1899
2280
  }
1900
2281
  async isLoggedIn(options) {
2282
+ if (options.provider === 'linkedin') {
2283
+ return rawSocialLogin.isLoggedIn({ provider: 'oauth2', providerId: LINKEDIN_PROVIDER_ID });
2284
+ }
1901
2285
  return rawSocialLogin.isLoggedIn(options);
1902
2286
  }
1903
2287
  async getAuthorizationCode(options) {
2288
+ if (options.provider === 'linkedin') {
2289
+ return rawSocialLogin.getAuthorizationCode({ provider: 'oauth2', providerId: LINKEDIN_PROVIDER_ID });
2290
+ }
1904
2291
  return rawSocialLogin.getAuthorizationCode(options);
1905
2292
  }
1906
2293
  async refresh(options) {
1907
- var _a, _b;
2294
+ var _a, _b, _c;
1908
2295
  if (options.provider === 'google' && ((_b = (_a = this.initializeOptions) === null || _a === void 0 ? void 0 : _a.google) === null || _b === void 0 ? void 0 : _b.mode) === 'offline') {
1909
2296
  console.warn(`[SocialLogin] ${GOOGLE_OFFLINE_REFRESH_MESSAGE}`);
1910
2297
  }
2298
+ if (options.provider === 'linkedin') {
2299
+ return rawSocialLogin.refresh({
2300
+ provider: 'oauth2',
2301
+ options: buildLinkedInLoginOptions((_c = options.options) !== null && _c !== void 0 ? _c : {}),
2302
+ });
2303
+ }
1911
2304
  return rawSocialLogin.refresh(options);
1912
2305
  }
1913
2306
  async refreshToken(options) {
2307
+ if (options.provider === 'linkedin') {
2308
+ return rawSocialLogin.refreshToken({
2309
+ provider: 'oauth2',
2310
+ providerId: LINKEDIN_PROVIDER_ID,
2311
+ refreshToken: options.refreshToken,
2312
+ additionalParameters: options.additionalParameters,
2313
+ });
2314
+ }
1914
2315
  return rawSocialLogin.refreshToken(options);
1915
2316
  }
1916
2317
  async handleRedirectCallback() {
@@ -2147,7 +2548,7 @@ const createAuthConnectClient = (client) => ({
2147
2548
  providerSpecificCall: async (options) => client.providerSpecificCall(options),
2148
2549
  getPluginVersion: async () => client.getPluginVersion(),
2149
2550
  });
2150
- const SocialLoginAuthConnect = createAuthConnectClient(SocialLoginBase);
2551
+ const SocialLoginAuthConnect = createAuthConnectClient(SocialLogin);
2151
2552
 
2152
2553
  class AppleSocialLogin extends BaseSocialLogin {
2153
2554
  constructor() {
@@ -2449,6 +2850,7 @@ class SocialLoginWeb extends core.WebPlugin {
2449
2850
  this.appleProvider = new AppleSocialLogin();
2450
2851
  this.facebookProvider = new FacebookSocialLogin();
2451
2852
  this.twitterProvider = new TwitterSocialLogin();
2853
+ this.telegramProvider = new TelegramSocialLogin();
2452
2854
  this.oauth2Provider = new OAuth2SocialLogin();
2453
2855
  // Auto-finish OAuth redirects only when running inside a popup window.
2454
2856
  // For redirect-based flows (full page navigation), the app should call `handleRedirectCallback()` explicitly.
@@ -2488,6 +2890,9 @@ class SocialLoginWeb extends core.WebPlugin {
2488
2890
  case 'twitter':
2489
2891
  result = await this.twitterProvider.handleOAuthRedirect(url, state);
2490
2892
  break;
2893
+ case 'telegram':
2894
+ result = await this.telegramProvider.handleOAuthRedirect(url, state);
2895
+ break;
2491
2896
  case 'oauth2':
2492
2897
  result = await this.oauth2Provider.handleOAuthRedirect(url, state);
2493
2898
  break;
@@ -2528,7 +2933,7 @@ class SocialLoginWeb extends core.WebPlugin {
2528
2933
  }
2529
2934
  }
2530
2935
  async initialize(options) {
2531
- var _a, _b, _c, _d;
2936
+ var _a, _b, _c, _d, _e, _f;
2532
2937
  const initPromises = [];
2533
2938
  if ((_a = options.google) === null || _a === void 0 ? void 0 : _a.webClientId) {
2534
2939
  initPromises.push(this.googleProvider.initialize(options.google.webClientId, options.google.mode, options.google.hostedDomain, options.google.redirectUrl));
@@ -2542,12 +2947,20 @@ class SocialLoginWeb extends core.WebPlugin {
2542
2947
  if ((_d = options.twitter) === null || _d === void 0 ? void 0 : _d.clientId) {
2543
2948
  initPromises.push(this.twitterProvider.initialize(options.twitter.clientId, options.twitter.redirectUrl, options.twitter.defaultScopes, options.twitter.forceLogin, options.twitter.audience));
2544
2949
  }
2545
- if (options.oauth2 && Object.keys(options.oauth2).length > 0) {
2546
- initPromises.push(this.oauth2Provider.initializeProviders(options.oauth2));
2950
+ if ((_e = options.telegram) === null || _e === void 0 ? void 0 : _e.botId) {
2951
+ this.telegramProvider.initialize(options.telegram.botId, options.telegram.requestAccess, options.telegram.redirectUrl, options.telegram.origin, options.telegram.languageCode);
2952
+ }
2953
+ const oauth2Configs = Object.assign({}, ((_f = options.oauth2) !== null && _f !== void 0 ? _f : {}));
2954
+ if (options.linkedin && !oauth2Configs[LINKEDIN_PROVIDER_ID]) {
2955
+ oauth2Configs[LINKEDIN_PROVIDER_ID] = buildLinkedInOAuthConfig(options.linkedin);
2956
+ }
2957
+ if (Object.keys(oauth2Configs).length > 0) {
2958
+ initPromises.push(this.oauth2Provider.initializeProviders(oauth2Configs));
2547
2959
  }
2548
2960
  await Promise.all(initPromises);
2549
2961
  }
2550
2962
  async login(options) {
2963
+ var _a;
2551
2964
  switch (options.provider) {
2552
2965
  case 'google':
2553
2966
  return this.googleProvider.login(options.options);
@@ -2557,6 +2970,17 @@ class SocialLoginWeb extends core.WebPlugin {
2557
2970
  return this.facebookProvider.login(options.options);
2558
2971
  case 'twitter':
2559
2972
  return this.twitterProvider.login(options.options);
2973
+ case 'telegram':
2974
+ return this.telegramProvider.login(options.options);
2975
+ case 'linkedin': {
2976
+ const linkedInOptions = (_a = options.options) !== null && _a !== void 0 ? _a : {};
2977
+ const oauthOptions = buildLinkedInLoginOptions(linkedInOptions);
2978
+ if (oauthOptions.flow === 'redirect' && oauthOptions.state) {
2979
+ markLinkedInRedirectPending(oauthOptions.state);
2980
+ }
2981
+ const response = await this.oauth2Provider.login(oauthOptions);
2982
+ return asLinkedInLoginResult(response);
2983
+ }
2560
2984
  case 'oauth2':
2561
2985
  return this.oauth2Provider.login(options.options);
2562
2986
  default:
@@ -2573,6 +2997,10 @@ class SocialLoginWeb extends core.WebPlugin {
2573
2997
  return this.facebookProvider.logout();
2574
2998
  case 'twitter':
2575
2999
  return this.twitterProvider.logout();
3000
+ case 'telegram':
3001
+ return this.telegramProvider.logout();
3002
+ case 'linkedin':
3003
+ return this.oauth2Provider.logout(LINKEDIN_PROVIDER_ID);
2576
3004
  case 'oauth2':
2577
3005
  if (!options.providerId) {
2578
3006
  throw new Error('providerId is required for oauth2 logout');
@@ -2592,6 +3020,10 @@ class SocialLoginWeb extends core.WebPlugin {
2592
3020
  return this.facebookProvider.isLoggedIn();
2593
3021
  case 'twitter':
2594
3022
  return this.twitterProvider.isLoggedIn();
3023
+ case 'telegram':
3024
+ return this.telegramProvider.isLoggedIn();
3025
+ case 'linkedin':
3026
+ return this.oauth2Provider.isLoggedIn(LINKEDIN_PROVIDER_ID);
2595
3027
  case 'oauth2':
2596
3028
  if (!options.providerId) {
2597
3029
  throw new Error('providerId is required for oauth2 isLoggedIn');
@@ -2611,6 +3043,8 @@ class SocialLoginWeb extends core.WebPlugin {
2611
3043
  return this.facebookProvider.getAuthorizationCode();
2612
3044
  case 'twitter':
2613
3045
  return this.twitterProvider.getAuthorizationCode();
3046
+ case 'linkedin':
3047
+ return this.oauth2Provider.getAuthorizationCode(LINKEDIN_PROVIDER_ID);
2614
3048
  case 'oauth2':
2615
3049
  if (!options.providerId) {
2616
3050
  throw new Error('providerId is required for oauth2 getAuthorizationCode');
@@ -2630,6 +3064,10 @@ class SocialLoginWeb extends core.WebPlugin {
2630
3064
  return this.facebookProvider.refresh(options.options);
2631
3065
  case 'twitter':
2632
3066
  return this.twitterProvider.refresh();
3067
+ case 'telegram':
3068
+ return this.telegramProvider.refresh();
3069
+ case 'linkedin':
3070
+ return this.oauth2Provider.refresh(LINKEDIN_PROVIDER_ID);
2633
3071
  case 'oauth2': {
2634
3072
  const oauth2Options = options.options;
2635
3073
  if (!(oauth2Options === null || oauth2Options === void 0 ? void 0 : oauth2Options.providerId)) {
@@ -2659,19 +3097,28 @@ class SocialLoginWeb extends core.WebPlugin {
2659
3097
  }
2660
3098
  }
2661
3099
  async refreshToken(options) {
3100
+ if (options.provider === 'linkedin') {
3101
+ return this.oauth2Provider.refreshToken(LINKEDIN_PROVIDER_ID, options.refreshToken, options.additionalParameters);
3102
+ }
2662
3103
  if (options.provider !== 'oauth2') {
2663
- throw new Error('refreshToken is only implemented for oauth2 on web');
3104
+ throw new Error('refreshToken is only implemented for oauth2 and linkedin on web');
2664
3105
  }
2665
3106
  return this.oauth2Provider.refreshToken(options.providerId, options.refreshToken, options.additionalParameters);
2666
3107
  }
2667
3108
  async handleRedirectCallback() {
3109
+ var _a;
2668
3110
  const parsed = await this.parseRedirectResult();
3111
+ const callbackState = (_a = parsed.state) !== null && _a !== void 0 ? _a : new URL(window.location.href).searchParams.get('state');
3112
+ const pendingLinkedInRedirect = consumeLinkedInRedirectPending(callbackState);
2669
3113
  const result = parsed.result;
2670
3114
  if (!result)
2671
3115
  return null;
2672
3116
  if ('error' in result) {
2673
3117
  throw inferUserCancelledError(result.error);
2674
3118
  }
3119
+ if (pendingLinkedInRedirect && isLinkedInOAuthResult(result)) {
3120
+ return asLinkedInLoginResult(result);
3121
+ }
2675
3122
  return result;
2676
3123
  }
2677
3124
  async decodeIdToken(options) {
@@ -2745,8 +3192,8 @@ class SocialLoginWeb extends core.WebPlugin {
2745
3192
  SocialLoginWeb.OAUTH_STATE_KEY = OAUTH_STATE_KEY;
2746
3193
 
2747
3194
  var web = /*#__PURE__*/Object.freeze({
2748
- __proto__: null,
2749
- SocialLoginWeb: SocialLoginWeb
3195
+ __proto__: null,
3196
+ SocialLoginWeb: SocialLoginWeb
2750
3197
  });
2751
3198
 
2752
3199
  exports.SocialLogin = SocialLogin;