Skip to content
Clone

refactor(auth): refresh oauth authorize handler

zhenyi committed
parent 45a15da commit 25d9451 Browse files

1 file changed

+7 −7

Modified lib/auth/handler/oauth/authorize.rs View lib/auth/handler/oauth/authorize.rs
@@ -1,10 +1,10 @@
1use axum::Json;
21use axum::extract::State;
32use axum_extra::extract::cookie::CookieJar;
43
54use crate::error::AuthError;
65use crate::features::AuthService;
76use crate::features::oauth::types::{AuthorizationUrlResp, AuthorizeCmd};
7use export::data::{AppRequest, AppRequestData, AppResponseData};
88
99use super::super::cookies;
1010
@@ -12,9 +12,9 @@
1212 post,
1313 path = "/auth/oauth/authorize",
1414 tag = "auth",
15 request_body = AuthorizeCmd,
15 request_body = AppRequestData<AuthorizeCmd>,
1616 responses(
17 (status = 200, description = "Authorization URL. The state-cookie carries the OAuth state value for the callback.", body = AuthorizationUrlResp),
17 (status = 200, description = "Authorization URL. The state-cookie carries the OAuth state value for the callback.", body = AppResponseData<AuthorizationUrlResp>),
1818 (status = 400, description = "Validation / PoW failure.", body = super::super::openapi::ErrorBody),
1919 (status = 404, description = "Unknown provider.", body = super::super::openapi::ErrorBody),
2020 ),
@@ -22,10 +22,10 @@
2222pub(crate) async fn handler(
2323 State(svc): State<AuthService>,
2424 jar: CookieJar,
25 Json(cmd): Json<AuthorizeCmd>,
26) -> Result<(CookieJar, Json<AuthorizationUrlResp>), AuthError> {
27 let resp = svc.oauth_authorize(cmd).await?;
25 cmd: AppRequest<AuthorizeCmd>,
26) -> Result<(CookieJar, AppResponseData<AuthorizationUrlResp>), AuthError> {
27 let resp = svc.oauth_authorize(cmd.into_inner()).await?;
2828 let cookie = cookies::temp_key_to_cookie(&svc.config, &resp.temp_key);
2929 let jar = jar.add(cookie);
30 Ok((jar, Json(resp)))
30 Ok((jar, AppResponseData::ok(resp)))
3131}