1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-31 09:24:31 +03:00

storage: split the repository trait

This commit is contained in:
Quentin Gliech
2023-01-24 16:04:18 +01:00
parent 6a8c79c497
commit d14ca156ad
18 changed files with 401 additions and 308 deletions

View File

@ -31,7 +31,7 @@ use mas_http::HttpServiceExt;
use mas_iana::oauth::OAuthClientAuthenticationMethod;
use mas_jose::{jwk::PublicJsonWebKeySet, jwt::Jwt};
use mas_keystore::Encrypter;
use mas_storage::{oauth2::OAuth2ClientRepository, Repository};
use mas_storage::{oauth2::OAuth2ClientRepository, RepositoryAccess};
use serde::{de::DeserializeOwned, Deserialize};
use serde_json::Value;
use thiserror::Error;
@ -74,7 +74,7 @@ pub enum Credentials {
impl Credentials {
pub async fn fetch<E>(
&self,
repo: &mut (impl Repository<Error = E> + ?Sized),
repo: &mut (impl RepositoryAccess<Error = E> + ?Sized),
) -> Result<Option<Client>, E> {
let client_id = match self {
Credentials::None { client_id }

View File

@ -14,7 +14,7 @@
use axum_extra::extract::cookie::{Cookie, PrivateCookieJar};
use mas_data_model::BrowserSession;
use mas_storage::{user::BrowserSessionRepository, Repository};
use mas_storage::{user::BrowserSessionRepository, RepositoryAccess};
use serde::{Deserialize, Serialize};
use ulid::Ulid;
@ -45,7 +45,7 @@ impl SessionInfo {
/// Load the [`BrowserSession`] from database
pub async fn load_session<E>(
&self,
repo: &mut (impl Repository<Error = E> + ?Sized),
repo: &mut impl RepositoryAccess<Error = E>,
) -> Result<Option<BrowserSession>, E> {
let session_id = if let Some(id) = self.current {
id

View File

@ -29,7 +29,7 @@ use http::{header::WWW_AUTHENTICATE, HeaderMap, HeaderValue, Request, StatusCode
use mas_data_model::Session;
use mas_storage::{
oauth2::{OAuth2AccessTokenRepository, OAuth2SessionRepository},
Clock, Repository,
Clock, RepositoryAccess,
};
use serde::{de::DeserializeOwned, Deserialize};
use thiserror::Error;
@ -53,7 +53,7 @@ enum AccessToken {
impl AccessToken {
async fn fetch<E>(
&self,
repo: &mut (impl Repository<Error = E> + ?Sized),
repo: &mut impl RepositoryAccess<Error = E>,
) -> Result<(mas_data_model::AccessToken, Session), AuthorizationVerificationError<E>> {
let token = match self {
AccessToken::Form(t) | AccessToken::Header(t) => t,
@ -86,7 +86,7 @@ impl<F: Send> UserAuthorization<F> {
// TODO: take scopes to validate as parameter
pub async fn protected_form<E>(
self,
repo: &mut (impl Repository<Error = E> + ?Sized),
repo: &mut impl RepositoryAccess<Error = E>,
clock: &impl Clock,
) -> Result<(Session, F), AuthorizationVerificationError<E>> {
let form = match self.form {
@ -106,7 +106,7 @@ impl<F: Send> UserAuthorization<F> {
// TODO: take scopes to validate as parameter
pub async fn protected<E>(
self,
repo: &mut (impl Repository<Error = E> + ?Sized),
repo: &mut impl RepositoryAccess<Error = E>,
clock: &impl Clock,
) -> Result<Session, AuthorizationVerificationError<E>> {
let (token, session) = self.access_token.fetch(repo).await?;