verify

package
v0.169.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package verify answers the application verification checks of Telegram: Play Integrity (Android), APNS secret (Apple) and reCAPTCHA.

Telegram may answer a request, usually auth.sendCode or a sign-up, with a 403 error asking for proof that the request comes from a genuine app:

INTEGRITY_CHECK_CLASSIC_<project>_<nonce>  Google Play Integrity (Classic)
APNS_VERIFY_CHECK_<nonce>                  Apple push secret
RECAPTCHA_CHECK_<action>__<key_id>         reCAPTCHA

The official clients obtain the token and send the same request again wrapped in invokeWithGooglePlayIntegrity, invokeWithApnsSecret or invokeWithReCaptcha (tdlib: NetQueryDispatcher and NetQueryVerifier; Android: ConnectionsManager). This package does the same, but never obtains a token itself: the application decides whether and how to answer each check, through Handlers, as tdlib apps do on updateApplicationVerificationRequired. Without a handler for a check, the request fails with *Required, which the caller can answer later with Wrap.

Getting such tokens is subject to the terms of Telegram, Google and Apple; gotd ships no credentials and no way to produce them.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Wrap

func Wrap(r *Required, token string, query bin.Encoder) bin.Encoder

Wrap returns query wrapped to answer r with token, to be sent again.

Example

Without handlers, a request can be answered later: keep the *Required and send the same request again wrapped with the token.

package main

import (
	"github.com/gotd/td/telegram/verify"
)

func main() {
	var err error // from a request
	if r, ok := verify.Parse(err); ok {
		_ = r.Kind // obtain a token for r, then:
		// client.Invoke(ctx, verify.Wrap(r, token, request), result)
	}
}

Types

type Handler

type Handler func(ctx context.Context, r *Required) (token string, err error)

Handler returns the token answering r. An empty token with no error declines the check: the request fails with *Required.

type Handlers

type Handlers struct {
	PlayIntegrity Handler
	APNS          Handler
	ReCaptcha     Handler
	// MaxAttempts bounds how many checks one request may answer, as
	// MAX_CAPTCHA_CHECKS of Telegram for Android. Defaults to 3.
	MaxAttempts int
}

Handlers answer verification checks. A nil handler declines its kind.

Example

The application decides how to answer each check: here a reCAPTCHA token comes from a page the user solves, Play Integrity is declined, so a request that needs it fails with *verify.Required.

package main

import (
	"context"
	"errors"

	"github.com/gotd/td/telegram"
	"github.com/gotd/td/telegram/verify"
)

func main() {
	solve := func(ctx context.Context, action, keyID string) (string, error) {
		// Show a reCAPTCHA for keyID and action to the user, return the token.
		return "", errors.New("not implemented in the example")
	}
	h := verify.Handlers{
		ReCaptcha: func(ctx context.Context, r *verify.Required) (string, error) {
			return solve(ctx, r.Action, r.KeyID)
		},
	}
	client := telegram.NewClient(1, "hash", telegram.Options{
		Middlewares: []telegram.Middleware{h.Middleware()},
	})
	_ = client
}

func (Handlers) Invoker

func (h Handlers) Invoker(next tg.Invoker) tg.Invoker

Invoker returns next that answers verification checks with h, e.g. for the requests of an auth.Client only.

func (Handlers) Middleware

func (h Handlers) Middleware() telegram.Middleware

Middleware returns a telegram middleware that answers verification checks with h and sends the request again, wrapped. Put it in telegram.Options.Middlewares to cover every request of the client.

type Kind

type Kind int

Kind is the kind of a verification check.

const (
	// PlayIntegrity is a Google Play Integrity (Classic) check.
	PlayIntegrity Kind = iota + 1
	// APNS is an Apple push notification secret check.
	APNS
	// ReCaptcha is a reCAPTCHA check.
	ReCaptcha
)

func (Kind) String

func (k Kind) String() string

type Required

type Required struct {
	Kind Kind
	// ProjectNumber is the Google Cloud project number to request the Play
	// Integrity token for (PlayIntegrity).
	ProjectNumber int64
	// Nonce is the nonce to request the token for: for PlayIntegrity the
	// server nonce in base64url, as the Play Integrity API takes it; for APNS
	// as sent by the server. It is also sent back with the token.
	Nonce string
	// Action and KeyID are the reCAPTCHA action and site key (ReCaptcha).
	Action string
	KeyID  string
	// Err is the server error.
	Err *tgerr.Error
}

Required is a verification check asked for by the server instead of the result of a request.

func Parse

func Parse(err error) (*Required, bool)

Parse returns the verification check that err asks for, if any.

func (*Required) Error

func (r *Required) Error() string

func (*Required) Unwrap

func (r *Required) Unwrap() error

Unwrap returns the server error.

Jump to

Keyboard shortcuts

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