@capgo/capacitor-social-login 8.5.1 → 8.5.3

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 (30) hide show
  1. package/README.md +78 -18
  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 +150 -8
  7. package/dist/esm/definitions.d.ts +87 -3
  8. package/dist/esm/definitions.js.map +1 -1
  9. package/dist/esm/facebook-provider.d.ts +3 -1
  10. package/dist/esm/facebook-provider.js +33 -0
  11. package/dist/esm/facebook-provider.js.map +1 -1
  12. package/dist/esm/oauth-popup-bridge.js +17 -7
  13. package/dist/esm/oauth-popup-bridge.js.map +1 -1
  14. package/dist/esm/oauth-popup-redirect.js +5 -0
  15. package/dist/esm/oauth-popup-redirect.js.map +1 -1
  16. package/dist/esm/social-login.d.ts +1 -1
  17. package/dist/esm/social-login.js.map +1 -1
  18. package/dist/esm/telegram-provider.d.ts +37 -0
  19. package/dist/esm/telegram-provider.js +292 -0
  20. package/dist/esm/telegram-provider.js.map +1 -0
  21. package/dist/esm/web.d.ts +2 -1
  22. package/dist/esm/web.js +23 -3
  23. package/dist/esm/web.js.map +1 -1
  24. package/dist/plugin.cjs.js +364 -10
  25. package/dist/plugin.cjs.js.map +1 -1
  26. package/dist/plugin.js +364 -10
  27. package/dist/plugin.js.map +1 -1
  28. package/ios/Sources/SocialLoginPlugin/SocialLoginPlugin.swift +67 -1
  29. package/ios/Sources/SocialLoginPlugin/TelegramProvider.swift +260 -0
  30. package/package.json +1 -1
@@ -20,6 +20,7 @@ public class DependencyAvailabilityChecker {
20
20
  private static Boolean facebookDependenciesAvailable = null;
21
21
  private static Boolean appleDependenciesAvailable = null;
22
22
  private static Boolean twitterDependenciesAvailable = null;
23
+ private static Boolean telegramDependenciesAvailable = null;
23
24
 
24
25
  /**
25
26
  * Set the plugin instance for config access
@@ -66,7 +67,7 @@ public class DependencyAvailabilityChecker {
66
67
 
67
68
  /**
68
69
  * Check if a provider's dependencies are available.
69
- * @param providerName Provider name: "google", "facebook", "apple", or "twitter"
70
+ * @param providerName Provider name: "google", "facebook", "apple", "twitter", or "telegram"
70
71
  * @return true if dependencies are available, false otherwise
71
72
  */
72
73
  public static boolean isProviderAvailable(String providerName) {
@@ -83,6 +84,8 @@ public class DependencyAvailabilityChecker {
83
84
  return isAppleAvailable();
84
85
  case "twitter":
85
86
  return isTwitterAvailable();
87
+ case "telegram":
88
+ return isTelegramAvailable();
86
89
  default:
87
90
  Log.w(LOG_TAG, "Unknown provider: " + providerName);
88
91
  return false;
@@ -260,6 +263,22 @@ public class DependencyAvailabilityChecker {
260
263
  return allAvailable;
261
264
  }
262
265
 
266
+ /**
267
+ * Telegram Login uses the system WebView (OAuth2LoginActivity); allow config to disable it.
268
+ */
269
+ private static boolean isTelegramAvailable() {
270
+ if (telegramDependenciesAvailable != null) {
271
+ return telegramDependenciesAvailable;
272
+ }
273
+ if (!isProviderEnabledInConfig("telegram")) {
274
+ telegramDependenciesAvailable = false;
275
+ Log.d(LOG_TAG, "Telegram provider is disabled via config");
276
+ return false;
277
+ }
278
+ telegramDependenciesAvailable = true;
279
+ return true;
280
+ }
281
+
263
282
  /**
264
283
  * Check if a specific class is available using reflection.
265
284
  */
@@ -283,5 +302,6 @@ public class DependencyAvailabilityChecker {
283
302
  facebookDependenciesAvailable = null;
284
303
  appleDependenciesAvailable = null;
285
304
  twitterDependenciesAvailable = null;
305
+ telegramDependenciesAvailable = null;
286
306
  }
287
307
  }
package/dist/docs.json CHANGED
@@ -30,12 +30,12 @@
30
30
  },
31
31
  {
32
32
  "name": "login",
33
- "signature": "<T extends \"apple\" | \"google\" | \"facebook\" | \"twitter\" | \"oauth2\">(options: Extract<LoginOptions, { provider: T; }>) => Promise<{ provider: T; result: ProviderResponseMap[T]; }>",
33
+ "signature": "<T extends \"apple\" | \"google\" | \"facebook\" | \"twitter\" | \"oauth2\" | \"telegram\">(options: Extract<LoginOptions, { provider: T; }>) => Promise<{ provider: T; result: ProviderResponseMap[T]; }>",
34
34
  "parameters": [
35
35
  {
36
36
  "name": "options",
37
37
  "docs": "",
38
- "type": "Extract<{ provider: 'facebook'; options: FacebookLoginOptions; }, { provider: T; }> | Extract<{ provider: 'google'; options: GoogleLoginOptions; }, { provider: T; }> | Extract<{ provider: 'apple'; options: AppleProviderOptions; }, { provider: T; }> | Extract<{ provider: 'twitter'; options: TwitterLoginOptions; }, { provider: T; }> | Extract<{ provider: 'oauth2'; options: OAuth2LoginOptions; }, { provider: T; }>"
38
+ "type": "Extract<{ provider: 'facebook'; options: FacebookLoginOptions; }, { provider: T; }> | Extract<{ provider: 'google'; options: GoogleLoginOptions; }, { provider: T; }> | Extract<{ provider: 'apple'; options: AppleProviderOptions; }, { provider: T; }> | Extract<{ provider: 'twitter'; options: TwitterLoginOptions; }, { provider: T; }> | Extract<{ provider: 'telegram'; options: TelegramLoginOptions; }, { provider: T; }> | Extract<{ provider: 'oauth2'; options: OAuth2LoginOptions; }, { provider: T; }>"
39
39
  }
40
40
  ],
41
41
  "returns": "Promise<{ provider: T; result: ProviderResponseMap[T]; }>",
@@ -56,12 +56,12 @@
56
56
  },
57
57
  {
58
58
  "name": "logout",
59
- "signature": "(options: { provider: 'apple' | 'google' | 'facebook' | 'twitter' | 'oauth2'; providerId?: string; }) => Promise<void>",
59
+ "signature": "(options: { provider: 'apple' | 'google' | 'facebook' | 'twitter' | 'telegram' | 'oauth2'; providerId?: string; }) => Promise<void>",
60
60
  "parameters": [
61
61
  {
62
62
  "name": "options",
63
63
  "docs": "",
64
- "type": "{ provider: 'apple' | 'google' | 'facebook' | 'twitter' | 'oauth2'; providerId?: string | undefined; }"
64
+ "type": "{ provider: 'apple' | 'google' | 'facebook' | 'twitter' | 'oauth2' | 'telegram'; providerId?: string | undefined; }"
65
65
  }
66
66
  ],
67
67
  "returns": "Promise<void>",
@@ -120,7 +120,7 @@
120
120
  "tags": [
121
121
  {
122
122
  "name": "description",
123
- "text": "Get the authorization code for server-side authentication\n\n**Google Offline Mode Limitation:**\nThis method is NOT supported when Google is initialized with `mode: 'offline'`.\nIt will reject with error: \"getAuthorizationCode is not implemented when using offline mode\"\n\nIn offline mode, the authorization code (serverAuthCode) is already returned by the `login()` method."
123
+ "text": "Get the authorization code for server-side authentication\n\n**Google Offline Mode Limitation:**\nThis method is NOT supported when Google is initialized with `mode: 'offline'`.\nIt will reject with error: \"getAuthorizationCode is not implemented when using offline mode\"\n\nIn offline mode, the authorization code (serverAuthCode) is already returned by the `login()` method.\n\nTelegram login does not produce an authorization code; use the `hash` from `login()` and verify it on your backend."
124
124
  },
125
125
  {
126
126
  "name": "throws",
@@ -369,6 +369,13 @@
369
369
  ],
370
370
  "type": "Record<string, OAuth2ProviderConfig>"
371
371
  },
372
+ {
373
+ "name": "telegram",
374
+ "tags": [],
375
+ "docs": "Telegram Login Widget configuration.\nUses Telegram's OAuth widget (`oauth.telegram.org`), not standard OAuth2.",
376
+ "complexTypes": [],
377
+ "type": "{ botId: string; redirectUrl?: string | undefined; origin?: string | undefined; requestAccess?: 'read' | 'write' | undefined; languageCode?: string | undefined; } | undefined"
378
+ },
372
379
  {
373
380
  "name": "twitter",
374
381
  "tags": [],
@@ -1072,6 +1079,89 @@
1072
1079
  }
1073
1080
  ]
1074
1081
  },
1082
+ {
1083
+ "name": "TelegramLoginResponse",
1084
+ "slug": "telegramloginresponse",
1085
+ "docs": "",
1086
+ "tags": [],
1087
+ "methods": [],
1088
+ "properties": [
1089
+ {
1090
+ "name": "profile",
1091
+ "tags": [],
1092
+ "docs": "",
1093
+ "complexTypes": [
1094
+ "TelegramProfile"
1095
+ ],
1096
+ "type": "TelegramProfile"
1097
+ },
1098
+ {
1099
+ "name": "authDate",
1100
+ "tags": [],
1101
+ "docs": "Unix timestamp (seconds) when the user authorized the login.",
1102
+ "complexTypes": [],
1103
+ "type": "number"
1104
+ },
1105
+ {
1106
+ "name": "hash",
1107
+ "tags": [],
1108
+ "docs": "Telegram-provided hash for server-side verification.",
1109
+ "complexTypes": [],
1110
+ "type": "string"
1111
+ },
1112
+ {
1113
+ "name": "requestAccess",
1114
+ "tags": [],
1115
+ "docs": "Requested access level that was used for this login.",
1116
+ "complexTypes": [],
1117
+ "type": "'read' | 'write'"
1118
+ }
1119
+ ]
1120
+ },
1121
+ {
1122
+ "name": "TelegramProfile",
1123
+ "slug": "telegramprofile",
1124
+ "docs": "",
1125
+ "tags": [],
1126
+ "methods": [],
1127
+ "properties": [
1128
+ {
1129
+ "name": "id",
1130
+ "tags": [],
1131
+ "docs": "",
1132
+ "complexTypes": [],
1133
+ "type": "string"
1134
+ },
1135
+ {
1136
+ "name": "firstName",
1137
+ "tags": [],
1138
+ "docs": "",
1139
+ "complexTypes": [],
1140
+ "type": "string"
1141
+ },
1142
+ {
1143
+ "name": "lastName",
1144
+ "tags": [],
1145
+ "docs": "",
1146
+ "complexTypes": [],
1147
+ "type": "string | null | undefined"
1148
+ },
1149
+ {
1150
+ "name": "username",
1151
+ "tags": [],
1152
+ "docs": "",
1153
+ "complexTypes": [],
1154
+ "type": "string | null | undefined"
1155
+ },
1156
+ {
1157
+ "name": "photoUrl",
1158
+ "tags": [],
1159
+ "docs": "",
1160
+ "complexTypes": [],
1161
+ "type": "string | null | undefined"
1162
+ }
1163
+ ]
1164
+ },
1075
1165
  {
1076
1166
  "name": "OAuth2LoginResponse",
1077
1167
  "slug": "oauth2loginresponse",
@@ -1473,6 +1563,41 @@
1473
1563
  }
1474
1564
  ]
1475
1565
  },
1566
+ {
1567
+ "name": "TelegramLoginOptions",
1568
+ "slug": "telegramloginoptions",
1569
+ "docs": "",
1570
+ "tags": [],
1571
+ "methods": [],
1572
+ "properties": [
1573
+ {
1574
+ "name": "redirectUrl",
1575
+ "tags": [],
1576
+ "docs": "Override the redirect URL for this login attempt.\nDefaults to the redirect configured during initialize().\nRequired on iOS/Android when initialize() did not set `redirectUrl`.",
1577
+ "complexTypes": [],
1578
+ "type": "string | undefined"
1579
+ },
1580
+ {
1581
+ "name": "state",
1582
+ "tags": [],
1583
+ "docs": "Optional state parameter for CSRF protection.\nIf omitted, a secure random value is generated automatically.",
1584
+ "complexTypes": [],
1585
+ "type": "string | undefined"
1586
+ },
1587
+ {
1588
+ "name": "requestAccess",
1589
+ "tags": [
1590
+ {
1591
+ "text": "'write'",
1592
+ "name": "default"
1593
+ }
1594
+ ],
1595
+ "docs": "Override requested access level for this login.\nDefaults to the value configured during initialize().",
1596
+ "complexTypes": [],
1597
+ "type": "'read' | 'write' | undefined"
1598
+ }
1599
+ ]
1600
+ },
1476
1601
  {
1477
1602
  "name": "OAuth2LoginOptions",
1478
1603
  "slug": "oauth2loginoptions",
@@ -1581,7 +1706,7 @@
1581
1706
  ],
1582
1707
  "docs": "Provider",
1583
1708
  "complexTypes": [],
1584
- "type": "'apple' | 'google' | 'facebook' | 'twitter' | 'oauth2'"
1709
+ "type": "'apple' | 'google' | 'facebook' | 'twitter' | 'oauth2' | 'telegram'"
1585
1710
  },
1586
1711
  {
1587
1712
  "name": "providerId",
@@ -1753,12 +1878,16 @@
1753
1878
  {
1754
1879
  "name": "fields",
1755
1880
  "tags": [
1881
+ {
1882
+ "text": "['id', 'name', 'email', 'picture']",
1883
+ "name": "default"
1884
+ },
1756
1885
  {
1757
1886
  "text": "[\"id\", \"name\", \"email\", \"picture\"]",
1758
1887
  "name": "example"
1759
1888
  }
1760
1889
  ],
1761
- "docs": "Fields to retrieve from Facebook profile",
1890
+ "docs": "Fields to retrieve from Facebook profile.",
1762
1891
  "complexTypes": [],
1763
1892
  "type": "string[] | undefined"
1764
1893
  }
@@ -1886,12 +2015,13 @@
1886
2015
  "docs": "",
1887
2016
  "types": [
1888
2017
  {
1889
- "text": "{\n facebook: FacebookLoginResponse;\n google: GoogleLoginResponse;\n apple: AppleProviderResponse;\n twitter: TwitterLoginResponse;\n oauth2: OAuth2LoginResponse;\n}",
2018
+ "text": "{\n facebook: FacebookLoginResponse;\n google: GoogleLoginResponse;\n apple: AppleProviderResponse;\n twitter: TwitterLoginResponse;\n telegram: TelegramLoginResponse;\n oauth2: OAuth2LoginResponse;\n}",
1890
2019
  "complexTypes": [
1891
2020
  "FacebookLoginResponse",
1892
2021
  "GoogleLoginResponse",
1893
2022
  "AppleProviderResponse",
1894
2023
  "TwitterLoginResponse",
2024
+ "TelegramLoginResponse",
1895
2025
  "OAuth2LoginResponse"
1896
2026
  ]
1897
2027
  }
@@ -1945,6 +2075,12 @@
1945
2075
  "TwitterLoginOptions"
1946
2076
  ]
1947
2077
  },
2078
+ {
2079
+ "text": "{\n provider: 'telegram';\n options: TelegramLoginOptions;\n }",
2080
+ "complexTypes": [
2081
+ "TelegramLoginOptions"
2082
+ ]
2083
+ },
1948
2084
  {
1949
2085
  "text": "{\n provider: 'oauth2';\n options: OAuth2LoginOptions;\n }",
1950
2086
  "complexTypes": [
@@ -1996,6 +2132,12 @@
1996
2132
  "TwitterLoginResponse"
1997
2133
  ]
1998
2134
  },
2135
+ {
2136
+ "text": "{\n provider: 'telegram';\n result: TelegramLoginResponse;\n }",
2137
+ "complexTypes": [
2138
+ "TelegramLoginResponse"
2139
+ ]
2140
+ },
1999
2141
  {
2000
2142
  "text": "{\n provider: 'oauth2';\n result: OAuth2LoginResponse;\n }",
2001
2143
  "complexTypes": [
@@ -175,6 +175,39 @@ export interface InitializeOptions {
175
175
  * }
176
176
  */
177
177
  oauth2?: Record<string, OAuth2ProviderConfig>;
178
+ /**
179
+ * Telegram Login Widget configuration.
180
+ * Uses Telegram's OAuth widget (`oauth.telegram.org`), not standard OAuth2.
181
+ */
182
+ telegram?: {
183
+ /**
184
+ * Telegram bot ID (numeric, not the bot token).
185
+ * @example '123456789'
186
+ */
187
+ botId: string;
188
+ /**
189
+ * Default redirect URL that will receive Telegram auth data.
190
+ * For mobile apps, prefer a custom scheme (e.g. `myapp://telegram-auth`).
191
+ * On iOS/Android this must be set here or per login; native login rejects if it is missing.
192
+ */
193
+ redirectUrl?: string;
194
+ /**
195
+ * Origin/domain registered for the Telegram login widget.
196
+ * Required when `redirectUrl` is not `http`/`https` (for example a custom scheme like `myapp://telegram-auth`).
197
+ * Defaults to the origin of `redirectUrl` only when that URL is already http(s).
198
+ * @example 'https://example.com'
199
+ */
200
+ origin?: string;
201
+ /**
202
+ * Requested access level.
203
+ * @default 'write'
204
+ */
205
+ requestAccess?: 'read' | 'write';
206
+ /**
207
+ * Optional language code passed to Telegram (e.g. 'en', 'fr').
208
+ */
209
+ languageCode?: string;
210
+ };
178
211
  twitter?: {
179
212
  /**
180
213
  * The OAuth 2.0 client identifier issued by X (Twitter) Developer Portal
@@ -425,6 +458,25 @@ export interface TwitterLoginOptions {
425
458
  */
426
459
  forceLogin?: boolean;
427
460
  }
461
+ export interface TelegramLoginOptions {
462
+ /**
463
+ * Override the redirect URL for this login attempt.
464
+ * Defaults to the redirect configured during initialize().
465
+ * Required on iOS/Android when initialize() did not set `redirectUrl`.
466
+ */
467
+ redirectUrl?: string;
468
+ /**
469
+ * Optional state parameter for CSRF protection.
470
+ * If omitted, a secure random value is generated automatically.
471
+ */
472
+ state?: string;
473
+ /**
474
+ * Override requested access level for this login.
475
+ * Defaults to the value configured during initialize().
476
+ * @default 'write'
477
+ */
478
+ requestAccess?: 'read' | 'write';
479
+ }
428
480
  export interface OAuth2LoginOptions {
429
481
  /**
430
482
  * The provider ID as configured in initialize()
@@ -712,6 +764,9 @@ export type LoginOptions = {
712
764
  } | {
713
765
  provider: 'twitter';
714
766
  options: TwitterLoginOptions;
767
+ } | {
768
+ provider: 'telegram';
769
+ options: TelegramLoginOptions;
715
770
  } | {
716
771
  provider: 'oauth2';
717
772
  options: OAuth2LoginOptions;
@@ -728,6 +783,9 @@ export type LoginResult = {
728
783
  } | {
729
784
  provider: 'twitter';
730
785
  result: TwitterLoginResponse;
786
+ } | {
787
+ provider: 'telegram';
788
+ result: TelegramLoginResponse;
731
789
  } | {
732
790
  provider: 'oauth2';
733
791
  result: OAuth2LoginResponse;
@@ -817,6 +875,28 @@ export interface TwitterLoginResponse {
817
875
  expiresIn?: number | null;
818
876
  profile: TwitterProfile;
819
877
  }
878
+ export interface TelegramProfile {
879
+ id: string;
880
+ firstName: string;
881
+ lastName?: string | null;
882
+ username?: string | null;
883
+ photoUrl?: string | null;
884
+ }
885
+ export interface TelegramLoginResponse {
886
+ profile: TelegramProfile;
887
+ /**
888
+ * Unix timestamp (seconds) when the user authorized the login.
889
+ */
890
+ authDate: number;
891
+ /**
892
+ * Telegram-provided hash for server-side verification.
893
+ */
894
+ hash: string;
895
+ /**
896
+ * Requested access level that was used for this login.
897
+ */
898
+ requestAccess: 'read' | 'write';
899
+ }
820
900
  export interface AuthorizationCode {
821
901
  /**
822
902
  * Jwt
@@ -846,7 +926,7 @@ export interface isLoggedInOptions {
846
926
  * Provider
847
927
  * @description Provider for the isLoggedIn
848
928
  */
849
- provider: 'apple' | 'google' | 'facebook' | 'twitter' | 'oauth2';
929
+ provider: 'apple' | 'google' | 'facebook' | 'twitter' | 'telegram' | 'oauth2';
850
930
  /**
851
931
  * Provider ID for OAuth2 providers (required when provider is 'oauth2')
852
932
  * @description The ID used when configuring the OAuth2 provider in initialize()
@@ -916,7 +996,8 @@ export interface GoogleClearRestoreCredentialResponse {
916
996
  export type ProviderSpecificCall = 'facebook#getProfile' | 'facebook#requestTracking' | 'google#createRestoreCredential' | 'google#getRestoreCredential' | 'google#clearRestoreCredential';
917
997
  export interface FacebookGetProfileOptions {
918
998
  /**
919
- * Fields to retrieve from Facebook profile
999
+ * Fields to retrieve from Facebook profile.
1000
+ * @default ['id', 'name', 'email', 'picture']
920
1001
  * @example ["id", "name", "email", "picture"]
921
1002
  */
922
1003
  fields?: string[];
@@ -989,6 +1070,7 @@ export type ProviderResponseMap = {
989
1070
  google: GoogleLoginResponse;
990
1071
  apple: AppleProviderResponse;
991
1072
  twitter: TwitterLoginResponse;
1073
+ telegram: TelegramLoginResponse;
992
1074
  oauth2: OAuth2LoginResponse;
993
1075
  };
994
1076
  /**
@@ -1039,7 +1121,7 @@ export interface SocialLoginPlugin {
1039
1121
  * @throws Error if Google provider is in offline mode
1040
1122
  */
1041
1123
  logout(options: {
1042
- provider: 'apple' | 'google' | 'facebook' | 'twitter' | 'oauth2';
1124
+ provider: 'apple' | 'google' | 'facebook' | 'twitter' | 'telegram' | 'oauth2';
1043
1125
  providerId?: string;
1044
1126
  }): Promise<void>;
1045
1127
  /**
@@ -1065,6 +1147,8 @@ export interface SocialLoginPlugin {
1065
1147
  *
1066
1148
  * In offline mode, the authorization code (serverAuthCode) is already returned by the `login()` method.
1067
1149
  *
1150
+ * Telegram login does not produce an authorization code; use the `hash` from `login()` and verify it on your backend.
1151
+ *
1068
1152
  * @throws Error if Google provider is in offline mode
1069
1153
  */
1070
1154
  getAuthorizationCode(options: AuthorizationCodeOptions): Promise<AuthorizationCode>;