You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-07-31 09:24:31 +03:00
Database refactoring
This commit is contained in:
@ -89,7 +89,7 @@ pub struct CompatSession<T: StorageBackend> {
|
||||
pub user: User<T>,
|
||||
pub device: Device,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub deleted_at: Option<DateTime<Utc>>,
|
||||
pub finished_at: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
impl<S: StorageBackendMarker> From<CompatSession<S>> for CompatSession<()> {
|
||||
@ -99,7 +99,7 @@ impl<S: StorageBackendMarker> From<CompatSession<S>> for CompatSession<()> {
|
||||
user: t.user.into(),
|
||||
device: t.device,
|
||||
created_at: t.created_at,
|
||||
deleted_at: t.deleted_at,
|
||||
finished_at: t.finished_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -144,12 +144,12 @@ impl<S: StorageBackendMarker> From<CompatRefreshToken<S>> for CompatRefreshToken
|
||||
#[serde(bound = "T: StorageBackend")]
|
||||
pub enum CompatSsoLoginState<T: StorageBackend> {
|
||||
Pending,
|
||||
Fullfilled {
|
||||
fullfilled_at: DateTime<Utc>,
|
||||
Fulfilled {
|
||||
fulfilled_at: DateTime<Utc>,
|
||||
session: CompatSession<T>,
|
||||
},
|
||||
Exchanged {
|
||||
fullfilled_at: DateTime<Utc>,
|
||||
fulfilled_at: DateTime<Utc>,
|
||||
exchanged_at: DateTime<Utc>,
|
||||
session: CompatSession<T>,
|
||||
},
|
||||
@ -159,19 +159,19 @@ impl<S: StorageBackendMarker> From<CompatSsoLoginState<S>> for CompatSsoLoginSta
|
||||
fn from(t: CompatSsoLoginState<S>) -> Self {
|
||||
match t {
|
||||
CompatSsoLoginState::Pending => Self::Pending,
|
||||
CompatSsoLoginState::Fullfilled {
|
||||
fullfilled_at,
|
||||
CompatSsoLoginState::Fulfilled {
|
||||
fulfilled_at,
|
||||
session,
|
||||
} => Self::Fullfilled {
|
||||
fullfilled_at,
|
||||
} => Self::Fulfilled {
|
||||
fulfilled_at,
|
||||
session: session.into(),
|
||||
},
|
||||
CompatSsoLoginState::Exchanged {
|
||||
fullfilled_at,
|
||||
fulfilled_at,
|
||||
exchanged_at,
|
||||
session,
|
||||
} => Self::Exchanged {
|
||||
fullfilled_at,
|
||||
fulfilled_at,
|
||||
exchanged_at,
|
||||
session: session.into(),
|
||||
},
|
||||
@ -185,7 +185,7 @@ pub struct CompatSsoLogin<T: StorageBackend> {
|
||||
#[serde(skip_serializing)]
|
||||
pub data: T::CompatSsoLoginData,
|
||||
pub redirect_uri: Url,
|
||||
pub token: String,
|
||||
pub login_token: String,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub state: CompatSsoLoginState<T>,
|
||||
}
|
||||
@ -195,7 +195,7 @@ impl<S: StorageBackendMarker> From<CompatSsoLogin<S>> for CompatSsoLogin<()> {
|
||||
Self {
|
||||
data: (),
|
||||
redirect_uri: t.redirect_uri,
|
||||
token: t.token,
|
||||
login_token: t.login_token,
|
||||
created_at: t.created_at,
|
||||
state: t.state.into(),
|
||||
}
|
||||
|
@ -171,7 +171,6 @@ pub struct AuthorizationGrant<T: StorageBackend> {
|
||||
pub state: Option<String>,
|
||||
pub nonce: Option<String>,
|
||||
pub max_age: Option<NonZeroU32>,
|
||||
pub acr_values: Option<String>,
|
||||
pub response_mode: ResponseMode,
|
||||
pub response_type_id_token: bool,
|
||||
pub created_at: DateTime<Utc>,
|
||||
@ -190,7 +189,6 @@ impl<S: StorageBackendMarker> From<AuthorizationGrant<S>> for AuthorizationGrant
|
||||
state: g.state,
|
||||
nonce: g.nonce,
|
||||
max_age: g.max_age,
|
||||
acr_values: g.acr_values,
|
||||
response_mode: g.response_mode,
|
||||
response_type_id_token: g.response_type_id_token,
|
||||
created_at: g.created_at,
|
||||
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use chrono::{DateTime, Duration, Utc};
|
||||
use chrono::{DateTime, Utc};
|
||||
use crc::{Crc, CRC_32_ISO_HDLC};
|
||||
use mas_iana::oauth::OAuthTokenTypeHint;
|
||||
use rand::{distributions::Alphanumeric, Rng};
|
||||
@ -24,9 +24,9 @@ use crate::traits::{StorageBackend, StorageBackendMarker};
|
||||
pub struct AccessToken<T: StorageBackend> {
|
||||
pub data: T::AccessTokenData,
|
||||
pub jti: String,
|
||||
pub token: String,
|
||||
pub expires_after: Duration,
|
||||
pub access_token: String,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub expires_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
impl<S: StorageBackendMarker> From<AccessToken<S>> for AccessToken<()> {
|
||||
@ -34,23 +34,24 @@ impl<S: StorageBackendMarker> From<AccessToken<S>> for AccessToken<()> {
|
||||
AccessToken {
|
||||
data: (),
|
||||
jti: t.jti,
|
||||
token: t.token,
|
||||
expires_after: t.expires_after,
|
||||
access_token: t.access_token,
|
||||
expires_at: t.expires_at,
|
||||
created_at: t.created_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: StorageBackend> AccessToken<T> {
|
||||
// XXX
|
||||
pub fn exp(&self) -> DateTime<Utc> {
|
||||
self.created_at + self.expires_after
|
||||
self.expires_at
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct RefreshToken<T: StorageBackend> {
|
||||
pub data: T::RefreshTokenData,
|
||||
pub token: String,
|
||||
pub refresh_token: String,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub access_token: Option<AccessToken<T>>,
|
||||
}
|
||||
@ -59,7 +60,7 @@ impl<S: StorageBackendMarker> From<RefreshToken<S>> for RefreshToken<()> {
|
||||
fn from(t: RefreshToken<S>) -> Self {
|
||||
RefreshToken {
|
||||
data: (),
|
||||
token: t.token,
|
||||
refresh_token: t.refresh_token,
|
||||
created_at: t.created_at,
|
||||
access_token: t.access_token.map(Into::into),
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ where
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
|
||||
pub enum UserEmailVerificationState {
|
||||
AlreadyUsed { when: DateTime<Utc> },
|
||||
Expired,
|
||||
Expired { when: DateTime<Utc> },
|
||||
Valid,
|
||||
}
|
||||
|
||||
@ -200,7 +200,9 @@ where
|
||||
UserEmailVerificationState::AlreadyUsed {
|
||||
when: Utc::now() - Duration::minutes(5),
|
||||
},
|
||||
UserEmailVerificationState::Expired,
|
||||
UserEmailVerificationState::Expired {
|
||||
when: Utc::now() - Duration::hours(5),
|
||||
},
|
||||
UserEmailVerificationState::Valid,
|
||||
];
|
||||
|
||||
|
Reference in New Issue
Block a user