TmaAuthentication 1.0.1
dotnet add package TmaAuthentication --version 1.0.1
NuGet\Install-Package TmaAuthentication -Version 1.0.1
<PackageReference Include="TmaAuthentication" Version="1.0.1" />
<PackageVersion Include="TmaAuthentication" Version="1.0.1" />
<PackageReference Include="TmaAuthentication" />
paket add TmaAuthentication --version 1.0.1
#r "nuget: TmaAuthentication, 1.0.1"
#:package TmaAuthentication@1.0.1
#addin nuget:?package=TmaAuthentication&version=1.0.1
#tool nuget:?package=TmaAuthentication&version=1.0.1
TmaAuthentication
A C# library for validating Telegram Mini App initialization data.
Overview
TmaAuthentication is a C# library for working with Telegram Mini App initialization data. It provides functionality to:
- Parse initialization data from a query string format
- Validate the initialization data using the bot token
- Sign initialization data for testing or other purposes
Installation
Add the NuGet package to your project:
dotnet add package TmaAuthentication
Usage
Validating Initialization Data
The validator helps you verify if the initialization data received from Telegram is authentic and hasn't been tampered with.
// Create validator instance
var validator = new TmaInitDataValidator();
// Validate initialization data with 24-hour expiration
var initData = "query_id=AAHdF6IQAAAAAN0XohDhrOrc&user=%7B%22id%22%3A279058397%2C%22first_name%22%3A%22John%22%2C%22last_name%22%3A%22Doe%22%7D&auth_date=1713542400&hash=abc123...";
var isValid = validator.Validate(initData, "YOUR_BOT_TOKEN", TimeSpan.FromHours(24));
if (isValid)
{
Console.WriteLine("Initialization data is valid");
}
else
{
Console.WriteLine("Initialization data is invalid");
}
Creating Signatures
The signer helps you create valid signatures for testing or when you need to generate initialization data programmatically.
// Create signer instance
var signer = new TmaInitDataSigner();
// Create a signature from parameters
var parameters = new Dictionary<string, string>
{
{ "user", "{\"id\":123456789,\"first_name\":\"John\",\"last_name\":\"Doe\"}" },
{ "query_id", "AAHdF6IQAAAAAN0XohDhrOrc" },
{ "auth_date", DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString() }
};
var hash = signer.Sign(parameters, "YOUR_BOT_TOKEN");
License
This library is open source and available under the MIT license.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net8.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on TmaAuthentication:
Package | Downloads |
---|---|
TmaAuthentication.AspNetCore
ASP.NET Core integration for Telegram Mini App Authentication Library |
GitHub repositories
This package is not used by any popular GitHub repositories.