Telegram.MiniApp.Auth
1.2.1
dotnet add package Telegram.MiniApp.Auth --version 1.2.1
NuGet\Install-Package Telegram.MiniApp.Auth -Version 1.2.1
<PackageReference Include="Telegram.MiniApp.Auth" Version="1.2.1" />
<PackageVersion Include="Telegram.MiniApp.Auth" Version="1.2.1" />
<PackageReference Include="Telegram.MiniApp.Auth" />
paket add Telegram.MiniApp.Auth --version 1.2.1
#r "nuget: Telegram.MiniApp.Auth, 1.2.1"
#:package Telegram.MiniApp.Auth@1.2.1
#addin nuget:?package=Telegram.MiniApp.Auth&version=1.2.1
#tool nuget:?package=Telegram.MiniApp.Auth&version=1.2.1
Telegram Mini App Auth
Telegram Mini Apps Official Documentation
Install
Install Telegram.MiniApp.Authentication using NuGet Package Manager:
Install-Package Telegram.MiniApp.Authentication
Or via the .NET CLI:
dotnet add package Telegram.MiniApp.Authentication
Usage
Backend
- Add Authentication:
builder.Services.AddTelegramMiniAppInHeader(options =>
{
options.BotToken = builder.Configuration.GetValue<string>("BotToken")!;
});
- Add Authorization:
// Library provides default policy:
builder.Services.AddAuthorization(options =>
{
// Simple TMA Policy. Only checks tma_user_id claims
options.AddDefaultTmaPolicy();
// For users with Telegram Premium. Checks tma_user_id and tma_is_premium claims
options.AddTmaPremiumPolicy();
});
// Or you can customize the policy the way you want:
builder.Services.AddAuthorization(options =>
{
options.AddPolicy("MyPolicy", policy =>
{
policy.AddAuthenticationSchemes(TmaDefaults.AuthenticationScheme);
// your settings
});
});
After successful authorization, records the following data in the Claims(if not null):
- tma_user_id - A unique identifier for the telegram user.
- tma_username - Username of the telegram user.
- tma_first_name - First name of the telegram user.
- tma_last_name - Last name of the telegram user.
- tma_chat_instance - Global identifier, uniquely corresponding to the chat.
- tma_is_premium - user is a Telegram Premium user or not.
You can get claims in the usual way, or use extension methods provided by the library:
// Get TMA claims as TmaUserPrincipals
if (HttpContext.User.TryGetTmaUser(out var tmaUser))
{
//Using
}
// Get all initData as TmaInitData
if (HttpContext.TryGetTmaInitData(out var initData))
{
//Using
}
Frontend
Set window.Telegram.WebApp.initData with prefix 'Tma ' in Authorization Header (Or another header, what you set in TmaAuthenticationOptions.TokenHeaderName)
example:
fetch('endpoint-url', {
headers: {
'Authorization': `TMA ${window.Telegram.WebApp.initData}`
}
})
Solution
- Telegram.MiniApp.Authentication - Nuget package
- tests/TestWebApi - .NET Web Api app for auth testing
Authors
By Konstantin Orlov with Kutumov Nikita support.
Address for TON
donations, we appreciate any "thanks" 😃
UQD0zFgp0p-eFnbL4cPA6DYqoeWzGbCA81KuU6BKwdFmf8jv
Connect in Telegram
2025
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- Microsoft.AspNetCore.Authentication (>= 2.2.0)
- Swashbuckle.AspNetCore (>= 6.8.1)
-
net7.0
- Microsoft.AspNetCore.Authentication (>= 2.2.0)
- Swashbuckle.AspNetCore (>= 6.8.1)
-
net8.0
- Microsoft.AspNetCore.Authentication (>= 2.2.0)
- Swashbuckle.AspNetCore (>= 6.8.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.