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 ¶
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)
}
}
Output:
Types ¶
type Handler ¶
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
}
Output:
func (Handlers) 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 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.