1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! authentication client for the central authentication service of
//! [unilim](https://www.unilim.fr), the university of limoges.
//!
//! talks to the lemonldap::ng portal at `cas.unilim.fr` and covers the whole
//! session lifecycle:
//!
//! - [`CAS::initialize`] submits credentials and returns a [`PendingAuth`]
//! holding the 2fa challenge.
//! - [`PendingAuth`] solves the challenge with an email code or a totp code,
//! then [`PendingAuth::finish`] establishes the session.
//! - [`CAS::restore`] brings back a persisted session without solving 2fa
//! again.
//! - [`CAS::service`] returns a ticket url for one of the supported
//! [`Services`].
//! - [`CAS::authorize`], [`CAS::tokenize`] and [`CAS::userinfo`] handle the
//! oauth2 flow of the portal.
//!
//! # quick start
//!
//! ```no_run
//! use unilim_cas::CAS;
//!
//! # async fn quick_start() -> unilim_cas::Result<()> {
//! // on first login, solve the 2fa challenge manually.
//! let mut auth = CAS::initialize("username", "password").await?;
//!
//! if !auth.solved {
//! if auth.is_totp_available {
//! auth.solve_with_totp("123456").await?;
//! }
//! else if auth.is_email_available {
//! auth.send_email_code().await?;
//! auth.solve_with_email_code("123456").await?;
//! }
//! }
//!
//! let cas = auth.finish().await?;
//!
//! // store `cas.connection` and `cas.key` somewhere safe, then restore
//! // later without any 2fa prompt.
//! let cas = CAS::restore("username", "password", &cas.connection, &cas.key).await?;
//! # Ok(())
//! # }
//! ```
//!
//! # session model
//!
//! an established [`CAS`] session is made of three strings:
//!
//! - [`CAS::cookie`], the `lemonldap` session cookie sent on every request.
//! - [`CAS::connection`], the `llngconnection` persistence cookie obtained
//! by registering the browser.
//! - [`CAS::key`], the totp secret answering the browser check during
//! [`CAS::restore`].
//!
//! the session cookie expires quickly, so store the other two for the long
//! term.
//!
//! # features
//!
//! - `client`, the default, provides the native client documented here. http
//! goes through [rikka](https://docs.rs/rikka), so it also runs on
//! `wasm32`.
//! - `wasm` only provides the `unilim_cas::wasm` module, extern declarations
//! of the `@unilim/cas` js classes for packages receiving the session from
//! javascript. pulls no client code and only compiles on `wasm32`.
pub use *;