Skip to content

Commit

Permalink
rm askama_axum
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Nov 29, 2024
1 parent c45449e commit f6ce62a
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 194 deletions.
249 changes: 104 additions & 145 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ members = [
resolver = "2"

[workspace.dependencies]
askama = { version = "0.12.1", default-features = false, features = [
"with-axum",
] }
askama = { version = "0.12.1", default-features = false }
asynk-strim = "0.1.2"
clap = { version = "4.5.21", features = ["derive", "wrap_help"] }
diesel = { version = "2.2.5", default-features = false, features = [
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-derive/impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0.92"
quote = "1.0.37"
syn = { version = "2.0.89", features = ["full"] }
syn = { version = "2.0.90", features = ["full"] }

[lints]
workspace = true
4 changes: 0 additions & 4 deletions crates/kitsune-email/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ edition.workspace = true
version.workspace = true
license.workspace = true

[package.metadata.cargo-machete]
ignored = ["askama_axum"] # See reason below.

[dependencies]
askama.workspace = true
askama_axum = "0.4.0" # Damn it, cargo. Because "kitsune" uses "askama" with the axum feature, we have to have the crate available here as well..
diesel.workspace = true
diesel-async.workspace = true
kitsune-db.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions crates/kitsune-observability/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ opentelemetry_sdk = { version = "0.27.1", default-features = false, features = [
"rt-tokio",
] }
tracing = "0.1.41"
tracing-error = "0.2.0"
tracing-error = "0.2.1"
tracing-opentelemetry = { version = "0.28.0", default-features = false }
tracing-subscriber = "0.3.18"
tracing-subscriber = "0.3.19"

[lints]
workspace = true
2 changes: 1 addition & 1 deletion crates/kitsune-wasm-mrf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bytes = "1.9.0"
tempfile = "3.14.0"
tokio = { workspace = true, features = ["macros", "rt"] }
tower = "0.5.1"
tracing-subscriber = "0.3.18"
tracing-subscriber = "0.3.19"
wat = "1.221.0"

[lints]
Expand Down
2 changes: 1 addition & 1 deletion kitsune-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ kitsune-error.workspace = true
serde = { version = "1.0.215", features = ["derive"] }
speedy-uuid.workspace = true
tokio = { workspace = true, features = ["full"] }
tracing-subscriber = "0.3.18"
tracing-subscriber = "0.3.19"

[lints]
workspace = true
16 changes: 10 additions & 6 deletions kitsune/src/http/handler/oauth/authorize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ pub struct LoginForm {
password: String,
}

#[derive(Serialize)]
pub struct LoginPage {
flash_messages: IncomingFlashes,
}

#[debug_handler(state = crate::state::Zustand)]
pub async fn get(
#[cfg(feature = "oidc")] (State(oidc_service), Query(query)): (
Expand Down Expand Up @@ -91,7 +86,16 @@ pub async fn get(
users::table.find(id).get_result(db_conn).await
})?
} else {
return Ok(Either3::E2(LoginPage { flash_messages }));
let messages: Vec<(axum_flash::Level, &str)> = flash_messages.into_iter().collect();
let page = crate::template::render(
"oauth/login.html",
minijinja::context! {
flash_messages => messages,
},
)
.unwrap();

return Ok(Either3::E2(Html(page)));
};

let solicitor = OAuthOwnerSolicitor::builder()
Expand Down
15 changes: 4 additions & 11 deletions kitsune/src/oauth2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ pub struct CreateApp {
redirect_uris: String,
}

#[derive(Serialize)]
struct ShowTokenPage {
app_name: String,
domain: String,
token: String,
}

#[kitsune_service]
pub struct OAuth2Service {
db_pool: PgPool,
Expand Down Expand Up @@ -138,10 +131,10 @@ impl OAuth2Service {
if application.redirect_uri == SHOW_TOKEN_URI {
let page = crate::template::render(
"oauth/token.html",
&ShowTokenPage {
app_name: application.name,
domain: self.url_service.domain().into(),
token: authorization_code.code,
minijinja::context! {
app_name => application.name,
domain => self.url_service.domain(),
token => authorization_code.code,
},
)
.unwrap();
Expand Down
29 changes: 12 additions & 17 deletions kitsune/src/oauth2/solicitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,11 @@ use kitsune_error::Result;
use oxide_auth::endpoint::{OAuthError, OwnerConsent, QueryParameter, Solicitation, WebRequest};
use oxide_auth_async::endpoint::OwnerSolicitor;
use oxide_auth_axum::{OAuthRequest, OAuthResponse, WebError};
use serde::Serialize;
use speedy_uuid::Uuid;
use std::{borrow::Cow, str::FromStr};
use trials::attempt;
use typed_builder::TypedBuilder;

#[derive(Serialize)]
struct ConsentPage<'a> {
authenticated_username: &'a str,
app_name: &'a str,
csrf_token: &'a str,
query: PageQueryParams,
scopes: &'a [OAuthScope],
}

#[derive(Serialize)]
struct PageQueryParams {
client_id: String,
csrf_token: Option<String>,
Expand Down Expand Up @@ -109,12 +98,18 @@ impl OAuthOwnerSolicitor {

let body = crate::template::render(
"oauth/consent.html",
&ConsentPage {
authenticated_username: &self.authenticated_user.username,
app_name: &app_name,
csrf_token: csrf_token.as_str(),
query,
scopes: &scopes,
minijinja::context! {
authenticated_username => &self.authenticated_user.username,
app_name => &app_name,
csrf_token => csrf_token.as_str(),
query => minijinja::context! {
client_id => query.client_id,
redirect_uri => query.redirect_uri,
response_type => query.response_type,
scope => query.scope,
state => query.state.as_deref().unwrap_or(""),
},
scopes => &scopes,
},
)
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions lib/athena/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ redis = ["dep:either", "dep:fred", "dep:rand", "dep:sonic-rs"]

[dev-dependencies]
kitsune-test.workspace = true
postcard = { version = "1.1.0", default-features = false, features = ["alloc"] }
tracing-subscriber = "0.3.18"
postcard = { version = "1.1.1", default-features = false, features = ["alloc"] }
tracing-subscriber = "0.3.19"

[lints]
workspace = true
2 changes: 1 addition & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ argh = "0.1.12"
eyre = "0.6.12"
sonic-rs.workspace = true
tracing = { version = "0.1.41", default-features = false }
tracing-subscriber = { version = "0.3.18", default-features = false, features = [
tracing-subscriber = { version = "0.3.19", default-features = false, features = [
"ansi",
"fmt",
] }
Expand Down

0 comments on commit f6ce62a

Please sign in to comment.