You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-11-20 12:02:22 +03:00
storage: unify the compat login errors
This commit is contained in:
@@ -22,10 +22,7 @@ use mas_data_model::{TokenFormatError, TokenType};
|
||||
use mas_iana::oauth::{OAuthClientAuthenticationMethod, OAuthTokenTypeHint};
|
||||
use mas_keystore::Encrypter;
|
||||
use mas_storage::{
|
||||
compat::{
|
||||
lookup_active_compat_access_token, lookup_active_compat_refresh_token,
|
||||
CompatAccessTokenLookupError, CompatRefreshTokenLookupError,
|
||||
},
|
||||
compat::{lookup_active_compat_access_token, lookup_active_compat_refresh_token},
|
||||
oauth2::{
|
||||
access_token::{lookup_active_access_token, AccessTokenLookupError},
|
||||
client::ClientFetchError,
|
||||
@@ -37,6 +34,8 @@ use oauth2_types::requests::{IntrospectionRequest, IntrospectionResponse};
|
||||
use sqlx::PgPool;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::impl_from_error_for_route;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum RouteError {
|
||||
#[error(transparent)]
|
||||
@@ -79,11 +78,8 @@ impl IntoResponse for RouteError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<sqlx::Error> for RouteError {
|
||||
fn from(e: sqlx::Error) -> Self {
|
||||
Self::Internal(Box::new(e))
|
||||
}
|
||||
}
|
||||
impl_from_error_for_route!(sqlx::Error);
|
||||
impl_from_error_for_route!(mas_storage::DatabaseError);
|
||||
|
||||
impl From<TokenFormatError> for RouteError {
|
||||
fn from(_e: TokenFormatError) -> Self {
|
||||
@@ -111,16 +107,6 @@ impl From<AccessTokenLookupError> for RouteError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CompatAccessTokenLookupError> for RouteError {
|
||||
fn from(e: CompatAccessTokenLookupError) -> Self {
|
||||
if e.not_found() {
|
||||
Self::UnknownToken
|
||||
} else {
|
||||
Self::Internal(Box::new(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RefreshTokenLookupError> for RouteError {
|
||||
fn from(e: RefreshTokenLookupError) -> Self {
|
||||
if e.not_found() {
|
||||
@@ -131,16 +117,6 @@ impl From<RefreshTokenLookupError> for RouteError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CompatRefreshTokenLookupError> for RouteError {
|
||||
fn from(e: CompatRefreshTokenLookupError) -> Self {
|
||||
if e.not_found() {
|
||||
Self::UnknownToken
|
||||
} else {
|
||||
Self::Internal(Box::new(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const INACTIVE: IntrospectionResponse = IntrospectionResponse {
|
||||
active: false,
|
||||
scope: None,
|
||||
@@ -232,8 +208,9 @@ pub(crate) async fn post(
|
||||
}
|
||||
}
|
||||
TokenType::CompatAccessToken => {
|
||||
let (token, session) =
|
||||
lookup_active_compat_access_token(&mut conn, &clock, token).await?;
|
||||
let (token, session) = lookup_active_compat_access_token(&mut conn, &clock, token)
|
||||
.await?
|
||||
.ok_or(RouteError::UnknownToken)?;
|
||||
|
||||
let device_scope = session.device.to_scope_token();
|
||||
let scope = [device_scope].into_iter().collect();
|
||||
@@ -255,7 +232,9 @@ pub(crate) async fn post(
|
||||
}
|
||||
TokenType::CompatRefreshToken => {
|
||||
let (refresh_token, _access_token, session) =
|
||||
lookup_active_compat_refresh_token(&mut conn, token).await?;
|
||||
lookup_active_compat_refresh_token(&mut conn, token)
|
||||
.await?
|
||||
.ok_or(RouteError::UnknownToken)?;
|
||||
|
||||
let device_scope = session.device.to_scope_token();
|
||||
let scope = [device_scope].into_iter().collect();
|
||||
|
||||
Reference in New Issue
Block a user