kych

OAuth 2.0 API for Swiyu to enable Taler integration of Swiyu for KYC (experimental)
Log | Files | Refs | README | LICENSE

main.rs (1540B)


      1 use axum::{
      2     Router,
      3     routing::{get, post},
      4 };
      5 use clap::Parser;
      6 use kych_oauth2_gateway_lib::{
      7     config::{CONFIG_SOURCE, Config},
      8     db, handlers,
      9     state::AppState,
     10 };
     11 use taler_config::{CommonArgs, serve::serve, taler_main};
     12 use tower_http::services::ServeDir;
     13 
     14 #[derive(Parser, Debug)]
     15 #[command(version, about = "OAuth 2.0 gateway for SWIYU credential verification")]
     16 struct Args {
     17     #[command(flatten)]
     18     common: CommonArgs,
     19 }
     20 
     21 fn main() {
     22     let args = Args::parse();
     23 
     24     taler_main(CONFIG_SOURCE, args.common, async |cfg| {
     25         tracing::info!(target: "kych", "Starting KyCH OAuth2 gateway v{}", env!("CARGO_PKG_VERSION"));
     26 
     27         let config = Config::parse(cfg)?;
     28         let pool = db::create_pool(config.database.clone()).await?;
     29         let listen = config.serve.clone();
     30         let state = AppState::new(config, pool);
     31 
     32         let app = Router::new()
     33             .route("/config", get(handlers::config))
     34             .route("/setup/{client_id}", post(handlers::setup))
     35             .route("/authorize/{nonce}", get(handlers::authorize))
     36             .route("/token", post(handlers::token))
     37             .route("/info", get(handlers::info))
     38             .route("/notification", post(handlers::notification_webhook))
     39             .route("/status/{verification_id}", get(handlers::status))
     40             .route("/finalize/{verification_id}", get(handlers::finalize))
     41             .nest_service("/js", ServeDir::new("js"))
     42             .with_state(state);
     43 
     44         serve(app, &listen).await?;
     45         Ok(())
     46     })
     47 }