Struct telegram_web_login_verifier::LoginVerifier [] [src]

pub struct LoginVerifier { /* fields omitted */ }

Verify the provided user data with the bot token

Methods

impl LoginVerifier
[src]

[src]

Returns a new LoginVerifier using the provided bot token as the key

Arguments

  • token - A &str containing the bot token provided by Telegram's Botfather # Examples ``` extern crate telegram_web_login_verifier;

use telegram_web_login_verifier::{LoginVerifier, RequestData};

let verifier = LoginVerifier::new("123456789:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); ```

[src]

Verifies if the provided login data is valid

Arguments

  • data - A reference to a telegram_web_login_verifier::RequestData struct.
  • check_time_stamp - If true the method will check if _auth_date_ is older than a day, in that case it will return Err("The login request expired")

Remarks

The method will return Ok(true) if the verification succeeds, it will return an error otherwise.

Examples

extern crate telegram_web_login_verifier;

use telegram_web_login_verifier::{LoginVerifier, RequestData};

let verifier = LoginVerifier::new("123456789:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");

let data = RequestData {
    auth_date: 1234567890,
    first_name: "First name".to_string(),
    hash: "d029f87e3d80f8fd9b1be67c7426b4cc1ff47b4a9d0a8461c826a59d8c5eb6cd".to_string(),
    id: 1234567,
    photo_url: "https://t.me/i/userpic/320/username.jpg".to_string(),
    username: "username".to_string()
};

let result = verifier.verify(&data, true);

match result {
    Ok(_) => println!("Ok!"),
    Err(e) => println!("{}", e)
}