Added oauth2 OIDC support
This commit is contained in:
@@ -45,6 +45,22 @@ struct Args {
|
||||
/// Disable TLS encryption (not recommended, use only for debugging)
|
||||
#[arg(long, default_value_t = false)]
|
||||
no_tls: bool,
|
||||
|
||||
/// OIDC Issuer URL (e.g. https://auth.example.com/application/o/furumi/)
|
||||
#[arg(long, env = "FURUMI_OIDC_ISSUER_URL")]
|
||||
oidc_issuer_url: Option<String>,
|
||||
|
||||
/// OIDC Client ID
|
||||
#[arg(long, env = "FURUMI_OIDC_CLIENT_ID")]
|
||||
oidc_client_id: Option<String>,
|
||||
|
||||
/// OIDC Client Secret
|
||||
#[arg(long, env = "FURUMI_OIDC_CLIENT_SECRET")]
|
||||
oidc_client_secret: Option<String>,
|
||||
|
||||
/// OIDC Redirect URL (e.g. https://music.example.com/auth/callback)
|
||||
#[arg(long, env = "FURUMI_OIDC_REDIRECT_URL")]
|
||||
oidc_redirect_url: Option<String>,
|
||||
}
|
||||
|
||||
async fn metrics_handler() -> String {
|
||||
@@ -115,7 +131,27 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
eprintln!("Error: Invalid web bind address '{}': {}", args.web_bind, e);
|
||||
std::process::exit(1);
|
||||
});
|
||||
let web_app = web::build_router(root_path.clone(), args.token.clone());
|
||||
|
||||
// Initialize OIDC State if provided
|
||||
let oidc_state = if let (Some(issuer), Some(client_id), Some(secret), Some(redirect)) = (
|
||||
args.oidc_issuer_url,
|
||||
args.oidc_client_id,
|
||||
args.oidc_client_secret,
|
||||
args.oidc_redirect_url,
|
||||
) {
|
||||
println!("OIDC (SSO): enabled for web UI (issuer: {})", issuer);
|
||||
match web::auth::oidc_init(issuer, client_id, secret, redirect).await {
|
||||
Ok(state) => Some(Arc::new(state)),
|
||||
Err(e) => {
|
||||
eprintln!("Error initializing OIDC client: {}", e);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let web_app = web::build_router(root_path.clone(), args.token.clone(), oidc_state);
|
||||
let web_listener = tokio::net::TcpListener::bind(web_addr).await?;
|
||||
println!("Web player: http://{}", web_addr);
|
||||
tokio::spawn(async move {
|
||||
|
||||
Reference in New Issue
Block a user