feat: added auth by api key
This commit is contained in:
@@ -13,6 +13,7 @@ pub struct AppState {
|
||||
#[allow(dead_code)]
|
||||
pub storage_dir: Arc<PathBuf>,
|
||||
pub oidc: Option<Arc<auth::OidcState>>,
|
||||
pub api_key: Option<String>,
|
||||
}
|
||||
|
||||
pub fn build_router(state: Arc<AppState>) -> Router {
|
||||
@@ -32,9 +33,9 @@ pub fn build_router(state: Arc<AppState>) -> Router {
|
||||
.route("/", get(player_html))
|
||||
.nest("/api", library);
|
||||
|
||||
let has_oidc = state.oidc.is_some();
|
||||
let requires_auth = state.oidc.is_some();
|
||||
|
||||
let app = if has_oidc {
|
||||
let app = if requires_auth {
|
||||
authed
|
||||
.route_layer(middleware::from_fn_with_state(state.clone(), auth::require_auth))
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user