fix(oauth2): use public bot

This commit is contained in:
Zomatree
2025-06-24 02:21:51 +01:00
parent 3ae25fbcfe
commit 1e5b27ff9e
3 changed files with 7 additions and 9 deletions

View File

@@ -125,10 +125,6 @@ pub fn scope_can_access_route(scope: &str, request: &Request<'_>) -> bool {
match scope { match scope {
"identify" => { "identify" => {
println!("{:?}", request.method() == Method::Get);
println!("{:?}", segments.get(0));
println!("{:?}", segments.get(1));
request.method() == Method::Get && request.method() == Method::Get &&
segments.get(0) == Some("users") && segments.get(0) == Some("users") &&
segments.get(1) == Some("@me") segments.get(1) == Some("@me")

View File

@@ -1,4 +1,4 @@
use crate::v0::{Bot, User}; use crate::v0::{PublicBot, User};
auto_derived!( auto_derived!(
pub struct OAuth2AuthorizeAuthResponse { pub struct OAuth2AuthorizeAuthResponse {
@@ -7,7 +7,7 @@ auto_derived!(
} }
pub struct OAuth2AuthorizeInfoResponse { pub struct OAuth2AuthorizeInfoResponse {
pub bot: Bot, pub bot: PublicBot,
pub user: User, pub user: User,
} }

View File

@@ -7,13 +7,15 @@ use rocket::{form::Form, serde::json::Json, State};
/// ///
/// Fetches the information needed for displaying on the OAuth grant page /// Fetches the information needed for displaying on the OAuth grant page
#[openapi(tag = "OAuth2")] #[openapi(tag = "OAuth2")]
#[get("/authorize", data="<info>")] #[get("/authorize?<info..>")]
pub async fn info( pub async fn info(
db: &State<Database>, db: &State<Database>,
user: User, user: User,
info: Form<v0::OAuth2AuthorizationForm>, info: v0::OAuth2AuthorizationForm,
) -> Result<Json<v0::OAuth2AuthorizeInfoResponse>> { ) -> Result<Json<v0::OAuth2AuthorizeInfoResponse>> {
let bot = Reference::from_unchecked(info.client_id.to_string()).as_bot(db).await?; let bot = Reference::from_unchecked(info.client_id.to_string()).as_bot(db).await?;
let bot_user = Reference::from_unchecked(bot.id.clone()).as_user(db).await?;
let public_bot = bot.clone().into_public_bot(bot_user);
let Some(oauth2) = &bot.oauth2 else { let Some(oauth2) = &bot.oauth2 else {
return Err(create_error!(InvalidOperation)); return Err(create_error!(InvalidOperation));
@@ -24,7 +26,7 @@ pub async fn info(
}; };
Ok(Json(v0::OAuth2AuthorizeInfoResponse { Ok(Json(v0::OAuth2AuthorizeInfoResponse {
bot: bot.into(), bot: public_bot,
user: user.into(db, None).await user: user.into(db, None).await
})) }))
} }