tglogin

package
v0.14.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2026 License: Apache-2.0, MIT Imports: 5 Imported by: 0

README

tglogin — Telegram Login Widget authentication

The tglogin package validates user data received from the Telegram Login Widget.

Installation

go get github.com/bots-go-framework/bots-api-telegram/tglogin

Usage

import "github.com/bots-go-framework/bots-api-telegram/tglogin"

// Populate from the widget callback query parameters
user := tglogin.LoginUser{
    ID:        123456789,
    FirstName: "Alice",
    AuthDate:  1700000000,
    Hash:      "<hash from Telegram>",
}

if user.IsFromTelegram(botToken) {
    // Data is authentic — safe to create a session for this user
} else {
    // Reject: data was not signed by Telegram
}

Exported API

LoginUser
type LoginUser struct {
    ID        int    `json:"id"`
    FirstName string `json:"first_name"`
    LastName  string `json:"last_name,omitempty"`
    Username  string `json:"username,omitempty"`
    PhotoUrl  string `json:"photo_url,omitempty"`
    AuthDate  int    `json:"auth_date"`
    Hash      string `json:"hash"`
}
Method Description
IsFromTelegram(botToken string) bool Returns true if the struct fields are authentically signed by Telegram using the given bot token

Telegram documentation

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoginUser

type LoginUser struct {
	ID        int    `json:"id"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name,omitempty"`
	Username  string `json:"username,omitempty"`
	PhotoUrl  string `json:"photo_url,omitempty"`
	AuthDate  int    `json:"auth_date"`
	Hash      string `json:"hash"`
}

LoginUser is a user data received from Telegram

func (LoginUser) IsFromTelegram

func (v LoginUser) IsFromTelegram(botToken string) bool

IsFromTelegram checks if the user data are signed with given Telegram bot token

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL