@ts-core/oauth 3.1.18 → 3.1.20

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/README.md CHANGED
@@ -176,7 +176,7 @@ console.log(user.name, user.telegram);
176
176
  | Яндекс | `YaAuth` | `YaUser` | Стандартный OAuth 2.0 |
177
177
  | Mail.ru | `MaAuth` | `MaUser` | Стандартный OAuth 2.0 |
178
178
  | Keycloak | `KeycloakAuth` | `KeycloakUser` | Настраиваемый realm/URL, logout через pop-up |
179
- | Telegram | `TgAuth` | `TgUser` | Web App + Login Widget |
179
+ | Telegram | `TgAuth` | `TgUser` | Web App + Login Widget + Cordova |
180
180
 
181
181
  ---
182
182
 
@@ -336,25 +336,49 @@ interface ITgAuthSettings {
336
336
 
337
337
  ### Cordova OAuth Plugin
338
338
 
339
+ Требуется `cordova-plugin-oauth`. Redirect URI выставляется в `<packageName>://oauth_callback`.
340
+
339
341
  ```typescript
340
- import { CordovaOAuthPluginPropertiesSet } from '@ts-core/oauth';
342
+ import { OAuthCordovaOAuthPluginPropertiesSet } from '@ts-core/oauth';
341
343
 
342
344
  const auth = new GoAuth(logger, 'CLIENT_ID');
343
- CordovaOAuthPluginPropertiesSet(auth);
345
+ OAuthCordovaOAuthPluginPropertiesSet(auth, 'com.example.app');
344
346
  ```
345
347
 
346
348
  ### Cordova InAppBrowser
347
349
 
350
+ Требуется `cordova-plugin-inappbrowser`. Когда InAppBrowser доходит до `redirectUri`, вызывается переданный метод: он по `state` забирает с бэкенда результат авторизации.
351
+
348
352
  ```typescript
349
- import { CordovaInAppBrowserPluginPropertiesSet } from '@ts-core/oauth';
353
+ import { OAuthCordovaInAppBrowserPluginPropertiesSet } from '@ts-core/oauth';
350
354
 
351
355
  const auth = new GoAuth(logger, 'CLIENT_ID');
352
- CordovaInAppBrowserPluginPropertiesSet(auth, async (url) => {
353
- // Ваша логика получения токена по URL
354
- return { codeOrToken: 'token', redirectUri: 'uri' };
356
+ OAuthCordovaInAppBrowserPluginPropertiesSet(auth, 'https://myapp.com/oauth', async (state) => {
357
+ // Получить сохранённый бэкендом результат для state
358
+ return { oAuthCodeOrToken: 'code' };
355
359
  });
356
360
  ```
357
361
 
362
+ ### Telegram Login в Cordova (InAppBrowser)
363
+
364
+ Виджет Telegram внутри Cordova не работает, поэтому `TgAuth` открывает `oauth.telegram.org/auth` в InAppBrowser. Как только браузер переходит на `returnUrl`, из `#tgAuthResult` или query-параметров собирается `TgUser`, окно закрывается. Если пользователь закрыл окно сам, `getUser()` отклоняется с `ERROR_WINDOW_CLOSED`.
365
+
366
+ Требуется `cordova-plugin-inappbrowser`. Домен из `origin` должен быть привязан к боту через `/setdomain` в @BotFather.
367
+
368
+ ```typescript
369
+ import { TgAuth, TgApiLoader, TgAuthCordovaInAppBrowserPluginPropertiesSet } from '@ts-core/oauth';
370
+
371
+ const auth = new TgAuth(logger, { api: new TgApiLoader(logger), botId: YOUR_BOT_ID });
372
+ TgAuthCordovaInAppBrowserPluginPropertiesSet(auth, {
373
+ origin: 'https://myapp.com', // Домен, привязанный к боту
374
+ returnUrl: 'https://myapp.com/oauth', // Куда Telegram вернёт пользователя
375
+ requestAccess: 'write', // Необязательно: разрешение писать пользователю
376
+ // inAppBrowserOptions: 'location=no' // Необязательно: опции InAppBrowser
377
+ });
378
+
379
+ const user = await auth.getUser();
380
+ ```
381
+
358
382
  ---
359
383
 
360
384
  ## Расширенные возможности
@@ -413,7 +437,8 @@ src/
413
437
  ├── external/ # Платформенные интеграции
414
438
  │ ├── browser.ts
415
439
  │ ├── cordovaOAuthPlugin.ts
416
- └── cordovaInAppBrowserPlugin.ts
440
+ ├── cordovaInAppBrowserPlugin.ts
441
+ │ └── cordovaInAppBrowserTgPlugin.ts
417
442
  ├── go/ # Google
418
443
  ├── vk/ # VK
419
444
  ├── ya/ # Яндекс
package/cjs/vk/VkAuth.js CHANGED
@@ -21,7 +21,7 @@ class VkAuth extends OAuthBase_1.OAuthBase {
21
21
  this.params.set('scope', 'status,email');
22
22
  }
23
23
  popUpUrl() {
24
- return `https://id.vk.ru/authorize?${this.getParams().toString()}`;
24
+ return `https://oauth.vk.com/authorize?${this.getParams().toString()}`;
25
25
  }
26
26
  getProfile(token, fields) {
27
27
  return __awaiter(this, void 0, void 0, function* () {
package/esm/vk/VkAuth.js CHANGED
@@ -18,7 +18,7 @@ export class VkAuth extends OAuthBase {
18
18
  this.params.set('scope', 'status,email');
19
19
  }
20
20
  popUpUrl() {
21
- return `https://id.vk.ru/authorize?${this.getParams().toString()}`;
21
+ return `https://oauth.vk.com/authorize?${this.getParams().toString()}`;
22
22
  }
23
23
  getProfile(token, fields) {
24
24
  return __awaiter(this, void 0, void 0, function* () {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ts-core/oauth",
3
- "version": "3.1.18",
4
- "description": "Classes and utils for oauth",
3
+ "version": "3.1.20",
4
+ "description": "TypeScript library for OAuth authentication through Google, VK, Yandex, Mail.ru, Keycloak and Telegram, supporting browser, Cordova and Telegram Web App platforms",
5
5
  "main": "./cjs/public-api.js",
6
6
  "module": "./esm/public-api.js",
7
7
  "exports": {
@@ -28,7 +28,20 @@
28
28
  "url": "git+https://github.com/ManhattanDoctor/ts-core-oauth.git"
29
29
  },
30
30
  "keywords": [
31
- "typescript"
31
+ "typescript",
32
+ "oauth",
33
+ "oauth2",
34
+ "authentication",
35
+ "authorization",
36
+ "google",
37
+ "vk",
38
+ "yandex",
39
+ "mailru",
40
+ "keycloak",
41
+ "telegram",
42
+ "cordova",
43
+ "login",
44
+ "sso"
32
45
  ],
33
46
  "bugs": {
34
47
  "url": "https://github.com/ManhattanDoctor/ts-core-oauth/issues"