Skip to content

Commit 848a797

Browse files
committed
fix warnings
Aside from style, also fix an error found by clippy: I was not actually looping over all authorization headers but instead only checked the first values. Now I ignore other schemes that might also be present.
1 parent 253986a commit 848a797

File tree

3 files changed

+30
-38
lines changed

3 files changed

+30
-38
lines changed

bouncy_backend/src/auth.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
//!
1111
//! Guest users can be authenticated by a client secret included in the body as JSON.
1212
13-
use crate::AppState;
14-
use axum::response::{IntoResponse, Redirect, Response};
15-
use axum::{extract::State, http::StatusCode};
16-
use axum_oidc::{EmptyAdditionalClaims, OidcClaims};
13+
// use crate::AppState;
14+
// use axum::response::{IntoResponse, Redirect, Response};
15+
// use axum::{extract::State, http::StatusCode};
16+
use axum_oidc::EmptyAdditionalClaims;
1717
use serde::{Deserialize, Serialize};
1818

1919
pub(crate) type AdditionalClaims = EmptyAdditionalClaims;
@@ -26,19 +26,19 @@ struct TokenResponse {
2626
token_type: String,
2727
}
2828

29-
/// Calling this will redirect to Keyloak, have the user log in and then
30-
/// redirect back to the PWA domain.
31-
pub async fn oauth_callback(
32-
claims: OidcClaims<AdditionalClaims>,
33-
State(state): State<AppState>,
34-
) -> Response {
35-
// The main checks are done in the OIDC middleware.
36-
// Here we just add additional checks.
37-
if !claims.email_verified().unwrap_or_default() {
38-
return (StatusCode::FORBIDDEN, "email not verified").into_response();
39-
}
29+
// /// Calling this will redirect to Keyloak, have the user log in and then
30+
// /// redirect back to the PWA domain.
31+
// pub async fn oauth_callback(
32+
// claims: OidcClaims<AdditionalClaims>,
33+
// State(state): State<AppState>,
34+
// ) -> Response {
35+
// // The main checks are done in the OIDC middleware.
36+
// // Here we just add additional checks.
37+
// if !claims.email_verified().unwrap_or_default() {
38+
// return (StatusCode::FORBIDDEN, "email not verified").into_response();
39+
// }
4040

41-
// Redirect to the PWA frontend if login was successful
42-
// TODO: redirect to the exact same page the user was on before
43-
Redirect::to(&state.app_url).into_response()
44-
}
41+
// // Redirect to the PWA frontend if login was successful
42+
// // TODO: redirect to the exact same page the user was on before
43+
// Redirect::to(&state.app_url).into_response()
44+
// }

bouncy_backend/src/main.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
use auth::AdditionalClaims;
2-
use axum::error_handling::HandleErrorLayer;
31
use axum::http::header;
4-
use axum::http::{HeaderValue, Method, StatusCode, Uri};
5-
use axum::response::IntoResponse;
2+
use axum::http::{HeaderValue, Method, StatusCode};
63
use axum::routing::{get, post};
74
use axum::{middleware, Router};
8-
use axum_oidc::error::MiddlewareError;
9-
use axum_oidc::OidcAuthLayer;
105
use sqlx::PgPool;
116
use tokio::net::TcpListener;
127
use tower::ServiceBuilder;
138
use tower_http::cors::AllowOrigin;
14-
use tower_sessions::cookie::time::Duration;
15-
use tower_sessions::cookie::SameSite;
16-
use tower_sessions::{Expiry, MemoryStore, SessionManagerLayer};
179

1810
mod auth;
1911
mod client_session;
@@ -29,11 +21,11 @@ struct AppState {
2921

3022
#[tokio::main]
3123
async fn main() -> anyhow::Result<()> {
32-
let api_url = require_env("API_URL");
24+
// let api_url = require_env("API_URL");
3325
let app_url = require_env("CLIENT_URL");
34-
let oidc_issuer = require_env("OIDC_ISSUER");
35-
let oidc_client_id = require_env("OIDC_CLIENT_ID");
36-
let oidc_client_secret = require_env("OIDC_CLIENT_SECRET");
26+
// let oidc_issuer = require_env("OIDC_ISSUER");
27+
// let oidc_client_id = require_env("OIDC_CLIENT_ID");
28+
// let oidc_client_secret = require_env("OIDC_CLIENT_SECRET");
3729
let db_url = require_env("DATABASE_URL");
3830

3931
let pg_db_pool = PgPool::connect(&db_url).await?;
@@ -74,7 +66,7 @@ async fn main() -> anyhow::Result<()> {
7466

7567
let user_service = middleware::from_fn_with_state(state.clone(), user2::user_lookup);
7668

77-
let parsed_api_url = Uri::from_maybe_shared(api_url).expect("valid api url");
69+
// let parsed_api_url = Uri::from_maybe_shared(api_url).expect("valid api url");
7870
let auth_service = ServiceBuilder::new()
7971
// .layer(HandleErrorLayer::new(|e: MiddlewareError| async {
8072
// e.into_response()

bouncy_backend/src/user2.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub async fn user_lookup(
2626
next: Next,
2727
) -> Response {
2828
let auth_headers = &req.headers().get_all("Authorization");
29-
match try_get_user(&state, &auth_headers, maybe_claims).await {
29+
match try_get_user(&state, auth_headers, maybe_claims).await {
3030
Ok(user_id) => {
3131
// Attach user ID for downstream handlers
3232
req.extensions_mut().insert(user_id);
@@ -47,7 +47,7 @@ async fn try_get_user(
4747
{
4848
let maybe_user =
4949
user_lookup_by_client_secret(state, client_session_id, client_session_secret).await;
50-
maybe_user.ok_or_else(|| auth_error_response::<UserId>("User not found"))
50+
maybe_user.ok_or_else(|| auth_error_response("User not found"))
5151
} else if let Some(claims) = maybe_claims {
5252
// this will lazily create the user if necessary
5353
Ok(user_lookup_by_oidc(state, claims).await)
@@ -69,7 +69,7 @@ fn client_session_credentials_from_headers(
6969
};
7070

7171
if !str_auth_value.starts_with(prefix) {
72-
return auth_error("Invalid auth scheme");
72+
continue;
7373
}
7474

7575
let rest = &str_auth_value[prefix.len()..];
@@ -158,10 +158,10 @@ pub async fn user_info(
158158
}
159159

160160
fn auth_error<T>(msg: &'static str) -> Result<T, Response> {
161-
Err(auth_error_response::<T>(msg))
161+
Err(auth_error_response(msg))
162162
}
163163

164-
fn auth_error_response<T>(msg: &'static str) -> Response {
164+
fn auth_error_response(msg: &'static str) -> Response {
165165
Response::builder()
166166
.status(StatusCode::UNAUTHORIZED)
167167
.body(msg.into())

0 commit comments

Comments
 (0)