@capgo/capacitor-social-login 8.5.3 → 8.5.5

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.
@@ -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',
@@ -680,40 +714,13 @@ class GoogleSocialLogin extends BaseSocialLogin {
680
714
  }
681
715
  }
682
716
 
683
- /******************************************************************************
684
- Copyright (c) Microsoft Corporation.
685
-
686
- Permission to use, copy, modify, and/or distribute this software for any
687
- purpose with or without fee is hereby granted.
688
-
689
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
690
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
691
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
692
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
693
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
694
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
695
- PERFORMANCE OF THIS SOFTWARE.
696
- ***************************************************************************** */
697
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
698
-
699
-
700
- function __rest(s, e) {
701
- var t = {};
702
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
703
- t[p] = s[p];
704
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
705
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
706
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
707
- t[p[i]] = s[p[i]];
708
- }
709
- return t;
710
- }
711
-
712
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
713
- var e = new Error(message);
714
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
717
+ const normalizeOAuthParamName = (value, fallback) => {
718
+ if (typeof value !== 'string') {
719
+ return fallback;
720
+ }
721
+ const trimmed = value.trim();
722
+ return trimmed.length > 0 ? trimmed : fallback;
715
723
  };
716
-
717
724
  /**
718
725
  * OAuth2 Social Login Manager
719
726
  * Supports multiple OAuth2 provider configurations
@@ -756,6 +763,8 @@ class OAuth2SocialLogin extends BaseSocialLogin {
756
763
  return {
757
764
  appId,
758
765
  clientSecret: config.clientSecret,
766
+ clientIdParamName: normalizeOAuthParamName(config.clientIdParamName, 'client_id'),
767
+ clientSecretParamName: normalizeOAuthParamName(config.clientSecretParamName, 'client_secret'),
759
768
  issuerUrl: config.issuerUrl,
760
769
  authorizationBaseUrl,
761
770
  accessTokenEndpoint,
@@ -835,11 +844,17 @@ class OAuth2SocialLogin extends BaseSocialLogin {
835
844
  this.persistConfiguration(providerId, internalConfig);
836
845
  }
837
846
  }
847
+ normalizeStoredConfig(config) {
848
+ return Object.assign(Object.assign({}, config), { clientIdParamName: normalizeOAuthParamName(config.clientIdParamName, 'client_id'), clientSecretParamName: normalizeOAuthParamName(config.clientSecretParamName, 'client_secret') });
849
+ }
838
850
  getProvider(providerId) {
839
851
  const config = this.providers.get(providerId);
840
852
  if (!config) {
841
853
  throw new Error(`OAuth2 provider '${providerId}' not configured. Call initialize() first.`);
842
854
  }
855
+ // Mutate in place so later discovery writes are visible to the same config object.
856
+ config.clientIdParamName = normalizeOAuthParamName(config.clientIdParamName, 'client_id');
857
+ config.clientSecretParamName = normalizeOAuthParamName(config.clientSecretParamName, 'client_secret');
843
858
  return config;
844
859
  }
845
860
  getTokensKey(providerId) {
@@ -866,7 +881,7 @@ class OAuth2SocialLogin extends BaseSocialLogin {
866
881
  try {
867
882
  const raw = localStorage.getItem(key);
868
883
  if (raw) {
869
- const config = JSON.parse(raw);
884
+ const config = this.normalizeStoredConfig(JSON.parse(raw));
870
885
  this.providers.set(providerId, config);
871
886
  }
872
887
  }
@@ -888,7 +903,7 @@ class OAuth2SocialLogin extends BaseSocialLogin {
888
903
  // Build authorization URL
889
904
  const params = new URLSearchParams({
890
905
  response_type: config.responseType,
891
- client_id: config.appId,
906
+ [config.clientIdParamName]: config.appId,
892
907
  redirect_uri: redirectUri,
893
908
  state,
894
909
  });
@@ -1246,7 +1261,7 @@ class OAuth2SocialLogin extends BaseSocialLogin {
1246
1261
  }
1247
1262
  const params = new URLSearchParams({
1248
1263
  grant_type: 'authorization_code',
1249
- client_id: config.appId,
1264
+ [config.clientIdParamName]: config.appId,
1250
1265
  code,
1251
1266
  redirect_uri: pending.redirectUri,
1252
1267
  });
@@ -1254,7 +1269,7 @@ class OAuth2SocialLogin extends BaseSocialLogin {
1254
1269
  params.set('code_verifier', pending.codeVerifier);
1255
1270
  }
1256
1271
  if (config.clientSecret) {
1257
- params.set('client_secret', config.clientSecret);
1272
+ params.set(config.clientSecretParamName, config.clientSecret);
1258
1273
  }
1259
1274
  if (config.additionalTokenParameters) {
1260
1275
  for (const [k, v] of Object.entries(config.additionalTokenParameters)) {
@@ -1285,10 +1300,10 @@ class OAuth2SocialLogin extends BaseSocialLogin {
1285
1300
  const params = new URLSearchParams({
1286
1301
  grant_type: 'refresh_token',
1287
1302
  refresh_token: refreshToken,
1288
- client_id: config.appId,
1303
+ [config.clientIdParamName]: config.appId,
1289
1304
  });
1290
1305
  if (config.clientSecret) {
1291
- params.set('client_secret', config.clientSecret);
1306
+ params.set(config.clientSecretParamName, config.clientSecret);
1292
1307
  }
1293
1308
  if (config.additionalTokenParameters) {
1294
1309
  for (const [k, v] of Object.entries(config.additionalTokenParameters)) {
@@ -2180,43 +2195,225 @@ function initOAuthPopupRedirectHandler() {
2180
2195
  // Auto-run on import so popup windows finish OAuth even before plugin lazy-load
2181
2196
  initOAuthPopupRedirectHandler();
2182
2197
 
2198
+ const LINKEDIN_PROVIDER_ID = 'linkedin';
2199
+ const LINKEDIN_REDIRECT_PENDING_KEY = 'capgo_social_login_linkedin_redirect';
2200
+ const LINKEDIN_AUTH_URL = 'https://www.linkedin.com/oauth/v2/authorization';
2201
+ const LINKEDIN_TOKEN_URL = 'https://www.linkedin.com/oauth/v2/accessToken';
2202
+ const LINKEDIN_RESOURCE_URL = 'https://api.linkedin.com/v2/userinfo';
2203
+ const LINKEDIN_DEFAULT_SCOPE = 'openid profile email';
2204
+ const normalizeScope = (scope) => {
2205
+ if (!scope)
2206
+ return LINKEDIN_DEFAULT_SCOPE;
2207
+ if (Array.isArray(scope)) {
2208
+ return scope.filter(Boolean).join(' ');
2209
+ }
2210
+ return scope;
2211
+ };
2212
+ const buildLinkedInOAuthConfig = (config) => {
2213
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
2214
+ const scope = normalizeScope((_a = config.scope) !== null && _a !== void 0 ? _a : config.scopes);
2215
+ 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 });
2216
+ };
2217
+ const createOAuthState = () => [...crypto.getRandomValues(new Uint8Array(16))].map((b) => b.toString(16).padStart(2, '0')).join('');
2218
+ const buildLinkedInLoginOptions = (options = {}) => {
2219
+ var _a;
2220
+ const scope = (_a = options.scope) !== null && _a !== void 0 ? _a : options.scopes;
2221
+ const loginOptions = Object.assign(Object.assign(Object.assign({}, options), { providerId: LINKEDIN_PROVIDER_ID }), (scope === undefined ? {} : { scope }));
2222
+ // Bind convenience-redirect remapping to this OAuth state, not a generic sentinel.
2223
+ if (loginOptions.flow === 'redirect' && !loginOptions.state) {
2224
+ loginOptions.state = createOAuthState();
2225
+ }
2226
+ return loginOptions;
2227
+ };
2228
+ const isLinkedInOAuthResult = (result) => result.provider === 'oauth2' && result.result.providerId === LINKEDIN_PROVIDER_ID;
2229
+ const asLinkedInLoginResult = (result) => ({
2230
+ provider: 'linkedin',
2231
+ result: result.result,
2232
+ });
2233
+ const markLinkedInRedirectPending = (state) => {
2234
+ try {
2235
+ sessionStorage.setItem(LINKEDIN_REDIRECT_PENDING_KEY, state);
2236
+ }
2237
+ catch (_a) {
2238
+ // sessionStorage may be unavailable
2239
+ }
2240
+ };
2241
+ const consumeLinkedInRedirectPending = (state) => {
2242
+ try {
2243
+ const pending = sessionStorage.getItem(LINKEDIN_REDIRECT_PENDING_KEY);
2244
+ sessionStorage.removeItem(LINKEDIN_REDIRECT_PENDING_KEY);
2245
+ return Boolean(pending && state && pending === state);
2246
+ }
2247
+ catch (_a) {
2248
+ return false;
2249
+ }
2250
+ };
2251
+
2252
+ const TIKTOK_PROVIDER_ID = 'tiktok';
2253
+ const TIKTOK_AUTH_URL = 'https://www.tiktok.com/v2/auth/authorize/';
2254
+ const TIKTOK_TOKEN_URL = 'https://open.tiktokapis.com/v2/oauth/token/';
2255
+ const TIKTOK_DEFAULT_SCOPE = 'user.info.basic';
2256
+ // TikTok Login Kit expects comma-separated scopes, not space-separated.
2257
+ const serializeTikTokScope = (scope) => {
2258
+ if (scope === undefined || scope === null || scope === '') {
2259
+ return undefined;
2260
+ }
2261
+ if (Array.isArray(scope)) {
2262
+ return scope.filter(Boolean).join(',');
2263
+ }
2264
+ return scope;
2265
+ };
2266
+ const buildTikTokOAuthConfig = (config) => {
2267
+ var _a, _b, _c, _d;
2268
+ return ({
2269
+ appId: config.clientKey,
2270
+ clientSecret: config.clientSecret,
2271
+ authorizationBaseUrl: TIKTOK_AUTH_URL,
2272
+ accessTokenEndpoint: TIKTOK_TOKEN_URL,
2273
+ redirectUrl: config.redirectUrl,
2274
+ responseType: 'code',
2275
+ pkceEnabled: (_a = config.pkceEnabled) !== null && _a !== void 0 ? _a : true,
2276
+ scope: (_c = serializeTikTokScope((_b = config.scope) !== null && _b !== void 0 ? _b : config.scopes)) !== null && _c !== void 0 ? _c : TIKTOK_DEFAULT_SCOPE,
2277
+ clientIdParamName: 'client_key',
2278
+ clientSecretParamName: 'client_secret',
2279
+ logsEnabled: (_d = config.logsEnabled) !== null && _d !== void 0 ? _d : false,
2280
+ });
2281
+ };
2282
+ const buildTikTokLoginOptions = (options = {}) => {
2283
+ var _a;
2284
+ const scope = serializeTikTokScope((_a = options.scope) !== null && _a !== void 0 ? _a : options.scopes);
2285
+ return Object.assign(Object.assign({ providerId: TIKTOK_PROVIDER_ID }, (scope === undefined ? {} : { scope })), { state: options.state, codeVerifier: options.codeVerifier, redirectUrl: options.redirectUrl });
2286
+ };
2287
+ const isTikTokOAuthResult = (result) => result.provider === 'oauth2' && result.result.providerId === TIKTOK_PROVIDER_ID;
2288
+ const asTikTokLoginResult = (result) => ({
2289
+ provider: 'tiktok',
2290
+ result: result.result,
2291
+ });
2292
+
2183
2293
  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.";
2184
2294
  const rawSocialLogin = core.registerPlugin('SocialLogin', {
2185
2295
  web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.SocialLoginWeb()),
2186
2296
  });
2187
2297
  class SocialLoginClient {
2298
+ normalizeInitializeOptions(options) {
2299
+ var _a, _b;
2300
+ let next = options;
2301
+ if (next.linkedin) {
2302
+ const { linkedin, oauth2 } = next, rest = __rest(next, ["linkedin", "oauth2"]);
2303
+ next = 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) }) });
2304
+ }
2305
+ if (next.tiktok) {
2306
+ if (!next.tiktok.clientKey || !next.tiktok.redirectUrl) {
2307
+ throw new Error('tiktok.clientKey and tiktok.redirectUrl are required');
2308
+ }
2309
+ const { tiktok, oauth2 } = next, rest = __rest(next, ["tiktok", "oauth2"]);
2310
+ next = Object.assign(Object.assign({}, rest), { tiktok, oauth2: Object.assign(Object.assign({}, (oauth2 !== null && oauth2 !== void 0 ? oauth2 : {})), { [TIKTOK_PROVIDER_ID]: (_b = oauth2 === null || oauth2 === void 0 ? void 0 : oauth2[TIKTOK_PROVIDER_ID]) !== null && _b !== void 0 ? _b : buildTikTokOAuthConfig(tiktok) }) });
2311
+ }
2312
+ return next;
2313
+ }
2188
2314
  constructor() {
2189
2315
  this.initialize = this.initialize.bind(this);
2190
2316
  this.refresh = this.refresh.bind(this);
2191
2317
  }
2192
2318
  async initialize(options) {
2193
- await rawSocialLogin.initialize(options);
2194
- this.initializeOptions = options;
2319
+ const normalized = this.normalizeInitializeOptions(options);
2320
+ await rawSocialLogin.initialize(normalized);
2321
+ this.initializeOptions = normalized;
2195
2322
  }
2196
2323
  async login(options) {
2324
+ var _a;
2325
+ if (options.provider === 'linkedin') {
2326
+ const linkedInOptions = (_a = options.options) !== null && _a !== void 0 ? _a : {};
2327
+ const oauthOptions = buildLinkedInLoginOptions(linkedInOptions);
2328
+ if (oauthOptions.flow === 'redirect' && oauthOptions.state) {
2329
+ markLinkedInRedirectPending(oauthOptions.state);
2330
+ }
2331
+ const response = await rawSocialLogin.login({
2332
+ provider: 'oauth2',
2333
+ options: oauthOptions,
2334
+ });
2335
+ return asLinkedInLoginResult(response);
2336
+ }
2337
+ if (options.provider === 'tiktok') {
2338
+ const response = await rawSocialLogin.login({
2339
+ provider: 'oauth2',
2340
+ options: buildTikTokLoginOptions(options.options),
2341
+ });
2342
+ return asTikTokLoginResult(response);
2343
+ }
2197
2344
  return rawSocialLogin.login(options);
2198
2345
  }
2199
2346
  async logout(options) {
2347
+ if (options.provider === 'linkedin') {
2348
+ return rawSocialLogin.logout({ provider: 'oauth2', providerId: LINKEDIN_PROVIDER_ID });
2349
+ }
2350
+ if (options.provider === 'tiktok') {
2351
+ return rawSocialLogin.logout({ provider: 'oauth2', providerId: TIKTOK_PROVIDER_ID });
2352
+ }
2200
2353
  return rawSocialLogin.logout(options);
2201
2354
  }
2202
2355
  async isLoggedIn(options) {
2356
+ if (options.provider === 'linkedin') {
2357
+ return rawSocialLogin.isLoggedIn({ provider: 'oauth2', providerId: LINKEDIN_PROVIDER_ID });
2358
+ }
2359
+ if (options.provider === 'tiktok') {
2360
+ return rawSocialLogin.isLoggedIn({ provider: 'oauth2', providerId: TIKTOK_PROVIDER_ID });
2361
+ }
2203
2362
  return rawSocialLogin.isLoggedIn(options);
2204
2363
  }
2205
2364
  async getAuthorizationCode(options) {
2365
+ if (options.provider === 'linkedin') {
2366
+ return rawSocialLogin.getAuthorizationCode({ provider: 'oauth2', providerId: LINKEDIN_PROVIDER_ID });
2367
+ }
2368
+ if (options.provider === 'tiktok') {
2369
+ return rawSocialLogin.getAuthorizationCode({ provider: 'oauth2', providerId: TIKTOK_PROVIDER_ID });
2370
+ }
2206
2371
  return rawSocialLogin.getAuthorizationCode(options);
2207
2372
  }
2208
2373
  async refresh(options) {
2209
- var _a, _b;
2374
+ var _a, _b, _c;
2210
2375
  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') {
2211
2376
  console.warn(`[SocialLogin] ${GOOGLE_OFFLINE_REFRESH_MESSAGE}`);
2212
2377
  }
2378
+ if (options.provider === 'linkedin') {
2379
+ return rawSocialLogin.refresh({
2380
+ provider: 'oauth2',
2381
+ options: buildLinkedInLoginOptions((_c = options.options) !== null && _c !== void 0 ? _c : {}),
2382
+ });
2383
+ }
2384
+ if (options.provider === 'tiktok') {
2385
+ return rawSocialLogin.refresh({
2386
+ provider: 'oauth2',
2387
+ options: buildTikTokLoginOptions(options.options),
2388
+ });
2389
+ }
2213
2390
  return rawSocialLogin.refresh(options);
2214
2391
  }
2215
2392
  async refreshToken(options) {
2393
+ if (options.provider === 'linkedin') {
2394
+ return rawSocialLogin.refreshToken({
2395
+ provider: 'oauth2',
2396
+ providerId: LINKEDIN_PROVIDER_ID,
2397
+ refreshToken: options.refreshToken,
2398
+ additionalParameters: options.additionalParameters,
2399
+ });
2400
+ }
2401
+ if (options.provider === 'tiktok') {
2402
+ return rawSocialLogin.refreshToken({
2403
+ provider: 'oauth2',
2404
+ providerId: TIKTOK_PROVIDER_ID,
2405
+ refreshToken: options.refreshToken,
2406
+ additionalParameters: options.additionalParameters,
2407
+ });
2408
+ }
2216
2409
  return rawSocialLogin.refreshToken(options);
2217
2410
  }
2218
2411
  async handleRedirectCallback() {
2219
- return rawSocialLogin.handleRedirectCallback();
2412
+ const result = await rawSocialLogin.handleRedirectCallback();
2413
+ if (result && isTikTokOAuthResult(result)) {
2414
+ return asTikTokLoginResult(result);
2415
+ }
2416
+ return result;
2220
2417
  }
2221
2418
  async decodeIdToken(options) {
2222
2419
  return rawSocialLogin.decodeIdToken(options);
@@ -2449,7 +2646,7 @@ const createAuthConnectClient = (client) => ({
2449
2646
  providerSpecificCall: async (options) => client.providerSpecificCall(options),
2450
2647
  getPluginVersion: async () => client.getPluginVersion(),
2451
2648
  });
2452
- const SocialLoginAuthConnect = createAuthConnectClient(SocialLoginBase);
2649
+ const SocialLoginAuthConnect = createAuthConnectClient(SocialLogin);
2453
2650
 
2454
2651
  class AppleSocialLogin extends BaseSocialLogin {
2455
2652
  constructor() {
@@ -2834,7 +3031,7 @@ class SocialLoginWeb extends core.WebPlugin {
2834
3031
  }
2835
3032
  }
2836
3033
  async initialize(options) {
2837
- var _a, _b, _c, _d, _e;
3034
+ var _a, _b, _c, _d, _e, _f;
2838
3035
  const initPromises = [];
2839
3036
  if ((_a = options.google) === null || _a === void 0 ? void 0 : _a.webClientId) {
2840
3037
  initPromises.push(this.googleProvider.initialize(options.google.webClientId, options.google.mode, options.google.hostedDomain, options.google.redirectUrl));
@@ -2851,12 +3048,25 @@ class SocialLoginWeb extends core.WebPlugin {
2851
3048
  if ((_e = options.telegram) === null || _e === void 0 ? void 0 : _e.botId) {
2852
3049
  this.telegramProvider.initialize(options.telegram.botId, options.telegram.requestAccess, options.telegram.redirectUrl, options.telegram.origin, options.telegram.languageCode);
2853
3050
  }
2854
- if (options.oauth2 && Object.keys(options.oauth2).length > 0) {
2855
- initPromises.push(this.oauth2Provider.initializeProviders(options.oauth2));
3051
+ const oauth2Configs = Object.assign({}, ((_f = options.oauth2) !== null && _f !== void 0 ? _f : {}));
3052
+ if (options.linkedin && !oauth2Configs[LINKEDIN_PROVIDER_ID]) {
3053
+ oauth2Configs[LINKEDIN_PROVIDER_ID] = buildLinkedInOAuthConfig(options.linkedin);
3054
+ }
3055
+ if (options.tiktok) {
3056
+ if (!options.tiktok.clientKey || !options.tiktok.redirectUrl) {
3057
+ throw new Error('tiktok.clientKey and tiktok.redirectUrl are required');
3058
+ }
3059
+ if (!oauth2Configs[TIKTOK_PROVIDER_ID]) {
3060
+ oauth2Configs[TIKTOK_PROVIDER_ID] = buildTikTokOAuthConfig(options.tiktok);
3061
+ }
3062
+ }
3063
+ if (Object.keys(oauth2Configs).length > 0) {
3064
+ initPromises.push(this.oauth2Provider.initializeProviders(oauth2Configs));
2856
3065
  }
2857
3066
  await Promise.all(initPromises);
2858
3067
  }
2859
3068
  async login(options) {
3069
+ var _a;
2860
3070
  switch (options.provider) {
2861
3071
  case 'google':
2862
3072
  return this.googleProvider.login(options.options);
@@ -2868,6 +3078,19 @@ class SocialLoginWeb extends core.WebPlugin {
2868
3078
  return this.twitterProvider.login(options.options);
2869
3079
  case 'telegram':
2870
3080
  return this.telegramProvider.login(options.options);
3081
+ case 'linkedin': {
3082
+ const linkedInOptions = (_a = options.options) !== null && _a !== void 0 ? _a : {};
3083
+ const oauthOptions = buildLinkedInLoginOptions(linkedInOptions);
3084
+ if (oauthOptions.flow === 'redirect' && oauthOptions.state) {
3085
+ markLinkedInRedirectPending(oauthOptions.state);
3086
+ }
3087
+ const response = await this.oauth2Provider.login(oauthOptions);
3088
+ return asLinkedInLoginResult(response);
3089
+ }
3090
+ case 'tiktok': {
3091
+ const response = await this.oauth2Provider.login(buildTikTokLoginOptions(options.options));
3092
+ return asTikTokLoginResult(response);
3093
+ }
2871
3094
  case 'oauth2':
2872
3095
  return this.oauth2Provider.login(options.options);
2873
3096
  default:
@@ -2886,6 +3109,10 @@ class SocialLoginWeb extends core.WebPlugin {
2886
3109
  return this.twitterProvider.logout();
2887
3110
  case 'telegram':
2888
3111
  return this.telegramProvider.logout();
3112
+ case 'linkedin':
3113
+ return this.oauth2Provider.logout(LINKEDIN_PROVIDER_ID);
3114
+ case 'tiktok':
3115
+ return this.oauth2Provider.logout(TIKTOK_PROVIDER_ID);
2889
3116
  case 'oauth2':
2890
3117
  if (!options.providerId) {
2891
3118
  throw new Error('providerId is required for oauth2 logout');
@@ -2907,6 +3134,10 @@ class SocialLoginWeb extends core.WebPlugin {
2907
3134
  return this.twitterProvider.isLoggedIn();
2908
3135
  case 'telegram':
2909
3136
  return this.telegramProvider.isLoggedIn();
3137
+ case 'linkedin':
3138
+ return this.oauth2Provider.isLoggedIn(LINKEDIN_PROVIDER_ID);
3139
+ case 'tiktok':
3140
+ return this.oauth2Provider.isLoggedIn(TIKTOK_PROVIDER_ID);
2910
3141
  case 'oauth2':
2911
3142
  if (!options.providerId) {
2912
3143
  throw new Error('providerId is required for oauth2 isLoggedIn');
@@ -2926,6 +3157,10 @@ class SocialLoginWeb extends core.WebPlugin {
2926
3157
  return this.facebookProvider.getAuthorizationCode();
2927
3158
  case 'twitter':
2928
3159
  return this.twitterProvider.getAuthorizationCode();
3160
+ case 'linkedin':
3161
+ return this.oauth2Provider.getAuthorizationCode(LINKEDIN_PROVIDER_ID);
3162
+ case 'tiktok':
3163
+ return this.oauth2Provider.getAuthorizationCode(TIKTOK_PROVIDER_ID);
2929
3164
  case 'oauth2':
2930
3165
  if (!options.providerId) {
2931
3166
  throw new Error('providerId is required for oauth2 getAuthorizationCode');
@@ -2947,6 +3182,10 @@ class SocialLoginWeb extends core.WebPlugin {
2947
3182
  return this.twitterProvider.refresh();
2948
3183
  case 'telegram':
2949
3184
  return this.telegramProvider.refresh();
3185
+ case 'linkedin':
3186
+ return this.oauth2Provider.refresh(LINKEDIN_PROVIDER_ID);
3187
+ case 'tiktok':
3188
+ return this.oauth2Provider.refresh(TIKTOK_PROVIDER_ID);
2950
3189
  case 'oauth2': {
2951
3190
  const oauth2Options = options.options;
2952
3191
  if (!(oauth2Options === null || oauth2Options === void 0 ? void 0 : oauth2Options.providerId)) {
@@ -2976,19 +3215,34 @@ class SocialLoginWeb extends core.WebPlugin {
2976
3215
  }
2977
3216
  }
2978
3217
  async refreshToken(options) {
3218
+ if (options.provider === 'linkedin') {
3219
+ return this.oauth2Provider.refreshToken(LINKEDIN_PROVIDER_ID, options.refreshToken, options.additionalParameters);
3220
+ }
3221
+ if (options.provider === 'tiktok') {
3222
+ return this.oauth2Provider.refreshToken(TIKTOK_PROVIDER_ID, options.refreshToken, options.additionalParameters);
3223
+ }
2979
3224
  if (options.provider !== 'oauth2') {
2980
- throw new Error('refreshToken is only implemented for oauth2 on web');
3225
+ throw new Error('refreshToken is only implemented for oauth2, linkedin, and tiktok on web');
2981
3226
  }
2982
3227
  return this.oauth2Provider.refreshToken(options.providerId, options.refreshToken, options.additionalParameters);
2983
3228
  }
2984
3229
  async handleRedirectCallback() {
3230
+ var _a;
2985
3231
  const parsed = await this.parseRedirectResult();
3232
+ const callbackState = (_a = parsed.state) !== null && _a !== void 0 ? _a : new URL(window.location.href).searchParams.get('state');
3233
+ const pendingLinkedInRedirect = consumeLinkedInRedirectPending(callbackState);
2986
3234
  const result = parsed.result;
2987
3235
  if (!result)
2988
3236
  return null;
2989
3237
  if ('error' in result) {
2990
3238
  throw inferUserCancelledError(result.error);
2991
3239
  }
3240
+ if (pendingLinkedInRedirect && isLinkedInOAuthResult(result)) {
3241
+ return asLinkedInLoginResult(result);
3242
+ }
3243
+ if (isTikTokOAuthResult(result)) {
3244
+ return asTikTokLoginResult(result);
3245
+ }
2992
3246
  return result;
2993
3247
  }
2994
3248
  async decodeIdToken(options) {
@@ -3062,8 +3316,8 @@ class SocialLoginWeb extends core.WebPlugin {
3062
3316
  SocialLoginWeb.OAUTH_STATE_KEY = OAUTH_STATE_KEY;
3063
3317
 
3064
3318
  var web = /*#__PURE__*/Object.freeze({
3065
- __proto__: null,
3066
- SocialLoginWeb: SocialLoginWeb
3319
+ __proto__: null,
3320
+ SocialLoginWeb: SocialLoginWeb
3067
3321
  });
3068
3322
 
3069
3323
  exports.SocialLogin = SocialLogin;