Lonami / grammers

(tele)gramme.rs - use Telegram's API from Rust
https://t.me/gramme_rs
Apache License 2.0
562 stars 117 forks source link

[FEATURE] Export loginToken for doing QR-Code login #222

Closed xndrpr closed 7 months ago

xndrpr commented 8 months ago

I would like to create a QR code login for my Telegram client, but the auth.exportLoginToken implementation is missing. I'd be grateful if you could implement this!

https://core.telegram.org/method/auth.exportLoginToken

xndrpr commented 8 months ago

This worked for me:

let request = tl::functions::auth::ExportLoginToken {
            api_id: env::var("API_ID").unwrap().parse().unwrap(),
            api_hash: env::var("API_HASH").unwrap(),
            except_ids: vec![],
        };

        let result = self.client.invoke(&request).await.unwrap();
// Then
    let url = format!("tg://login?token={}", base64_url::encode(&bytes));

// And after qr code is scanned
let result = self.client.invoke(&request).await.unwrap(); // again

// You are signed in
Lonami commented 7 months ago

I don't have plans to create a friendly method for this, and the raw API solution should work for those who need it.