1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-08-06 06:02:40 +03:00

storage: unify most oauth2 related errors

This commit is contained in:
Quentin Gliech
2022-12-07 20:11:49 +01:00
parent b7cad48bbd
commit 102571512e
15 changed files with 261 additions and 388 deletions

View File

@@ -27,7 +27,6 @@ use async_graphql::{
Context, Description, EmptyMutation, EmptySubscription, ID,
};
use mas_axum_utils::SessionInfo;
use mas_storage::LookupResultExt;
use sqlx::PgPool;
use self::model::{
@@ -96,9 +95,7 @@ impl RootQuery {
let database = ctx.data::<PgPool>()?;
let mut conn = database.acquire().await?;
let client = mas_storage::oauth2::client::lookup_client(&mut conn, id)
.await
.to_option()?;
let client = mas_storage::oauth2::client::lookup_client(&mut conn, id).await?;
Ok(client.map(OAuth2Client))
}

View File

@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use anyhow::Context as _;
use async_graphql::{Context, Description, Object, ID};
use mas_storage::oauth2::client::lookup_client;
use oauth2_types::scope::Scope;
@@ -114,7 +115,9 @@ impl OAuth2Consent {
/// OAuth 2.0 client for which the user granted access.
pub async fn client(&self, ctx: &Context<'_>) -> Result<OAuth2Client, async_graphql::Error> {
let mut conn = ctx.data::<PgPool>()?.acquire().await?;
let client = lookup_client(&mut conn, self.client_id).await?;
let client = lookup_client(&mut conn, self.client_id)
.await?
.context("Could not load client")?;
Ok(OAuth2Client(client))
}
}