ferri/ferri-server/src/endpoints/oauth.rs

36 lines
990 B
Rust
Raw Normal View History

2025-04-11 12:29:29 +01:00
use rocket::{get, post, response::Redirect, serde::{json::Json, Deserialize, Serialize}};
#[get("/oauth/authorize?<client_id>&<scope>&<redirect_uri>&<response_type>")]
pub async fn authorize(
client_id: &str,
scope: &str,
redirect_uri: &str,
response_type: &str,
) -> Redirect {
Redirect::temporary(format!(
"{}?code=code-for-{}&state=state-for-{}",
redirect_uri, client_id, client_id
))
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(crate = "rocket::serde")]
pub struct Token {
pub access_token: String,
pub token_type: String,
pub expires_in: i64,
pub scope: String,
pub id_token: String,
}
#[post("/oauth/token")]
pub async fn new_token() -> Json<Token> {
Json(Token {
2025-04-12 11:27:03 +01:00
access_token: "9b9d497b-2731-435f-a929-e609ca69dac9".to_string(),
2025-04-11 12:29:29 +01:00
token_type: "Bearer".to_string(),
expires_in: 3600,
scope: "read write follow push".to_string(),
id_token: "id-token".to_string(),
})
}