#actix #auth #security #permissions #grants

actix-web-grants

Extension for actix-web to validate user permissions

11 releases (3 major breaking)

3.0.0-beta.1 Apr 7, 2021
2.0.1 Mar 10, 2021
2.0.0 Jan 22, 2021
1.0.0 Jan 18, 2021
0.1.6 Jan 17, 2021

#26 in Authentication

Download history 121/week @ 2021-01-12 33/week @ 2021-01-19 7/week @ 2021-01-26 23/week @ 2021-02-02 88/week @ 2021-02-09 58/week @ 2021-02-16 57/week @ 2021-02-23 88/week @ 2021-03-02 121/week @ 2021-03-09 47/week @ 2021-03-16 79/week @ 2021-03-23 88/week @ 2021-03-30 130/week @ 2021-04-06 111/week @ 2021-04-13

278 downloads per month

MIT/Apache

33KB
219 lines

actix-web-grants

actix-web-grants

Extension for actix-web to validate user permissions.

CI Crates.io Downloads Badge crates.io Documentation dependency status Apache 2.0 or MIT licensed

To check user access to specific services, you can use built-in proc-macro, PermissionGuard or manual.

The library can also be integrated with third-party solutions (like actix-web-httpauth).

Example of proc-macro way protection

use actix_web_grants::proc_macro::{has_permissions};

#[get("/secure")]
#[has_permissions("OP_READ_SECURED_INFO")]
async fn macro_secured() -> HttpResponse {
    HttpResponse::Ok().body("ADMIN_RESPONSE")
}

Example of Guard way protection

use actix_web_grants::{PermissionGuard, GrantsMiddleware};

App::new()
    .wrap(GrantsMiddleware::with_extractor(extract))
    .service(web::resource("/admin")
            .to(|| async { HttpResponse::Ok().finish() })
            .guard(PermissionGuard::new("ROLE_ADMIN".to_string())))

Example of manual way protection

use actix_web_grants::permissions::{AuthDetails, PermissionsCheck};

async fn manual_secure(details: AuthDetails) -> HttpResponse {
    if details.has_permission(ROLE_ADMIN) {
        return HttpResponse::Ok().body("ADMIN_RESPONSE");
    }
    HttpResponse::Ok().body("OTHER_RESPONSE")
}

You can find more examples in the git repository folder and documentation.

Supported actix-web versions

  • For actix-web-grants: 2.* supported version of actix-web is 3.*
  • For actix-web-grants: 3.* supported version of actix-web is 4.*

Dependencies

~21MB
~487K SLoC