aboutsummaryrefslogtreecommitdiffstats
path: root/crates/api-auth
diff options
context:
space:
mode:
authorrtkay123 <dev@kanjala.com>2026-04-12 12:54:36 +0200
committerrtkay123 <dev@kanjala.com>2026-04-12 12:54:36 +0200
commit34b2f8ff6a99471fbb72ed7c52a92b92645b0652 (patch)
tree214e46b91aa63234e7fa033de7001d70d06c1f46 /crates/api-auth
parentb7c123490a1dad28c84960f00fe206fd8b43f0d4 (diff)
downloadsellershut-34b2f8ff6a99471fbb72ed7c52a92b92645b0652.tar.bz2
sellershut-34b2f8ff6a99471fbb72ed7c52a92b92645b0652.zip
fix: clippy
Diffstat (limited to 'crates/api-auth')
-rw-r--r--crates/api-auth/src/discord/mod.rs11
-rw-r--r--crates/api-auth/src/util.rs52
2 files changed, 31 insertions, 32 deletions
diff --git a/crates/api-auth/src/discord/mod.rs b/crates/api-auth/src/discord/mod.rs
index 43a62bf..ffa5a68 100644
--- a/crates/api-auth/src/discord/mod.rs
+++ b/crates/api-auth/src/discord/mod.rs
@@ -1,15 +1,10 @@
use api_core::models::user::User;
-use async_session::{Session, serde_json};
use async_trait::async_trait;
-use oauth2::{AuthorizationCode, CsrfToken, TokenResponse};
-use redis::AsyncCommands;
use serde::{Deserialize, Serialize};
-use sh_util::cache::{CacheKey, RedisManager};
+use sh_util::cache::RedisManager;
use sqlx::PgPool;
-use crate::{
- BasicClient, CSRF_TOKEN, OauthDriver, SessionResponse, client::AuthHttpClient, error::AuthError,
-};
+use crate::{BasicClient, OauthDriver, SessionResponse, client::AuthHttpClient, error::AuthError};
// The user data we'll get back from Discord.
// https://discord.com/developers/docs/resources/user#user-object-user-structure
@@ -72,7 +67,7 @@ impl OauthDriver for AuthServiceDiscord {
crate::util::create_oauth_session(&self.client, &self.cache, &["identify", "email"]).await
}
- async fn save_session(&self, user: &User) -> Result<(), AuthError> {
+ async fn save_session(&self, _user: &User) -> Result<(), AuthError> {
todo!()
}
}
diff --git a/crates/api-auth/src/util.rs b/crates/api-auth/src/util.rs
index 0893bd5..b15a5e2 100644
--- a/crates/api-auth/src/util.rs
+++ b/crates/api-auth/src/util.rs
@@ -2,7 +2,7 @@ use api_core::models::user::User;
use async_session::{Session, serde_json};
use oauth2::{AuthorizationCode, CsrfToken, Scope, TokenResponse};
use redis::AsyncCommands;
-use serde::{Deserialize, de::DeserializeOwned};
+use serde::de::DeserializeOwned;
use sh_util::cache::{CacheKey, RedisManager};
use crate::{BasicClient, CSRF_TOKEN, SessionResponse, client::AuthHttpClient, error::AuthError};
@@ -44,7 +44,7 @@ pub async fn get_user<T>(
c: &BasicClient,
client: &AuthHttpClient,
code: &str,
- endpoint: &str,
+ _endpoint: &str,
) -> Result<User, AuthError>
where
User: TryFrom<T>,
@@ -71,33 +71,37 @@ where
User::try_from(user_data).map_err(|_e| AuthError::UserDeserialisation)
}
- pub async fn validate_session(cache: &RedisManager, cookie: &str, state: &str) -> Result<(), AuthError> {
- let id = Session::id_from_cookie_value(cookie)?;
- let cache_key = CacheKey::Session(&id);
- let mut cache = cache.get().await.unwrap();
- let session = cache.get::<_, String>(&cache_key).await?;
- let session: Session =
- serde_json::from_str(&session).map_err(|_e| AuthError::InvalidSession)?;
+pub async fn validate_session(
+ cache: &RedisManager,
+ cookie: &str,
+ state: &str,
+) -> Result<(), AuthError> {
+ let id = Session::id_from_cookie_value(cookie)?;
+ let cache_key = CacheKey::Session(&id);
+ let mut cache = cache.get().await.unwrap();
+ let session = cache.get::<_, String>(&cache_key).await?;
+ let session: Session =
+ serde_json::from_str(&session).map_err(|_e| AuthError::InvalidSession)?;
- match session.validate() {
- Some(session) => {
- // Extract the CSRF token from the session
- let stored_csrf_token = session.get::<CsrfToken>(CSRF_TOKEN);
+ match session.validate() {
+ Some(session) => {
+ // Extract the CSRF token from the session
+ let stored_csrf_token = session.get::<CsrfToken>(CSRF_TOKEN);
- if let Some(stored) = stored_csrf_token {
- // Cleanup the CSRF token session
- cache.del::<_, ()>(cache_key).await?;
+ if let Some(stored) = stored_csrf_token {
+ // Cleanup the CSRF token session
+ cache.del::<_, ()>(cache_key).await?;
- // Validate CSRF token is the same as the one in the auth request
- if *stored.secret() != state {
- Err(AuthError::TokenMismatch)
- } else {
- Ok(())
- }
+ // Validate CSRF token is the same as the one in the auth request
+ if *stored.secret() != state {
+ Err(AuthError::TokenMismatch)
} else {
- Err(AuthError::NoCSRFToken)
+ Ok(())
}
+ } else {
+ Err(AuthError::NoCSRFToken)
}
- None => Err(AuthError::MissingSession),
}
+ None => Err(AuthError::MissingSession),
}
+}