use axum::extract::State; use axum_extra::extract::cookie::CookieJar; use crate::error::AuthError; use crate::features::AuthService; use crate::features::oauth::types::{AuthorizationUrlResp, AuthorizeCmd}; use export::data::{AppRequest, AppRequestData, AppResponseData}; use super::super::cookies; #[utoipa::path( post, path = "/auth/oauth/authorize", tag = "auth", request_body = AppRequestData, responses( (status = 200, description = "Authorization URL. The state-cookie carries the OAuth state value for the callback.", body = AppResponseData), (status = 400, description = "Validation / PoW failure.", body = super::super::openapi::ErrorBody), (status = 404, description = "Unknown provider.", body = super::super::openapi::ErrorBody), ), )] pub(crate) async fn handler( State(svc): State, jar: CookieJar, cmd: AppRequest, ) -> Result<(CookieJar, AppResponseData), AuthError> { let resp = svc.oauth_authorize(cmd.into_inner()).await?; let cookie = cookies::temp_key_to_cookie(&svc.config, &resp.temp_key); let jar = jar.add(cookie); Ok((jar, AppResponseData::ok(resp))) }