tgloginwidget

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2025 License: MIT Imports: 9 Imported by: 1

README

package tgloginwidget

Provides utilities to work with Telegram Login Widget.

Usage/Examples

package main

import "github.com/bots-go-framework/bots-fw-telegram-webapp/tgloginwidget"


func main() {
	
	authData := tgloginwidget.AuthData{
		// ... Initialize AuthData struct.
	}

	// Telegram bot token.
	const token = "XXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXX"

	// Call "Check" method to validate hash.
	if err := authData.Check(token); err != nil {
		// Invalid hash.
		return
	}
	// Hash is valid.
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBotTokenRequired = errors.New("bot token is required")
View Source
var ErrHashIsNotValidHex = errors.New("provided hash is a not valid hex string")
View Source
var ErrHashMismatch = errors.New("provided hash does not match computed hash")

Functions

This section is empty.

Types

type AuthData

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

func (AuthData) Check

func (v AuthData) Check(botToken string) (err error)

Check validates SHA256 of v.StringToCheck() matches v.Hash

func (AuthData) GetHash

func (v AuthData) GetHash(token string) string

GetHash returns hash of v.StringToCheck() with token

func (AuthData) String

func (v AuthData) String() string

func (AuthData) StringToCheck

func (v AuthData) StringToCheck() string

func (AuthData) Validate

func (v AuthData) Validate() error

Jump to

Keyboard shortcuts

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