Skip to content

Commit

Permalink
fix auth for change password
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvdixit88 committed Nov 24, 2023
1 parent e480564 commit 8290ebe
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/router/src/routes/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub async fn change_password(
&http_req,
json_payload.into_inner(),
|state, user, req| user::change_password(state, req, user),
&auth::JWTAuth,
&auth::DashboardNoPermissionAuth,
api_locking::LockAction::NotApplicable,
))
.await
Expand Down
47 changes: 47 additions & 0 deletions crates/router/src/services/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,53 @@ where
}
}

pub struct DashboardNoPermissionAuth;

#[cfg(feature = "olap")]
#[async_trait]
impl<A> AuthenticateAndFetch<UserFromToken, A> for DashboardNoPermissionAuth
where
A: AppStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
request_headers: &HeaderMap,
state: &A,
) -> RouterResult<(UserFromToken, AuthenticationType)> {
let payload = parse_jwt_payload::<A, AuthToken>(request_headers, state).await?;

Ok((
UserFromToken {
user_id: payload.user_id.clone(),
merchant_id: payload.merchant_id.clone(),
org_id: payload.org_id,
role_id: payload.role_id,
},
AuthenticationType::MerchantJWT {
merchant_id: payload.merchant_id,
user_id: Some(payload.user_id),
},
))
}
}

#[cfg(feature = "olap")]
#[async_trait]
impl<A> AuthenticateAndFetch<(), A> for DashboardNoPermissionAuth
where
A: AppStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
request_headers: &HeaderMap,
state: &A,
) -> RouterResult<((), AuthenticationType)> {
parse_jwt_payload::<A, AuthToken>(request_headers, state).await?;

Ok(((), AuthenticationType::NoAuth))
}
}

pub trait ClientSecretFetch {
fn get_client_secret(&self) -> Option<&String>;
}
Expand Down

0 comments on commit 8290ebe

Please sign in to comment.