63 lines
2.0 KiB
Rust
63 lines
2.0 KiB
Rust
pub mod handlers;
|
|
pub mod models;
|
|
pub mod config;
|
|
|
|
use axum::{
|
|
Router,
|
|
routing::{get, post},
|
|
};
|
|
use axum_session::{SessionConfig, SessionLayer, SessionStore};
|
|
use axum_session_sqlx::SessionSqlitePool;
|
|
use sqlx::SqlitePool;
|
|
use tower_http::services::ServeDir;
|
|
|
|
pub type OidcClient = oauth2::Client<
|
|
oauth2::StandardErrorResponse<oauth2::basic::BasicErrorResponseType>,
|
|
oauth2::StandardTokenResponse<oauth2::EmptyExtraTokenFields, oauth2::basic::BasicTokenType>,
|
|
oauth2::StandardTokenIntrospectionResponse<
|
|
oauth2::EmptyExtraTokenFields,
|
|
oauth2::basic::BasicTokenType,
|
|
>,
|
|
oauth2::StandardRevocableToken,
|
|
oauth2::StandardErrorResponse<oauth2::RevocationErrorResponseType>,
|
|
oauth2::EndpointSet,
|
|
oauth2::EndpointNotSet,
|
|
oauth2::EndpointNotSet,
|
|
oauth2::EndpointNotSet,
|
|
oauth2::EndpointSet,
|
|
>;
|
|
|
|
#[derive(Clone)]
|
|
pub struct AppState {
|
|
pub pool: SqlitePool,
|
|
pub oidc_client: OidcClient,
|
|
}
|
|
|
|
pub async fn create_app(state: AppState, session_secret: Vec<u8>, pool: SqlitePool) -> Router {
|
|
//This Defaults as normal Cookies.
|
|
//To enable Private cookies for integrity, and authenticity please check the next Example.
|
|
let session_config = SessionConfig::default()
|
|
.with_table_name("sessions_table")
|
|
.with_key(axum_session::Key::from(&session_secret));
|
|
|
|
// create SessionStore and initiate the database tables
|
|
let session_store =
|
|
SessionStore::<SessionSqlitePool>::new(Some(pool.clone().into()), session_config)
|
|
.await
|
|
.unwrap();
|
|
|
|
let app = Router::new()
|
|
.route("/", get(handlers::index))
|
|
.route("/auth/login", get(handlers::login))
|
|
.route("/auth/callback", get(handlers::callback))
|
|
.route("/input", post(handlers::input_post))
|
|
.with_state(state)
|
|
.layer(SessionLayer::new(session_store))
|
|
.nest_service("/static", ServeDir::new("static"));
|
|
|
|
#[cfg(test)]
|
|
let app = app.route("/test/login", get(handlers::test_login));
|
|
|
|
app
|
|
}
|