You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-08-07 17:03:01 +03:00
Cleanups
This commit is contained in:
@@ -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)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct RefreshToken<T: StorageBackend> {
|
pub struct RefreshToken<T: StorageBackend> {
|
||||||
pub data: T::RefreshTokenData,
|
pub data: T::RefreshTokenData,
|
||||||
|
@@ -193,7 +193,6 @@ pub(crate) async fn post(
|
|||||||
let reply = match token_type {
|
let reply = match token_type {
|
||||||
TokenType::AccessToken => {
|
TokenType::AccessToken => {
|
||||||
let (token, session) = lookup_active_access_token(&mut conn, token).await?;
|
let (token, session) = lookup_active_access_token(&mut conn, token).await?;
|
||||||
let exp = token.exp();
|
|
||||||
|
|
||||||
IntrospectionResponse {
|
IntrospectionResponse {
|
||||||
active: true,
|
active: true,
|
||||||
@@ -201,7 +200,7 @@ pub(crate) async fn post(
|
|||||||
client_id: Some(session.client.client_id),
|
client_id: Some(session.client.client_id),
|
||||||
username: Some(session.browser_session.user.username),
|
username: Some(session.browser_session.user.username),
|
||||||
token_type: Some(OAuthTokenTypeHint::AccessToken),
|
token_type: Some(OAuthTokenTypeHint::AccessToken),
|
||||||
exp: Some(exp),
|
exp: Some(token.expires_at),
|
||||||
iat: Some(token.created_at),
|
iat: Some(token.created_at),
|
||||||
nbf: Some(token.created_at),
|
nbf: Some(token.created_at),
|
||||||
sub: Some(session.browser_session.user.sub),
|
sub: Some(session.browser_session.user.sub),
|
||||||
|
@@ -110,22 +110,14 @@ impl AccessTokenLookupError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove that manual async
|
#[allow(clippy::too_many_lines)]
|
||||||
#[allow(clippy::too_many_lines, clippy::manual_async_fn)]
|
pub async fn lookup_active_access_token<'a, 'c, A>(
|
||||||
pub fn lookup_active_access_token<'a, 'c, A>(
|
|
||||||
conn: A,
|
conn: A,
|
||||||
token: &'a str,
|
token: &'a str,
|
||||||
) -> impl std::future::Future<
|
) -> Result<(AccessToken<PostgresqlBackend>, Session<PostgresqlBackend>), AccessTokenLookupError>
|
||||||
Output = Result<
|
|
||||||
(AccessToken<PostgresqlBackend>, Session<PostgresqlBackend>),
|
|
||||||
AccessTokenLookupError,
|
|
||||||
>,
|
|
||||||
> + Send
|
|
||||||
+ 'a
|
|
||||||
where
|
where
|
||||||
A: Acquire<'c, Database = Postgres> + Send + 'a,
|
A: Acquire<'c, Database = Postgres> + Send + 'a,
|
||||||
{
|
{
|
||||||
async move {
|
|
||||||
let mut conn = conn.acquire().await?;
|
let mut conn = conn.acquire().await?;
|
||||||
let res = sqlx::query_as!(
|
let res = sqlx::query_as!(
|
||||||
OAuth2AccessTokenLookup,
|
OAuth2AccessTokenLookup,
|
||||||
@@ -173,9 +165,10 @@ where
|
|||||||
.fetch_one(&mut *conn)
|
.fetch_one(&mut *conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
let id = Ulid::from(res.oauth2_access_token_id);
|
||||||
let access_token = AccessToken {
|
let access_token = AccessToken {
|
||||||
data: res.oauth2_access_token_id.into(),
|
data: id,
|
||||||
jti: res.oauth2_access_token_id.to_string(),
|
jti: id.to_string(),
|
||||||
access_token: res.oauth2_access_token,
|
access_token: res.oauth2_access_token,
|
||||||
created_at: res.oauth2_access_token_created_at,
|
created_at: res.oauth2_access_token_created_at,
|
||||||
expires_at: res.oauth2_access_token_expires_at,
|
expires_at: res.oauth2_access_token_expires_at,
|
||||||
@@ -237,7 +230,6 @@ where
|
|||||||
|
|
||||||
Ok((access_token, session))
|
Ok((access_token, session))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(
|
#[tracing::instrument(
|
||||||
skip_all,
|
skip_all,
|
||||||
|
@@ -179,14 +179,16 @@ pub async fn lookup_active_refresh_token(
|
|||||||
res.oauth2_access_token_expires_at,
|
res.oauth2_access_token_expires_at,
|
||||||
) {
|
) {
|
||||||
(None, None, None, None) => None,
|
(None, None, None, None) => None,
|
||||||
(Some(id), Some(access_token), Some(created_at), Some(expires_at)) => Some(AccessToken {
|
(Some(id), Some(access_token), Some(created_at), Some(expires_at)) => {
|
||||||
data: id.into(),
|
let id = Ulid::from(id);
|
||||||
// XXX: are we doing that everywhere?
|
Some(AccessToken {
|
||||||
jti: Ulid::from(id).to_string(),
|
data: id,
|
||||||
|
jti: id.to_string(),
|
||||||
access_token,
|
access_token,
|
||||||
created_at,
|
created_at,
|
||||||
expires_at,
|
expires_at,
|
||||||
}),
|
})
|
||||||
|
}
|
||||||
_ => return Err(DatabaseInconsistencyError.into()),
|
_ => return Err(DatabaseInconsistencyError.into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user