2026-04-21 20:30:41 +01:00
|
|
|
use serde::Deserialize;
|
|
|
|
|
|
|
|
|
|
use crate::{api, query};
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
2026-04-22 12:41:33 +01:00
|
|
|
pub struct CreateDeviceCode;
|
2026-04-21 20:30:41 +01:00
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
2026-04-22 12:41:33 +01:00
|
|
|
pub struct DeviceCodeResponse {
|
2026-04-21 20:30:41 +01:00
|
|
|
device_code: String,
|
|
|
|
|
user_code: String,
|
|
|
|
|
vertification_uri: String,
|
|
|
|
|
expires_in: u16,
|
|
|
|
|
interval: u16,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl query::QueryFn for CreateDeviceCode {
|
|
|
|
|
type Data = DeviceCodeResponse;
|
|
|
|
|
type Error = api::Error;
|
|
|
|
|
type Context = api::QueryContext;
|
|
|
|
|
|
|
|
|
|
fn key(&self) -> &'static str {
|
2026-04-22 12:41:33 +01:00
|
|
|
"auth.device_code"
|
2026-04-21 20:30:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn run(&self, c: &Self::Context) -> Result<Self::Data, Self::Error> {
|
|
|
|
|
let data = c
|
|
|
|
|
.http
|
|
|
|
|
.post(format!(
|
|
|
|
|
"https://github.com/login/device/code?client_id={}",
|
|
|
|
|
c.github.client_id
|
|
|
|
|
))
|
|
|
|
|
.send()
|
|
|
|
|
.await?
|
|
|
|
|
.bytes()
|
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
serde_json::from_slice::<DeviceCodeResponse>(&data).map_err(|e| e.into())
|
|
|
|
|
}
|
|
|
|
|
}
|