-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtypes.ts
More file actions
257 lines (231 loc) · 5.51 KB
/
types.ts
File metadata and controls
257 lines (231 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/**
* Data returned by Telegram Login Widget
*/
export interface TelegramAuthData {
auth_date: number;
first_name: string;
hash: string;
id: number;
last_name?: string;
photo_url?: string;
username?: string;
}
/**
* User object from Telegram Mini Apps
*/
export interface TelegramMiniAppUser {
allows_write_to_pm?: boolean;
first_name: string;
id: number;
is_bot?: boolean;
is_premium?: boolean;
language_code?: string;
last_name?: string;
photo_url?: string;
username?: string;
}
/**
* Chat object from Telegram Mini Apps
*/
export interface TelegramMiniAppChat {
id: number;
photo_url?: string;
title?: string;
type: string;
username?: string;
}
/**
* Complete data from Telegram Mini Apps initData
*/
export interface TelegramMiniAppData {
auth_date: number;
can_send_after?: number;
chat?: TelegramMiniAppChat;
chat_instance?: string;
chat_type?: "sender" | "private" | "group" | "supergroup" | "channel";
hash: string;
query_id?: string;
receiver?: TelegramMiniAppUser;
start_param?: string;
user?: TelegramMiniAppUser;
}
/**
* JWT ID token claims from Telegram OIDC
*/
export interface TelegramOIDCClaims {
aud: string;
exp: number;
iat: number;
iss: string;
name?: string;
phone_number?: string;
picture?: string;
preferred_username?: string;
sub: string;
}
/**
* Configuration options for Telegram OIDC authentication
*/
export interface TelegramOIDCOptions {
/**
* Client ID from @BotFather's Web Login settings.
* If omitted, extracted from the main botToken (first part before colon).
* Use this when your OIDC bot is different from your Login Widget bot.
*/
clientId?: string;
/**
* Client Secret from @BotFather's Web Login settings.
* This is NOT your bot token — BotFather provides a separate secret
* when you configure Web Login under Bot Settings > Web Login.
*
* If omitted, falls back to the bot token (deprecated behavior that
* won't work with Telegram's official OIDC registration).
*/
clientSecret?: string;
/**
* Enable Telegram OIDC support
* @default false
*/
enabled?: boolean;
/**
* Custom function to map OIDC claims to user object
*/
mapOIDCProfileToUser?: (claims: TelegramOIDCClaims) => {
name?: string;
email?: string;
image?: string;
[key: string]: any;
};
/**
* Request bot access (adds "telegram:bot_access" scope)
* @default false
*/
requestBotAccess?: boolean;
/**
* Request phone number (adds "phone" scope)
* @default false
*/
requestPhone?: boolean;
/**
* Additional scopes beyond "openid"
* @default ["profile"]
*/
scopes?: string[];
}
/**
* Configuration options for the Telegram plugin
*/
export interface TelegramPluginOptions {
/**
* Allow users to link their Telegram account to existing account
* @default true
*/
allowUserToLink?: boolean;
/**
* Automatically create user if doesn't exist
* @default true
*/
autoCreateUser?: boolean;
/**
* Bot token obtained from @BotFather
* Used for verifying authentication data
*/
botToken: string;
/**
* Bot username (without @)
* Used for generating the login widget
*/
botUsername: string;
/**
* Enable Login Widget endpoints (signin, link, unlink).
* When false, Widget endpoints are not registered and Telegram-specific
* user/account schema fields are omitted (unless Mini App is enabled).
* @default true
*/
loginWidget?: boolean;
/**
* Custom function to map Telegram data to user object
*/
mapTelegramDataToUser?: (data: TelegramAuthData) => {
name?: string;
email?: string;
image?: string;
[key: string]: any;
};
/**
* Maximum age of auth_date in seconds
* Prevents replay attacks
* @default 86400 (24 hours)
*/
maxAuthAge?: number;
/**
* Telegram Mini Apps configuration
*/
miniApp?: {
/**
* Enable Telegram Mini Apps support
* @default false
*/
enabled?: boolean;
/**
* Validate initData from Mini Apps
* @default true
*/
validateInitData?: boolean;
/**
* Allow automatic sign-in from Mini Apps
* @default true
*/
allowAutoSignin?: boolean;
/**
* Custom function to map Mini App user data to user object
*/
mapMiniAppDataToUser?: (data: TelegramMiniAppUser) => {
name?: string;
email?: string;
image?: string;
[key: string]: any;
};
};
/**
* Telegram OIDC (OpenID Connect) configuration
* Uses standard OAuth 2.0 Authorization Code flow with PKCE
* via oauth.telegram.org
*/
oidc?: TelegramOIDCOptions;
/**
* Enable Telegram test server mode.
* When enabled, the client widget will use Telegram's test environment.
* HMAC verification works identically — only the bot token differs.
* Note: OIDC (oauth.telegram.org) has no documented test variant;
* a warning is logged if both testMode and oidc are enabled.
* @default false
*/
testMode?: boolean;
}
/**
* Additional fields to add to the user table
*/
export interface TelegramUserFields {
telegramId?: string;
telegramPhoneNumber?: string;
telegramUsername?: string;
}
/**
* Additional fields to add to the account table
*/
export interface TelegramAccountFields {
telegramId: string;
telegramUsername?: string;
}
/**
* Account record as returned by the Better Auth adapter
*/
export interface TelegramAccountRecord {
accountId: string;
id: string;
providerId: string;
telegramId?: string;
telegramUsername?: string;
userId: string;
}