indieauth-client 0.1.0

A small library for actix-web to log your users in using IndieAuth
Documentation
#[actix_web::get("/")]
async fn index(user: Option<actix_identity::Identity>) -> impl actix_web::Responder {
    use actix_web::HttpResponse;

    if let Some(user) = user {
        HttpResponse::Ok()
            .content_type("text/html")
            .body(format!("Hello {}!", user.id().unwrap()))
    } else {
        HttpResponse::Ok()
            .content_type("text/html")
            .body("Hello, anonymous! <a href=\"/auth/indieauth/login\">Login</a>")
    }
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    use actix_identity::IdentityMiddleware;
    use actix_session::{storage::CookieSessionStore, SessionMiddleware};
    use indieauth_client::{get_service, AuthConfig};

    // get first arg
    let args: Vec<String> = std::env::args().collect();
    if args.len() < 2 {
        println!("Usage: {} <issuer>", args[0]);
        return Ok(());
    }
    let issuer = args[1].clone();

    let config = AuthConfig::new(issuer);

    let secret_key = actix_web::cookie::Key::generate();

    actix_web::HttpServer::new(move || {
        actix_web::App::new()
            .wrap(IdentityMiddleware::default())
            .wrap(SessionMiddleware::new(
                CookieSessionStore::default(),
                secret_key.clone(),
            ))
            .service(index)
            .service(get_service(&config))
    })
    .workers(1)
    .bind("127.0.0.1:8080")?
    .run()
    .await
}