# Module actix_web::middleware::identity[−][src]

Request identity service for Actix 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 RequestIdentity should be used. HttpRequest implements RequestIdentity trait.

    use actix_web::middleware::identity::RequestIdentity;
    use actix_web::middleware::identity::{CookieIdentityPolicy, IdentityService};
    use actix_web::*;

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

    fn login(mut req: HttpRequest) -> HttpResponse {
        req.remember("User1".to_owned()); // <- remember identity
        HttpResponse::Ok().finish()
    }

    fn logout(mut req: HttpRequest) -> HttpResponse {
        req.forget(); // <- remove identity
        HttpResponse::Ok().finish()
    }

    fn main() {
        let app = App::new().middleware(IdentityService::new(
            // <- create identity middleware
            CookieIdentityPolicy::new(&[0; 32])    // <- create cookie session backend
                  .name("auth-cookie")
                  .secure(false),
        ));
    }

## Structs

CookieIdentityPolicy | Use cookies for request identity storage.
IdentityService | Request identity middleware

## Traits

Identity | An identity
IdentityPolicy | Identity policy definition.
RequestIdentity | The helper trait to obtain your identity from a request.

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g. `str,u8` or `String,struct:Vec,test`)