@ts-core/oauth 3.1.19 → 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 +33 -8
- package/cjs/vk/VkAuth.js +1 -1
- package/esm/vk/VkAuth.js +1 -1
- package/package.json +1 -1
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 {
|
|
342
|
+
import { OAuthCordovaOAuthPluginPropertiesSet } from '@ts-core/oauth';
|
|
341
343
|
|
|
342
344
|
const auth = new GoAuth(logger, 'CLIENT_ID');
|
|
343
|
-
|
|
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 {
|
|
353
|
+
import { OAuthCordovaInAppBrowserPluginPropertiesSet } from '@ts-core/oauth';
|
|
350
354
|
|
|
351
355
|
const auth = new GoAuth(logger, 'CLIENT_ID');
|
|
352
|
-
|
|
353
|
-
//
|
|
354
|
-
return {
|
|
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
|
-
│
|
|
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://
|
|
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://
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-core/oauth",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.20",
|
|
4
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",
|