@capgo/capacitor-social-login 8.5.4 → 8.5.6

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/dist/plugin.js CHANGED
@@ -713,6 +713,13 @@ var capacitorCapacitorUpdater = (function (exports, core) {
713
713
  }
714
714
  }
715
715
 
716
+ const normalizeOAuthParamName = (value, fallback) => {
717
+ if (typeof value !== 'string') {
718
+ return fallback;
719
+ }
720
+ const trimmed = value.trim();
721
+ return trimmed.length > 0 ? trimmed : fallback;
722
+ };
716
723
  /**
717
724
  * OAuth2 Social Login Manager
718
725
  * Supports multiple OAuth2 provider configurations
@@ -755,6 +762,8 @@ var capacitorCapacitorUpdater = (function (exports, core) {
755
762
  return {
756
763
  appId,
757
764
  clientSecret: config.clientSecret,
765
+ clientIdParamName: normalizeOAuthParamName(config.clientIdParamName, 'client_id'),
766
+ clientSecretParamName: normalizeOAuthParamName(config.clientSecretParamName, 'client_secret'),
758
767
  issuerUrl: config.issuerUrl,
759
768
  authorizationBaseUrl,
760
769
  accessTokenEndpoint,
@@ -834,11 +843,17 @@ var capacitorCapacitorUpdater = (function (exports, core) {
834
843
  this.persistConfiguration(providerId, internalConfig);
835
844
  }
836
845
  }
846
+ normalizeStoredConfig(config) {
847
+ return Object.assign(Object.assign({}, config), { clientIdParamName: normalizeOAuthParamName(config.clientIdParamName, 'client_id'), clientSecretParamName: normalizeOAuthParamName(config.clientSecretParamName, 'client_secret') });
848
+ }
837
849
  getProvider(providerId) {
838
850
  const config = this.providers.get(providerId);
839
851
  if (!config) {
840
852
  throw new Error(`OAuth2 provider '${providerId}' not configured. Call initialize() first.`);
841
853
  }
854
+ // Mutate in place so later discovery writes are visible to the same config object.
855
+ config.clientIdParamName = normalizeOAuthParamName(config.clientIdParamName, 'client_id');
856
+ config.clientSecretParamName = normalizeOAuthParamName(config.clientSecretParamName, 'client_secret');
842
857
  return config;
843
858
  }
844
859
  getTokensKey(providerId) {
@@ -865,7 +880,7 @@ var capacitorCapacitorUpdater = (function (exports, core) {
865
880
  try {
866
881
  const raw = localStorage.getItem(key);
867
882
  if (raw) {
868
- const config = JSON.parse(raw);
883
+ const config = this.normalizeStoredConfig(JSON.parse(raw));
869
884
  this.providers.set(providerId, config);
870
885
  }
871
886
  }
@@ -887,7 +902,7 @@ var capacitorCapacitorUpdater = (function (exports, core) {
887
902
  // Build authorization URL
888
903
  const params = new URLSearchParams({
889
904
  response_type: config.responseType,
890
- client_id: config.appId,
905
+ [config.clientIdParamName]: config.appId,
891
906
  redirect_uri: redirectUri,
892
907
  state,
893
908
  });
@@ -1245,7 +1260,7 @@ var capacitorCapacitorUpdater = (function (exports, core) {
1245
1260
  }
1246
1261
  const params = new URLSearchParams({
1247
1262
  grant_type: 'authorization_code',
1248
- client_id: config.appId,
1263
+ [config.clientIdParamName]: config.appId,
1249
1264
  code,
1250
1265
  redirect_uri: pending.redirectUri,
1251
1266
  });
@@ -1253,7 +1268,7 @@ var capacitorCapacitorUpdater = (function (exports, core) {
1253
1268
  params.set('code_verifier', pending.codeVerifier);
1254
1269
  }
1255
1270
  if (config.clientSecret) {
1256
- params.set('client_secret', config.clientSecret);
1271
+ params.set(config.clientSecretParamName, config.clientSecret);
1257
1272
  }
1258
1273
  if (config.additionalTokenParameters) {
1259
1274
  for (const [k, v] of Object.entries(config.additionalTokenParameters)) {
@@ -1284,10 +1299,10 @@ var capacitorCapacitorUpdater = (function (exports, core) {
1284
1299
  const params = new URLSearchParams({
1285
1300
  grant_type: 'refresh_token',
1286
1301
  refresh_token: refreshToken,
1287
- client_id: config.appId,
1302
+ [config.clientIdParamName]: config.appId,
1288
1303
  });
1289
1304
  if (config.clientSecret) {
1290
- params.set('client_secret', config.clientSecret);
1305
+ params.set(config.clientSecretParamName, config.clientSecret);
1291
1306
  }
1292
1307
  if (config.additionalTokenParameters) {
1293
1308
  for (const [k, v] of Object.entries(config.additionalTokenParameters)) {
@@ -2233,18 +2248,67 @@ var capacitorCapacitorUpdater = (function (exports, core) {
2233
2248
  }
2234
2249
  };
2235
2250
 
2251
+ const TIKTOK_PROVIDER_ID = 'tiktok';
2252
+ const TIKTOK_AUTH_URL = 'https://www.tiktok.com/v2/auth/authorize/';
2253
+ const TIKTOK_TOKEN_URL = 'https://open.tiktokapis.com/v2/oauth/token/';
2254
+ const TIKTOK_DEFAULT_SCOPE = 'user.info.basic';
2255
+ // TikTok Login Kit expects comma-separated scopes, not space-separated.
2256
+ const serializeTikTokScope = (scope) => {
2257
+ if (scope === undefined || scope === null || scope === '') {
2258
+ return undefined;
2259
+ }
2260
+ if (Array.isArray(scope)) {
2261
+ return scope.filter(Boolean).join(',');
2262
+ }
2263
+ return scope;
2264
+ };
2265
+ const buildTikTokOAuthConfig = (config) => {
2266
+ var _a, _b, _c, _d;
2267
+ return ({
2268
+ appId: config.clientKey,
2269
+ clientSecret: config.clientSecret,
2270
+ authorizationBaseUrl: TIKTOK_AUTH_URL,
2271
+ accessTokenEndpoint: TIKTOK_TOKEN_URL,
2272
+ redirectUrl: config.redirectUrl,
2273
+ responseType: 'code',
2274
+ pkceEnabled: (_a = config.pkceEnabled) !== null && _a !== void 0 ? _a : true,
2275
+ scope: (_c = serializeTikTokScope((_b = config.scope) !== null && _b !== void 0 ? _b : config.scopes)) !== null && _c !== void 0 ? _c : TIKTOK_DEFAULT_SCOPE,
2276
+ clientIdParamName: 'client_key',
2277
+ clientSecretParamName: 'client_secret',
2278
+ logsEnabled: (_d = config.logsEnabled) !== null && _d !== void 0 ? _d : false,
2279
+ });
2280
+ };
2281
+ const buildTikTokLoginOptions = (options = {}) => {
2282
+ var _a;
2283
+ const scope = serializeTikTokScope((_a = options.scope) !== null && _a !== void 0 ? _a : options.scopes);
2284
+ return Object.assign(Object.assign({ providerId: TIKTOK_PROVIDER_ID }, (scope === undefined ? {} : { scope })), { state: options.state, codeVerifier: options.codeVerifier, redirectUrl: options.redirectUrl });
2285
+ };
2286
+ const isTikTokOAuthResult = (result) => result.provider === 'oauth2' && result.result.providerId === TIKTOK_PROVIDER_ID;
2287
+ const asTikTokLoginResult = (result) => ({
2288
+ provider: 'tiktok',
2289
+ result: result.result,
2290
+ });
2291
+
2236
2292
  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.";
2237
2293
  const rawSocialLogin = core.registerPlugin('SocialLogin', {
2238
2294
  web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.SocialLoginWeb()),
2239
2295
  });
2240
2296
  class SocialLoginClient {
2241
2297
  normalizeInitializeOptions(options) {
2242
- var _a;
2243
- if (!options.linkedin) {
2244
- return options;
2298
+ var _a, _b;
2299
+ let next = options;
2300
+ if (next.linkedin) {
2301
+ const { linkedin, oauth2 } = next, rest = __rest(next, ["linkedin", "oauth2"]);
2302
+ 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) }) });
2303
+ }
2304
+ if (next.tiktok) {
2305
+ if (!next.tiktok.clientKey || !next.tiktok.redirectUrl) {
2306
+ throw new Error('tiktok.clientKey and tiktok.redirectUrl are required');
2307
+ }
2308
+ const { tiktok, oauth2 } = next, rest = __rest(next, ["tiktok", "oauth2"]);
2309
+ 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) }) });
2245
2310
  }
2246
- const { linkedin, oauth2 } = options, rest = __rest(options, ["linkedin", "oauth2"]);
2247
- 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) }) });
2311
+ return next;
2248
2312
  }
2249
2313
  constructor() {
2250
2314
  this.initialize = this.initialize.bind(this);
@@ -2269,24 +2333,40 @@ var capacitorCapacitorUpdater = (function (exports, core) {
2269
2333
  });
2270
2334
  return asLinkedInLoginResult(response);
2271
2335
  }
2336
+ if (options.provider === 'tiktok') {
2337
+ const response = await rawSocialLogin.login({
2338
+ provider: 'oauth2',
2339
+ options: buildTikTokLoginOptions(options.options),
2340
+ });
2341
+ return asTikTokLoginResult(response);
2342
+ }
2272
2343
  return rawSocialLogin.login(options);
2273
2344
  }
2274
2345
  async logout(options) {
2275
2346
  if (options.provider === 'linkedin') {
2276
2347
  return rawSocialLogin.logout({ provider: 'oauth2', providerId: LINKEDIN_PROVIDER_ID });
2277
2348
  }
2349
+ if (options.provider === 'tiktok') {
2350
+ return rawSocialLogin.logout({ provider: 'oauth2', providerId: TIKTOK_PROVIDER_ID });
2351
+ }
2278
2352
  return rawSocialLogin.logout(options);
2279
2353
  }
2280
2354
  async isLoggedIn(options) {
2281
2355
  if (options.provider === 'linkedin') {
2282
2356
  return rawSocialLogin.isLoggedIn({ provider: 'oauth2', providerId: LINKEDIN_PROVIDER_ID });
2283
2357
  }
2358
+ if (options.provider === 'tiktok') {
2359
+ return rawSocialLogin.isLoggedIn({ provider: 'oauth2', providerId: TIKTOK_PROVIDER_ID });
2360
+ }
2284
2361
  return rawSocialLogin.isLoggedIn(options);
2285
2362
  }
2286
2363
  async getAuthorizationCode(options) {
2287
2364
  if (options.provider === 'linkedin') {
2288
2365
  return rawSocialLogin.getAuthorizationCode({ provider: 'oauth2', providerId: LINKEDIN_PROVIDER_ID });
2289
2366
  }
2367
+ if (options.provider === 'tiktok') {
2368
+ return rawSocialLogin.getAuthorizationCode({ provider: 'oauth2', providerId: TIKTOK_PROVIDER_ID });
2369
+ }
2290
2370
  return rawSocialLogin.getAuthorizationCode(options);
2291
2371
  }
2292
2372
  async refresh(options) {
@@ -2300,6 +2380,12 @@ var capacitorCapacitorUpdater = (function (exports, core) {
2300
2380
  options: buildLinkedInLoginOptions((_c = options.options) !== null && _c !== void 0 ? _c : {}),
2301
2381
  });
2302
2382
  }
2383
+ if (options.provider === 'tiktok') {
2384
+ return rawSocialLogin.refresh({
2385
+ provider: 'oauth2',
2386
+ options: buildTikTokLoginOptions(options.options),
2387
+ });
2388
+ }
2303
2389
  return rawSocialLogin.refresh(options);
2304
2390
  }
2305
2391
  async refreshToken(options) {
@@ -2311,10 +2397,22 @@ var capacitorCapacitorUpdater = (function (exports, core) {
2311
2397
  additionalParameters: options.additionalParameters,
2312
2398
  });
2313
2399
  }
2400
+ if (options.provider === 'tiktok') {
2401
+ return rawSocialLogin.refreshToken({
2402
+ provider: 'oauth2',
2403
+ providerId: TIKTOK_PROVIDER_ID,
2404
+ refreshToken: options.refreshToken,
2405
+ additionalParameters: options.additionalParameters,
2406
+ });
2407
+ }
2314
2408
  return rawSocialLogin.refreshToken(options);
2315
2409
  }
2316
2410
  async handleRedirectCallback() {
2317
- return rawSocialLogin.handleRedirectCallback();
2411
+ const result = await rawSocialLogin.handleRedirectCallback();
2412
+ if (result && isTikTokOAuthResult(result)) {
2413
+ return asTikTokLoginResult(result);
2414
+ }
2415
+ return result;
2318
2416
  }
2319
2417
  async decodeIdToken(options) {
2320
2418
  return rawSocialLogin.decodeIdToken(options);
@@ -2953,6 +3051,14 @@ var capacitorCapacitorUpdater = (function (exports, core) {
2953
3051
  if (options.linkedin && !oauth2Configs[LINKEDIN_PROVIDER_ID]) {
2954
3052
  oauth2Configs[LINKEDIN_PROVIDER_ID] = buildLinkedInOAuthConfig(options.linkedin);
2955
3053
  }
3054
+ if (options.tiktok) {
3055
+ if (!options.tiktok.clientKey || !options.tiktok.redirectUrl) {
3056
+ throw new Error('tiktok.clientKey and tiktok.redirectUrl are required');
3057
+ }
3058
+ if (!oauth2Configs[TIKTOK_PROVIDER_ID]) {
3059
+ oauth2Configs[TIKTOK_PROVIDER_ID] = buildTikTokOAuthConfig(options.tiktok);
3060
+ }
3061
+ }
2956
3062
  if (Object.keys(oauth2Configs).length > 0) {
2957
3063
  initPromises.push(this.oauth2Provider.initializeProviders(oauth2Configs));
2958
3064
  }
@@ -2980,6 +3086,10 @@ var capacitorCapacitorUpdater = (function (exports, core) {
2980
3086
  const response = await this.oauth2Provider.login(oauthOptions);
2981
3087
  return asLinkedInLoginResult(response);
2982
3088
  }
3089
+ case 'tiktok': {
3090
+ const response = await this.oauth2Provider.login(buildTikTokLoginOptions(options.options));
3091
+ return asTikTokLoginResult(response);
3092
+ }
2983
3093
  case 'oauth2':
2984
3094
  return this.oauth2Provider.login(options.options);
2985
3095
  default:
@@ -3000,6 +3110,8 @@ var capacitorCapacitorUpdater = (function (exports, core) {
3000
3110
  return this.telegramProvider.logout();
3001
3111
  case 'linkedin':
3002
3112
  return this.oauth2Provider.logout(LINKEDIN_PROVIDER_ID);
3113
+ case 'tiktok':
3114
+ return this.oauth2Provider.logout(TIKTOK_PROVIDER_ID);
3003
3115
  case 'oauth2':
3004
3116
  if (!options.providerId) {
3005
3117
  throw new Error('providerId is required for oauth2 logout');
@@ -3023,6 +3135,8 @@ var capacitorCapacitorUpdater = (function (exports, core) {
3023
3135
  return this.telegramProvider.isLoggedIn();
3024
3136
  case 'linkedin':
3025
3137
  return this.oauth2Provider.isLoggedIn(LINKEDIN_PROVIDER_ID);
3138
+ case 'tiktok':
3139
+ return this.oauth2Provider.isLoggedIn(TIKTOK_PROVIDER_ID);
3026
3140
  case 'oauth2':
3027
3141
  if (!options.providerId) {
3028
3142
  throw new Error('providerId is required for oauth2 isLoggedIn');
@@ -3044,6 +3158,8 @@ var capacitorCapacitorUpdater = (function (exports, core) {
3044
3158
  return this.twitterProvider.getAuthorizationCode();
3045
3159
  case 'linkedin':
3046
3160
  return this.oauth2Provider.getAuthorizationCode(LINKEDIN_PROVIDER_ID);
3161
+ case 'tiktok':
3162
+ return this.oauth2Provider.getAuthorizationCode(TIKTOK_PROVIDER_ID);
3047
3163
  case 'oauth2':
3048
3164
  if (!options.providerId) {
3049
3165
  throw new Error('providerId is required for oauth2 getAuthorizationCode');
@@ -3067,6 +3183,8 @@ var capacitorCapacitorUpdater = (function (exports, core) {
3067
3183
  return this.telegramProvider.refresh();
3068
3184
  case 'linkedin':
3069
3185
  return this.oauth2Provider.refresh(LINKEDIN_PROVIDER_ID);
3186
+ case 'tiktok':
3187
+ return this.oauth2Provider.refresh(TIKTOK_PROVIDER_ID);
3070
3188
  case 'oauth2': {
3071
3189
  const oauth2Options = options.options;
3072
3190
  if (!(oauth2Options === null || oauth2Options === void 0 ? void 0 : oauth2Options.providerId)) {
@@ -3099,8 +3217,11 @@ var capacitorCapacitorUpdater = (function (exports, core) {
3099
3217
  if (options.provider === 'linkedin') {
3100
3218
  return this.oauth2Provider.refreshToken(LINKEDIN_PROVIDER_ID, options.refreshToken, options.additionalParameters);
3101
3219
  }
3220
+ if (options.provider === 'tiktok') {
3221
+ return this.oauth2Provider.refreshToken(TIKTOK_PROVIDER_ID, options.refreshToken, options.additionalParameters);
3222
+ }
3102
3223
  if (options.provider !== 'oauth2') {
3103
- throw new Error('refreshToken is only implemented for oauth2 and linkedin on web');
3224
+ throw new Error('refreshToken is only implemented for oauth2, linkedin, and tiktok on web');
3104
3225
  }
3105
3226
  return this.oauth2Provider.refreshToken(options.providerId, options.refreshToken, options.additionalParameters);
3106
3227
  }
@@ -3118,6 +3239,9 @@ var capacitorCapacitorUpdater = (function (exports, core) {
3118
3239
  if (pendingLinkedInRedirect && isLinkedInOAuthResult(result)) {
3119
3240
  return asLinkedInLoginResult(result);
3120
3241
  }
3242
+ if (isTikTokOAuthResult(result)) {
3243
+ return asTikTokLoginResult(result);
3244
+ }
3121
3245
  return result;
3122
3246
  }
3123
3247
  async decodeIdToken(options) {