@skroz/profile-api 1.0.20 → 1.0.21
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.
|
@@ -6,6 +6,12 @@ type RedisClient = {
|
|
|
6
6
|
setex(key: string, ttl: number, value: string): Promise<any>;
|
|
7
7
|
del(key: string): Promise<any>;
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Вызывается ботом при получении /start tgauth_<token>.
|
|
11
|
+
* Записывает telegramUserId в Redis, подтверждая авторизацию.
|
|
12
|
+
* Возвращает true если токен найден и подтверждён, false если истёк или не существует.
|
|
13
|
+
*/
|
|
14
|
+
export declare function confirmTelegramBotAuth(redis: RedisClient, token: string, telegramUserId: number | string): Promise<boolean>;
|
|
9
15
|
export interface OauthResolverDependencies<TContext extends ProfileContext = ProfileContext> {
|
|
10
16
|
authService: ProfileAuthService | ((ctx: TContext) => ProfileAuthService);
|
|
11
17
|
userType: any;
|
|
@@ -35,6 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.confirmTelegramBotAuth = confirmTelegramBotAuth;
|
|
38
39
|
exports.createOauthResolver = createOauthResolver;
|
|
39
40
|
const crypto_1 = __importDefault(require("crypto"));
|
|
40
41
|
const nanoid_1 = require("nanoid");
|
|
@@ -44,6 +45,21 @@ const OauthInput_1 = require("../dto/OauthInput");
|
|
|
44
45
|
// другими ключами в том же Redis-инстансе.
|
|
45
46
|
const TELEGRAM_BOT_AUTH_REDIS_PREFIX = 'skroz:profile:tgbotauth';
|
|
46
47
|
const TELEGRAM_BOT_AUTH_TOKEN_TTL_SECONDS = 300; // 5 минут
|
|
48
|
+
/**
|
|
49
|
+
* Вызывается ботом при получении /start tgauth_<token>.
|
|
50
|
+
* Записывает telegramUserId в Redis, подтверждая авторизацию.
|
|
51
|
+
* Возвращает true если токен найден и подтверждён, false если истёк или не существует.
|
|
52
|
+
*/
|
|
53
|
+
function confirmTelegramBotAuth(redis, token, telegramUserId) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const redisKey = `${TELEGRAM_BOT_AUTH_REDIS_PREFIX}:${token}`;
|
|
56
|
+
const val = yield redis.get(redisKey);
|
|
57
|
+
if (val !== 'pending')
|
|
58
|
+
return false;
|
|
59
|
+
yield redis.setex(redisKey, TELEGRAM_BOT_AUTH_TOKEN_TTL_SECONDS, String(telegramUserId));
|
|
60
|
+
return true;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
47
63
|
let TelegramBotAuthLinkPayload = class TelegramBotAuthLinkPayload {
|
|
48
64
|
};
|
|
49
65
|
__decorate([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skroz/profile-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.21",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "git@gitlab.com:skroz/libs/utils.git",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"type-graphql": "^1.1.1",
|
|
45
45
|
"typeorm": "^0.2.45"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "4d48bd69998725da84ce966a6ab383fb5eb208cc"
|
|
48
48
|
}
|
|
@@ -6,11 +6,34 @@ import { OAuthProvider } from '../oauth/OAuthProvider';
|
|
|
6
6
|
import { OauthLoginInput, TelegramAuthData } from '../dto/OauthInput';
|
|
7
7
|
import { ProfileContext } from '../types';
|
|
8
8
|
|
|
9
|
+
type RedisClient = {
|
|
10
|
+
get(key: string): Promise<string | null>;
|
|
11
|
+
setex(key: string, ttl: number, value: string): Promise<any>;
|
|
12
|
+
del(key: string): Promise<any>;
|
|
13
|
+
};
|
|
14
|
+
|
|
9
15
|
// Префикс Redis-ключей намеренно длинный, чтобы исключить коллизии с любыми
|
|
10
16
|
// другими ключами в том же Redis-инстансе.
|
|
11
17
|
const TELEGRAM_BOT_AUTH_REDIS_PREFIX = 'skroz:profile:tgbotauth';
|
|
12
18
|
const TELEGRAM_BOT_AUTH_TOKEN_TTL_SECONDS = 300; // 5 минут
|
|
13
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Вызывается ботом при получении /start tgauth_<token>.
|
|
22
|
+
* Записывает telegramUserId в Redis, подтверждая авторизацию.
|
|
23
|
+
* Возвращает true если токен найден и подтверждён, false если истёк или не существует.
|
|
24
|
+
*/
|
|
25
|
+
export async function confirmTelegramBotAuth(
|
|
26
|
+
redis: RedisClient,
|
|
27
|
+
token: string,
|
|
28
|
+
telegramUserId: number | string
|
|
29
|
+
): Promise<boolean> {
|
|
30
|
+
const redisKey = `${TELEGRAM_BOT_AUTH_REDIS_PREFIX}:${token}`;
|
|
31
|
+
const val = await redis.get(redisKey);
|
|
32
|
+
if (val !== 'pending') return false;
|
|
33
|
+
await redis.setex(redisKey, TELEGRAM_BOT_AUTH_TOKEN_TTL_SECONDS, String(telegramUserId));
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
|
|
14
37
|
@ObjectType()
|
|
15
38
|
class TelegramBotAuthLinkPayload {
|
|
16
39
|
@Field()
|
|
@@ -29,12 +52,6 @@ class TelegramBotAuthConfirmResult {
|
|
|
29
52
|
expired!: boolean;
|
|
30
53
|
}
|
|
31
54
|
|
|
32
|
-
type RedisClient = {
|
|
33
|
-
get(key: string): Promise<string | null>;
|
|
34
|
-
setex(key: string, ttl: number, value: string): Promise<any>;
|
|
35
|
-
del(key: string): Promise<any>;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
55
|
export interface OauthResolverDependencies<
|
|
39
56
|
TContext extends ProfileContext = ProfileContext
|
|
40
57
|
> {
|