#http #web #async


Identity service for ntex web framework

1 unstable release

0.1.0 Mar 5, 2022

#616 in #http

MIT license

781 lines

Identity service for actix web framework Build Status codecov crates.io Join the chat at https://gitter.im/actix/actix

This crate moved to https://github.com/actix/actix-extras.

Documentation & community resources


Request identity service for ntex applications.

IdentityService middleware can be used with different policies types to store identity information.

By default, only cookie identity policy is implemented. Other backend implementations can be added separately.

CookieIdentityPolicy uses cookies as identity storage.

To access current request identity Identity extractor should be used.

use ntex::web;
use ntex_identity::{Identity, CookieIdentityPolicy, IdentityService};

async fn index(id: Identity) -> String {
    // access request identity
    if let Some(id) = id.identity() {
        format!("Welcome! {}", id)
    } else {
        "Welcome Anonymous!".to_owned()

async fn login(id: Identity) -> web::HttpResponse {
    id.remember("User1".to_owned()); // <- remember identity

async fn logout(id: Identity) -> web::HttpResponse {
    id.forget();                      // <- remove identity

let app = web::App::new().wrap(IdentityService::new(
    // <- create identity middleware
    CookieIdentityPolicy::new(&[0; 32])    // <- create cookie identity policy


~401K SLoC