actix / actix/actix-extras

Session: allow usage of Opaque token instead of cookies

Offen
#325 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
A-session C-feature
Vorherrschende Sprache
Rust
Sterne
889
Forks
224
Ø Merge
9 Std. 37 Min.
Gemergte PRs (30 T.)
20

Beschreibung

## Expected Behavior

I propose to change some behaviour on the `SessionMiddleware` to allow developers to use an Opaque Token instead of a cookie to manage session identification for the Redis backend. This change opens the possibility to keep a stateful session when working with Actix as a Rest API for mobile app in example.

## Current Behavior

The current `SessionMiddleware` only allow session management through cookies. While it works pretty well for web application, this is not suitable for other apps like mobile or desktop applications which doesn't necessarily support cookies as well as browsers.

## Possible Solution

One possibility to improve this session middleware would be to ask developers if they prefer using cookies or an Opaque Token (in this case, the /login route will require to return the tokens to let the client store it somewhere)

## Context

A way to implement this use-case on the developer-side would be like the following:
```rs
let redis_store = RedisSessionStore::new("redis://redis_url").await.unwrap();

let provider = SessionProvider::opaque_token();
// or for cookies (this would propably need a builder to make it pretty to use
let provider = Sessionprovider::cookie(Key::from(&[0; 64]))
.cookie_path("/")
.cookie_http_only(true);

let session_middleware = SessionMiddleware::builder(redis_store)
.provider(provider)
.session_lifecycle(
PersistentSession::default().session_ttl(time::Duration::days(5))
)
.build();
```

* Rust Version: 1.72.0
* Actix-session Version: 0.7.2

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.