package main
import (
"net/http"
"time"
http_request_body_json_decoder "entrlcom.dev/http-request-body-json-decoder"
telegram_login_widget "entrlcom.dev/telegram-login-widget"
"entrlcom.dev/unit"
)
const limit = unit.B * 512 // 512 B.
// TODO: Update values.
const (
timeout = time.Second * 10
token = "XXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXX"
)
func ServeHTTP(w http.ResponseWriter, r *http.Request) {
var authorizationData telegram_login_widget.AuthorizationData
// Decode HTTP request body to authorization data struct.
if err := http_request_body_json_decoder.Decode(w, r, &authorizationData, limit); err != nil {
// TODO: Handle error.
return
}
// Validate authorization data.
if err := authorizationData.Validate(token); err != nil {
// TODO: Handle error.
return
}
// Check whether authorization data is expired.
if authorizationData.IsExpired(timeout) {
// TODO: Handle.
return
}
// ...
}
package main
import (
"net/http"
"time"
telegram_login_widget "entrlcom.dev/telegram-login-widget"
)
// TODO: Update values.
const (
timeout = time.Second * 10
token = "XXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXX"
)
func ServeHTTP(w http.ResponseWriter, r *http.Request) {
authorizationData, err := telegram_login_widget.NewAuthorizationDataFromURL(r.URL.String())
if err != nil {
// TODO: Handle error.
return
}
// Validate authorization data.
if err = authorizationData.Validate(token); err != nil {
// TODO: Handle error.
return
}
// Check whether authorization data is expired.
if authorizationData.IsExpired(timeout) {
// TODO: Handle.
return
}
// ...
}
package main
import (
"net/http"
"time"
telegram_login_widget "entrlcom.dev/telegram-login-widget"
)
// TODO: Update values.
const (
timeout = time.Second * 10
token = "XXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXX"
)
func ServeHTTP(w http.ResponseWriter, r *http.Request) {
authorizationData, err := telegram_login_widget.NewAuthorizationDataFromURLValues(r.URL.Query())
if err != nil {
// TODO: Handle error.
return
}
// Validate authorization data.
if err = authorizationData.Validate(token); err != nil {
// TODO: Handle error.
return
}
// Check whether authorization data is expired.
if authorizationData.IsExpired(timeout) {
// TODO: Handle.
return
}
// ...
}
The Telegram login widget is a simple way to authorize users on your website. Check out this page for a general overview of the widget.
Call Validate
method on AuthorizationData
struct to validate hash.
Call IsExpired
method on AuthorizationData
struct to check whether authentication data is expired.