1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-20 12:02:22 +03:00

storage: wrap the postgres repository in a struct

This commit is contained in:
Quentin Gliech
2023-01-13 18:03:37 +01:00
parent 488a666a8d
commit 195203823a
44 changed files with 505 additions and 548 deletions

View File

@@ -27,7 +27,7 @@ use mas_policy::PolicyFactory;
use mas_router::{PostAuthAction, Route};
use mas_storage::{
oauth2::{OAuth2AuthorizationGrantRepository, OAuth2ClientRepository},
Repository,
PgRepository, Repository,
};
use mas_templates::Templates;
use oauth2_types::{
@@ -139,10 +139,10 @@ pub(crate) async fn get(
Form(params): Form<Params>,
) -> Result<Response, RouteError> {
let (clock, mut rng) = crate::clock_and_rng();
let mut txn = pool.begin().await?;
let mut repo = PgRepository::from_pool(&pool).await?;
// First, figure out what client it is
let client = txn
let client = repo
.oauth2_client()
.find_by_client_id(&params.auth.client_id)
.await?
@@ -170,7 +170,7 @@ pub(crate) async fn get(
let templates = templates.clone();
let callback_destination = callback_destination.clone();
async move {
let maybe_session = session_info.load_session(&mut txn).await?;
let maybe_session = session_info.load_session(&mut repo).await?;
let prompt = params.auth.prompt.as_deref().unwrap_or_default();
// Check if the request/request_uri/registration params are used. If so, reply
@@ -275,7 +275,7 @@ pub(crate) async fn get(
let requires_consent = prompt.contains(&Prompt::Consent);
let grant = txn
let grant = repo
.oauth2_authorization_grant()
.add(
&mut rng,
@@ -302,7 +302,7 @@ pub(crate) async fn get(
}
None if prompt.contains(&Prompt::Create) => {
// Client asked for a registration, show the registration prompt
txn.commit().await?;
repo.save().await?;
mas_router::Register::and_then(continue_grant)
.go()
@@ -310,7 +310,7 @@ pub(crate) async fn get(
}
None => {
// Other cases where we don't have a session, ask for a login
txn.commit().await?;
repo.save().await?;
mas_router::Login::and_then(continue_grant)
.go()
@@ -323,7 +323,7 @@ pub(crate) async fn get(
|| prompt.contains(&Prompt::SelectAccount) =>
{
// TODO: better pages here
txn.commit().await?;
repo.save().await?;
mas_router::Reauth::and_then(continue_grant)
.go()
@@ -333,7 +333,7 @@ pub(crate) async fn get(
// Else, we immediately try to complete the authorization grant
Some(user_session) if prompt.contains(&Prompt::None) => {
// With prompt=none, we should get back to the client immediately
match self::complete::complete(grant, user_session, &policy_factory, txn).await
match self::complete::complete(grant, user_session, &policy_factory, repo).await
{
Ok(params) => callback_destination.go(&templates, params).await?,
Err(GrantCompletionError::RequiresConsent) => {
@@ -372,7 +372,7 @@ pub(crate) async fn get(
Some(user_session) => {
let grant_id = grant.id;
// Else, we show the relevant reauth/consent page if necessary
match self::complete::complete(grant, user_session, &policy_factory, txn).await
match self::complete::complete(grant, user_session, &policy_factory, repo).await
{
Ok(params) => callback_destination.go(&templates, params).await?,
Err(