Skip to content

Commit 8290ebe

Browse files
committed
fix auth for change password
1 parent e480564 commit 8290ebe

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

crates/router/src/routes/user.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub async fn change_password(
4242
&http_req,
4343
json_payload.into_inner(),
4444
|state, user, req| user::change_password(state, req, user),
45-
&auth::JWTAuth,
45+
&auth::DashboardNoPermissionAuth,
4646
api_locking::LockAction::NotApplicable,
4747
))
4848
.await

crates/router/src/services/authentication.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,53 @@ where
543543
}
544544
}
545545

546+
pub struct DashboardNoPermissionAuth;
547+
548+
#[cfg(feature = "olap")]
549+
#[async_trait]
550+
impl<A> AuthenticateAndFetch<UserFromToken, A> for DashboardNoPermissionAuth
551+
where
552+
A: AppStateInfo + Sync,
553+
{
554+
async fn authenticate_and_fetch(
555+
&self,
556+
request_headers: &HeaderMap,
557+
state: &A,
558+
) -> RouterResult<(UserFromToken, AuthenticationType)> {
559+
let payload = parse_jwt_payload::<A, AuthToken>(request_headers, state).await?;
560+
561+
Ok((
562+
UserFromToken {
563+
user_id: payload.user_id.clone(),
564+
merchant_id: payload.merchant_id.clone(),
565+
org_id: payload.org_id,
566+
role_id: payload.role_id,
567+
},
568+
AuthenticationType::MerchantJWT {
569+
merchant_id: payload.merchant_id,
570+
user_id: Some(payload.user_id),
571+
},
572+
))
573+
}
574+
}
575+
576+
#[cfg(feature = "olap")]
577+
#[async_trait]
578+
impl<A> AuthenticateAndFetch<(), A> for DashboardNoPermissionAuth
579+
where
580+
A: AppStateInfo + Sync,
581+
{
582+
async fn authenticate_and_fetch(
583+
&self,
584+
request_headers: &HeaderMap,
585+
state: &A,
586+
) -> RouterResult<((), AuthenticationType)> {
587+
parse_jwt_payload::<A, AuthToken>(request_headers, state).await?;
588+
589+
Ok(((), AuthenticationType::NoAuth))
590+
}
591+
}
592+
546593
pub trait ClientSecretFetch {
547594
fn get_client_secret(&self) -> Option<&String>;
548595
}

0 commit comments

Comments
 (0)