Skip to content
Clone
030e59e
31 lines 1.2 KB Rust
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<AuthorizeCmd>,
responses(
(status = 200, description = "Authorization URL. The state-cookie carries the OAuth state value for the callback.", body = AppResponseData<AuthorizationUrlResp>),
(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<AuthService>,
jar: CookieJar,
cmd: AppRequest<AuthorizeCmd>,
) -> Result<(CookieJar, AppResponseData<AuthorizationUrlResp>), 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)))
}