Documentation
¶
Index ¶
- Constants
- func Configure(c Config)
- func CreateTelegramLoginToken(secret, where string) (string, error)
- func IsTelegramLoginToken(token string) bool
- func NewTelegramLoginSecret() (string, error)
- func ParseTelegramLoginToken(token string) (tenantDir string, ok bool)
- func PollTelegramLogin(token, secret string) (status string, userID int64)
- func ProcessTelegramLoginConfirm(token string, chatID int64, langHint string) (owned bool, reply string)
- func ProcessTelegramLoginStart(token string, chatID int64, chatType, langHint string) (owned bool, reply, confirm, confirmLabel string)
- func ProcessTelegramLoginStartAs(token string, chatID int64, chatType, langHint string, who Identity) (owned bool, reply, confirm, confirmLabel string)
- func TelegramTokenTenant(token string) (dir string, named bool)
- type Config
- type Flow
- func (f *Flow) CreateTelegramLoginToken(secret, where string) (string, error)
- func (f *Flow) PollTelegramLogin(token, secret string) (status string, userID int64)
- func (f *Flow) ProcessTelegramLoginConfirm(token string, chatID int64, langHint string) (owned bool, reply string)
- func (f *Flow) ProcessTelegramLoginStartAs(token string, chatID int64, chatType, langHint string, who Identity) (owned bool, reply, confirm, confirmLabel string)
- type HTTPConfig
- type Identity
- type Subject
Constants ¶
const ( TelegramLoginPrefix = "login_" TelegramLinkPrefix = "link_" )
const PollSecretHeader = "X-Login-Secret"
Variables ¶
This section is empty.
Functions ¶
func IsTelegramLoginToken ¶
IsTelegramLoginToken reports whether a /start payload is a sign-in token.
func NewTelegramLoginSecret ¶
NewTelegramLoginSecret returns the page-held secret that polls must present.
func ParseTelegramLoginToken ¶
ParseTelegramLoginToken returns the tenant a sign-in token was issued by.
func PollTelegramLogin ¶
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 TelegramTokenTenant ¶
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
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
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
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)