Fix session disconnection issue by removing automatic refresh on client initialization
This commit is contained in:
@@ -3,15 +3,13 @@ use crate::matrix_connection::matrix_manager::MatrixManagerMsg;
|
|||||||
use crate::users::UserEmail;
|
use crate::users::UserEmail;
|
||||||
use crate::utils::rand_utils::rand_string;
|
use crate::utils::rand_utils::rand_string;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use matrix_sdk::authentication::oauth::error::{
|
use matrix_sdk::authentication::oauth::error::OAuthDiscoveryError;
|
||||||
BasicErrorResponseType, OAuthDiscoveryError, RequestTokenError,
|
|
||||||
};
|
|
||||||
use matrix_sdk::authentication::oauth::{
|
use matrix_sdk::authentication::oauth::{
|
||||||
ClientId, OAuthError, OAuthSession, UrlOrQuery, UserSession,
|
ClientId, OAuthError, OAuthSession, UrlOrQuery, UserSession,
|
||||||
};
|
};
|
||||||
use matrix_sdk::encryption::recovery::RecoveryState;
|
use matrix_sdk::encryption::recovery::RecoveryState;
|
||||||
use matrix_sdk::ruma::serde::Raw;
|
use matrix_sdk::ruma::serde::Raw;
|
||||||
use matrix_sdk::{Client, ClientBuildError, RefreshTokenError};
|
use matrix_sdk::{Client, ClientBuildError};
|
||||||
use ractor::ActorRef;
|
use ractor::ActorRef;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
@@ -161,20 +159,6 @@ impl MatrixClient {
|
|||||||
.encryption()
|
.encryption()
|
||||||
.wait_for_e2ee_initialization_tasks()
|
.wait_for_e2ee_initialization_tasks()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
// Force token refresh to make sure session is still alive, otherwise disconnect user
|
|
||||||
if let Err(refresh_error) = client.client.oauth().refresh_access_token().await {
|
|
||||||
if let RefreshTokenError::OAuth(e) = &refresh_error
|
|
||||||
&& let OAuthError::RefreshToken(RequestTokenError::ServerResponse(e)) = &**e
|
|
||||||
&& e.error() == &BasicErrorResponseType::InvalidGrant
|
|
||||||
{
|
|
||||||
log::warn!(
|
|
||||||
"Refresh token rejected by server, token must have been invalidated! {refresh_error}"
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
log::warn!("Failed to refresh token! {refresh_error}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Automatically save session when token gets refreshed
|
// Automatically save session when token gets refreshed
|
||||||
|
|||||||
@@ -116,14 +116,14 @@ pub struct BaseAPIToken {
|
|||||||
/// Restricted API network for token
|
/// Restricted API network for token
|
||||||
pub networks: Option<Vec<ipnet::IpNet>>,
|
pub networks: Option<Vec<ipnet::IpNet>>,
|
||||||
|
|
||||||
/// Read only access
|
|
||||||
pub read_only: bool,
|
|
||||||
|
|
||||||
/// Token max inactivity
|
/// Token max inactivity
|
||||||
pub max_inactivity: u32,
|
pub max_inactivity: u32,
|
||||||
|
|
||||||
/// Token expiration
|
/// Token expiration
|
||||||
pub expiration: Option<u64>,
|
pub expiration: Option<u64>,
|
||||||
|
|
||||||
|
/// Read only access
|
||||||
|
pub read_only: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BaseAPIToken {
|
impl BaseAPIToken {
|
||||||
|
|||||||
Reference in New Issue
Block a user