[WIP] feat: scoped api keys

This commit is contained in:
Iris System 2025-08-17 02:47:01 -07:00
parent e7ee593a85
commit 06cb160f95
45 changed files with 1264 additions and 154 deletions

View file

@ -6,6 +6,7 @@ edition = "2021"
[dependencies]
anyhow = { workspace = true }
fred = { workspace = true }
jsonwebtoken = { workspace = true }
lazy_static = { workspace = true }
metrics = { workspace = true }
pk_macros = { path = "../macros" }

View file

@ -62,6 +62,11 @@ pub struct ApiConfig {
#[serde(default)]
pub temp_token2: Option<String>,
pub token_privatekey: String,
pub token_publickey: String,
pub internal_request_secret: String,
}
#[derive(Deserialize, Clone, Debug)]

View file

@ -1,3 +1,5 @@
use uuid::Uuid;
pub async fn legacy_token_auth(
pool: &sqlx::postgres::PgPool,
token: &str,
@ -18,3 +20,24 @@ pub async fn legacy_token_auth(
struct LegacyTokenDbResponse {
id: i32,
}
pub async fn app_token_auth(
pool: &sqlx::postgres::PgPool,
token: &str,
) -> anyhow::Result<Option<Uuid>> {
let mut app: Vec<AppTokenDbResponse> =
sqlx::query_as("select id from external_apps where api_rl_token = $1")
.bind(token)
.fetch_all(pool)
.await?;
Ok(if let Some(app) = app.pop() {
Some(app.id)
} else {
None
})
}
#[derive(sqlx::FromRow)]
struct AppTokenDbResponse {
id: Uuid,
}