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
//! Session issuance and signed cookies for custom sign-in flows.
//!
//! After your application verifies its sign-in proof and resolves the user ID,
//! issue the session through the initialized auth instance. Issuance applies
//! configured session hooks and the admin plugin's ban policy.
//!
//! ```
//! use alibi::prelude::AuthSession;
//! use alibi::session::{
//! IssuedSession, SessionIssueError, create_session_cookie, issue_user_session,
//! };
//! use alibi::{AuthError, AuthResult, AuthSchema, Alibi};
//!
//! async fn sign_in_verified_user<S: AuthSchema>(
//! auth: &Alibi<S>,
//! user_id: &str,
//! ) -> AuthResult<(IssuedSession<S>, String)> {
//! let issued = match issue_user_session(auth.context(), user_id, None, None).await {
//! Ok(issued) => issued,
//! Err(SessionIssueError::Banned { message }) => {
//! return Err(AuthError::banned_user(message));
//! }
//! Err(SessionIssueError::Auth(error)) => return Err(error),
//! };
//! let cookie = create_session_cookie(issued.session.token(), auth.config())?;
//! Ok((issued, cookie))
//! }
//! ```
//!
//! Deliver the returned cookie as a `Set-Cookie` response header. The optional
//! IP address and user agent arguments to [`issue_user_session`] populate session
//! metadata. [`create_session_cookie`] uses the configured name, signing secret,
//! lifetime and cookie attributes.
//!
//! To select an organization during the initial insert, use
//! [`issue_user_session_with_fields`] after verifying access to that organization:
//!
//! ```
//! use alibi::session::{SessionIssueError, SessionOverrides, issue_user_session_with_fields};
//! use alibi::{AuthSchema, Alibi};
//!
//! async fn sign_in_to_organization<S: AuthSchema>(
//! auth: &Alibi<S>, user_id: &str, organization_id: &str,
//! ) -> Result<(), SessionIssueError> {
//! let issued = issue_user_session_with_fields(
//! auth.context(), user_id, None, None,
//! SessionOverrides {
//! active_organization_id: Some(organization_id.to_owned()),
//! ..Default::default()
//! },
//! ).await?;
//! // Deliver a signed cookie using `issued.session`, as above.
//! Ok(())
//! }
//! ```
//!
//! Overrides also support active teams, impersonation, and configured additional
//! fields. Creation hooks see these fields and can transform or reject them;
//! the returned session contains the final stored values. For callbacks that
//! need retained adapter output, use [`issue_user_session_with_fields_record`].
pub use *;
pub use create_session_cookie;
pub use ;