wip
This commit is contained in:
40
src/api/auth.rs
Normal file
40
src/api/auth.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{api, query};
|
||||
|
||||
#[derive(Clone)]
|
||||
struct CreateDeviceCode;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct DeviceCodeResponse {
|
||||
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 {
|
||||
todo!()
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,16 @@ use crate::query;
|
||||
#[derive(Clone)]
|
||||
pub struct List;
|
||||
|
||||
impl query::QueryFn<QueryContext> for List {
|
||||
impl query::QueryFn for List {
|
||||
type Data = ();
|
||||
type Error = ();
|
||||
type Context = QueryContext;
|
||||
|
||||
fn key(&self) -> &'static str {
|
||||
"repo.list"
|
||||
}
|
||||
|
||||
async fn run(&self, _c: &QueryContext) -> Result<Self::Data, Self::Error> {
|
||||
async fn run(&self, _c: &Self::Context) -> Result<Self::Data, Self::Error> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,16 @@ use crate::{api, query};
|
||||
#[derive(Clone)]
|
||||
pub struct Fetch;
|
||||
|
||||
impl query::QueryFn<api::QueryContext> for Fetch {
|
||||
impl query::QueryFn for Fetch {
|
||||
type Data = api::Error;
|
||||
|
||||
type Error = api::Error;
|
||||
type Context = api::QueryContext;
|
||||
|
||||
fn key(&self) -> &'static str {
|
||||
"user"
|
||||
}
|
||||
|
||||
async fn run(&self, c: &api::QueryContext) -> Result<Self::Data, Self::Error> {
|
||||
async fn run(&self, c: &Self::Context) -> Result<Self::Data, Self::Error> {
|
||||
Err(api::Error::Unauthenticated)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user