tgverifier

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2021 License: MIT Imports: 6 Imported by: 0

README

what is this

Fork form here and fix some bugs

telegram-auth-verifier

Golang package for Telegram Website Login credentials verification. Check documentation here.

Install

With a correctly configured Go toolchain:

go get github.com/bborn2/telegram-auth-verifier

Example

Let's verify credentials:

import (
	"encoding/json"
	"fmt"
	"net/url"

	tgverifier "github.com/electrofocus/telegram-auth-verifier"
)

func main() {
	token := []byte("Your Telegram Bot Token")
	
	creds := tgverifier.Credentials{
		ID:        111111111,
		FirstName: "Kun",
		LastName:  "Song",
		Username:  "recoba",
		PhotoURL:  "http://tg.me/xxx",
		AuthDate:  1617443847,
		Hash:      ”ae1b08443b7bb50295be3961084c106072798cb65e91995a1b49927cd4cc5b0c“,
	}

	if err := creds.Verify(token); err != nil {
		fmt.Println("Credentials are not from Telegram")
		return
	}

	fmt.Println("Credentials are from Telegram")
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCreds = errors.New("invalid telegram creds")

ErrInvalidCreds ... Represents error in case of having invalid Telegram auth credentials

Functions

This section is empty.

Types

type Credentials

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

Credentials ... Telegram Login credentials available for parsing from JSON.

func (*Credentials) String

func (c *Credentials) String() string

String ... Builds credentials string, excluding hash field.

func (*Credentials) Verify

func (c *Credentials) Verify(token []byte) error

Verify ... Checks if the credentials are from Telegram. Returns nil error if credentials are from Telegram.

Jump to

Keyboard shortcuts

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