From 237accf0a1313ff5d73fe18096dd7229e0f8ba62 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sun, 20 Mar 2022 17:39:10 -0700 Subject: Initial commit --- src/demo/main.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/demo/main.rs (limited to 'src/demo/main.rs') diff --git a/src/demo/main.rs b/src/demo/main.rs new file mode 100644 index 0000000..f598b84 --- /dev/null +++ b/src/demo/main.rs @@ -0,0 +1,47 @@ +use actix_middleware_rfc7662::{ + AnyScope, RequireAuthorization, RequireAuthorizationConfig, RequireScope, +}; +use actix_web::{get, HttpResponse, HttpServer, Responder}; + +#[get("/read")] +async fn handle_read(_auth: RequireAuthorization) -> impl Responder { + HttpResponse::Ok().body("Success!\n") +} + +struct WriteScope; +impl RequireScope for WriteScope { + fn scope() -> &'static str { + "write" + } +} + +#[get("/write")] +async fn handle_write(_auth: RequireAuthorization) -> impl Responder { + HttpResponse::Ok().body("Success!\n") +} + +#[actix_web::main] +async fn main() -> std::io::Result<()> { + let bind = std::env::var("BIND").unwrap_or_else(|_| "127.0.0.1:8182".to_string()); + + let oauth_config = RequireAuthorizationConfig::new( + "cid1".to_string(), + Some("cs1".to_string()), + "https://cadmium.jesterpm.net/oauth/authorize" + .parse() + .expect("invalid url"), + "https://cadmium.jesterpm.net/oauth/introspect" + .parse() + .expect("invalid url"), + ); + + HttpServer::new(move || { + actix_web::App::new() + .app_data(oauth_config.clone()) + .service(handle_read) + .service(handle_write) + }) + .bind(bind)? + .run() + .await +} -- cgit v1.2.3