mirror of
https://github.com/kanidm/kanidm.git
synced 2025-02-23 20:47:01 +01:00
htmx logout tidy up (#2884)
This commit is contained in:
parent
d0e57442d2
commit
d7a5097527
|
@ -59,6 +59,7 @@ const EXPECT_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ClientError {
|
pub enum ClientError {
|
||||||
Unauthorized,
|
Unauthorized,
|
||||||
|
SessionExpired,
|
||||||
Http(reqwest::StatusCode, Option<OperationError>, String),
|
Http(reqwest::StatusCode, Option<OperationError>, String),
|
||||||
Transport(reqwest::Error),
|
Transport(reqwest::Error),
|
||||||
AuthenticationFailed,
|
AuthenticationFailed,
|
||||||
|
@ -633,10 +634,16 @@ impl KanidmClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn logout(&self) -> Result<(), ClientError> {
|
pub async fn logout(&self) -> Result<(), ClientError> {
|
||||||
self.perform_get_request("/v1/logout").await?;
|
match self.perform_get_request("/v1/logout").await {
|
||||||
let mut tguard = self.bearer_token.write().await;
|
Err(ClientError::Unauthorized)
|
||||||
*tguard = None;
|
| Err(ClientError::Http(reqwest::StatusCode::UNAUTHORIZED, _, _))
|
||||||
Ok(())
|
| Ok(()) => {
|
||||||
|
let mut tguard = self.bearer_token.write().await;
|
||||||
|
*tguard = None;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
e => e,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_token_cache_path(&self) -> String {
|
pub fn get_token_cache_path(&self) -> String {
|
||||||
|
|
|
@ -1662,6 +1662,13 @@ async fn test_server_user_auth_token_lifecycle(rsclient: KanidmClient) {
|
||||||
.await
|
.await
|
||||||
.expect("Failed to destroy user auth token");
|
.expect("Failed to destroy user auth token");
|
||||||
|
|
||||||
|
// The session is revoked server side, but we can still call logout locally
|
||||||
|
// and on the 401 it will just clear the token.
|
||||||
|
rsclient
|
||||||
|
.logout()
|
||||||
|
.await
|
||||||
|
.expect("Failed to remove local token");
|
||||||
|
|
||||||
// Since the session is revoked, check with the admin.
|
// Since the session is revoked, check with the admin.
|
||||||
let res = rsclient
|
let res = rsclient
|
||||||
.auth_simple_password(ADMIN_TEST_USER, ADMIN_TEST_PASSWORD)
|
.auth_simple_password(ADMIN_TEST_USER, ADMIN_TEST_PASSWORD)
|
||||||
|
|
Loading…
Reference in a new issue