tgverifier

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: MIT Imports: 5 Imported by: 1

README

telegram-auth-verifier

Open in Visual Studio Code

About

This repository contains the source code of the Golang package for Telegram Website Login credentials verification. Check documentation here.

Install

With a correctly configured Go toolchain run:

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

Example

Let's verify credentials:

import (
	"encoding/json"
	"fmt"

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

func main() {
	var (
		token = []byte("Your Telegram Bot Token")
		creds = tgverifier.Credentials{}
	)

	rawCreds := `{
		"id": 111111111,
		"first_name": "John",
		"last_name": "Doe",
		"username": "johndoe",
		"auth_date": 1615974774,
		"hash": "ae1b08443b7bb50295be3961084c106072798cb65e91995a1b49927cd4cc5b0c"
	}`

	json.Unmarshal([]byte(rawCreds), &creds)

	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 are 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