1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-31 09:24:31 +03:00
This commit is contained in:
Quentin Gliech
2022-10-27 09:26:56 +02:00
parent b7c50b5403
commit 368a9282a1
4 changed files with 78 additions and 92 deletions

View File

@ -41,13 +41,6 @@ impl<S: StorageBackendMarker> From<AccessToken<S>> for AccessToken<()> {
}
}
impl<T: StorageBackend> AccessToken<T> {
// XXX
pub fn exp(&self) -> DateTime<Utc> {
self.expires_at
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct RefreshToken<T: StorageBackend> {
pub data: T::RefreshTokenData,

View File

@ -193,7 +193,6 @@ pub(crate) async fn post(
let reply = match token_type {
TokenType::AccessToken => {
let (token, session) = lookup_active_access_token(&mut conn, token).await?;
let exp = token.exp();
IntrospectionResponse {
active: true,
@ -201,7 +200,7 @@ pub(crate) async fn post(
client_id: Some(session.client.client_id),
username: Some(session.browser_session.user.username),
token_type: Some(OAuthTokenTypeHint::AccessToken),
exp: Some(exp),
exp: Some(token.expires_at),
iat: Some(token.created_at),
nbf: Some(token.created_at),
sub: Some(session.browser_session.user.sub),

View File

@ -110,22 +110,14 @@ impl AccessTokenLookupError {
}
}
// TODO: remove that manual async
#[allow(clippy::too_many_lines, clippy::manual_async_fn)]
pub fn lookup_active_access_token<'a, 'c, A>(
#[allow(clippy::too_many_lines)]
pub async fn lookup_active_access_token<'a, 'c, A>(
conn: A,
token: &'a str,
) -> impl std::future::Future<
Output = Result<
(AccessToken<PostgresqlBackend>, Session<PostgresqlBackend>),
AccessTokenLookupError,
>,
> + Send
+ 'a
) -> Result<(AccessToken<PostgresqlBackend>, Session<PostgresqlBackend>), AccessTokenLookupError>
where
A: Acquire<'c, Database = Postgres> + Send + 'a,
{
async move {
let mut conn = conn.acquire().await?;
let res = sqlx::query_as!(
OAuth2AccessTokenLookup,
@ -173,9 +165,10 @@ where
.fetch_one(&mut *conn)
.await?;
let id = Ulid::from(res.oauth2_access_token_id);
let access_token = AccessToken {
data: res.oauth2_access_token_id.into(),
jti: res.oauth2_access_token_id.to_string(),
data: id,
jti: id.to_string(),
access_token: res.oauth2_access_token,
created_at: res.oauth2_access_token_created_at,
expires_at: res.oauth2_access_token_expires_at,
@ -236,7 +229,6 @@ where
};
Ok((access_token, session))
}
}
#[tracing::instrument(

View File

@ -179,14 +179,16 @@ pub async fn lookup_active_refresh_token(
res.oauth2_access_token_expires_at,
) {
(None, None, None, None) => None,
(Some(id), Some(access_token), Some(created_at), Some(expires_at)) => Some(AccessToken {
data: id.into(),
// XXX: are we doing that everywhere?
jti: Ulid::from(id).to_string(),
(Some(id), Some(access_token), Some(created_at), Some(expires_at)) => {
let id = Ulid::from(id);
Some(AccessToken {
data: id,
jti: id.to_string(),
access_token,
created_at,
expires_at,
}),
})
}
_ => return Err(DatabaseInconsistencyError.into()),
};