telegramlogin

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TelegramLoginPrefix = "login_"
	TelegramLinkPrefix  = "link_"
)
View Source
const PollSecretHeader = "X-Login-Secret"

Variables

This section is empty.

Functions

func Configure

func Configure(c Config)

func CreateTelegramLoginToken

func CreateTelegramLoginToken(secret, where string) (string, error)

func IsTelegramLoginToken

func IsTelegramLoginToken(token string) bool

IsTelegramLoginToken reports whether a /start payload is a sign-in token.

func NewTelegramLoginSecret

func NewTelegramLoginSecret() (string, error)

NewTelegramLoginSecret returns the page-held secret that polls must present.

func ParseTelegramLoginToken

func ParseTelegramLoginToken(token string) (tenantDir string, ok bool)

ParseTelegramLoginToken returns the tenant a sign-in token was issued by.

func PollTelegramLogin

func PollTelegramLogin(token, secret string) (status string, userID int64)

func ProcessTelegramLoginConfirm

func ProcessTelegramLoginConfirm(token string, chatID int64, langHint string) (owned bool, reply string)

func ProcessTelegramLoginStart

func ProcessTelegramLoginStart(token string, chatID int64, chatType, langHint string) (owned bool, reply, confirm, confirmLabel string)

ProcessTelegramLoginStart handles the bot's /start <token>. owned is false when this tenant has no such pending sign-in. confirm and confirmLabel are set when the person must confirm with the button; reply is the message to send either way. Only an enabled admin or staff account linked to this Telegram account can sign in.

func ProcessTelegramLoginStartAs added in v1.8.0

func ProcessTelegramLoginStartAs(token string, chatID int64, chatType, langHint string, who Identity) (owned bool, reply, confirm, confirmLabel string)

func TelegramTokenTenant

func TelegramTokenTenant(token string) (dir string, named bool)

TelegramTokenTenant reports which tenant issued a /start token. named is true for sign-in and account-link tokens; dir is empty when such a token is malformed. A bare /start or any other payload is not named.

Types

type Config

type Config struct {
	OwnDirName func() string
	FindUsers  func(chatID int64) ([]int64, error)
	Resolve    func(chatID int64, who Identity) ([]int64, error)
	Text       func(langHint, key string) string
}

Config wires the package to an application. Resolve is optional: an application that lets people sign up with Telegram sets it to find or create the account for a chat, and FindUsers is then not used.

type Flow added in v1.8.0

type Flow struct {
	Config
	Kind string
}

Flow is one sign-in flow: a bot, how it finds or creates accounts, and the wording it uses. Kind keeps flows apart: a token issued by one kind is not accepted by another, so a customer sign-in cannot be completed through the bot that signs staff in.

func (*Flow) CreateTelegramLoginToken added in v1.8.0

func (f *Flow) CreateTelegramLoginToken(secret, where string) (string, error)

CreateTelegramLoginToken issues a sign-in token bound to secret. where is shown to the person in the confirmation message.

func (*Flow) PollTelegramLogin added in v1.8.0

func (f *Flow) PollTelegramLogin(token, secret string) (status string, userID int64)

PollTelegramLogin reports where a sign-in stands for the page that holds the secret: pending, awaiting (the person has been asked to confirm), approved (the token is consumed and userID is who to sign in), rejected or expired.

func (*Flow) ProcessTelegramLoginConfirm added in v1.8.0

func (f *Flow) ProcessTelegramLoginConfirm(token string, chatID int64, langHint string) (owned bool, reply string)

ProcessTelegramLoginConfirm handles the confirm button. Only the chat the start came from can approve it.

func (*Flow) ProcessTelegramLoginStartAs added in v1.8.0

func (f *Flow) ProcessTelegramLoginStartAs(token string, chatID int64, chatType, langHint string, who Identity) (owned bool, reply, confirm, confirmLabel string)

ProcessTelegramLoginStartAs is ProcessTelegramLoginStart for applications that also need who the person is, to create an account on first sign-in.

type HTTPConfig

type HTTPConfig struct {
	Flow         *Flow
	BotUsername  func() string
	Where        func(r *http.Request) string
	LookupUser   func(id int64) (Subject, error)
	LogSignIn    func(r *http.Request, s Subject)
	Temp2FAToken func(userID int64) (string, error)
	Finalize     func(w http.ResponseWriter, r *http.Request, s Subject)
	TwoFAPath    string
}

func (HTTPConfig) HandlePoll

func (c HTTPConfig) HandlePoll(w http.ResponseWriter, r *http.Request)

func (HTTPConfig) HandleStart

func (c HTTPConfig) HandleStart(w http.ResponseWriter, r *http.Request)

type Identity added in v1.8.0

type Identity struct {
	Username  string
	FirstName string
	Lang      string
}

Identity is what Telegram says about the person who opened the bot.

type Subject

type Subject struct {
	ID       int64
	Disabled bool
	TwoFA    bool
	Payload  any
}

Jump to

Keyboard shortcuts

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