OxL Reference

fn createSession

Creates a server-side session for user user (§13.2, provider session(cookie: name)) and returns its id: the value the client keeps in the cookie name. The server stores only the SHA-256 of the id, with the roles, the tenant and the expiry; calls that carry the cookie then have Principal.User(user, roles, …). ttl is 1 ms .. 30 days. Delete it with endSession.

oxl
let id = createSession("u1", ["Admin"], 8.hours())!
// reply with: Set-Cookie: sid=<id>; HttpOnly; Secure; SameSite=Lax; Path=/

Example:

oxl✓ checked in CI
use std.rpc { createSession, endSession }
use std.time { Duration }

fn main() io, db {
  let id = createSession("u1", ["Admin"], Duration.ofHours(8))!
  print("{id.len() > 20}")
  endSession(id)!
}
Output
true
pub(api) fn createSession(user: str, roles: List<str>, ttl: Duration, tenant: str? = none, mfa: bool = false) -> str | SessionError  db

Since. 1.0.0-beta

Parameters

NameType
userstr
rolesList<str>
ttlDuration
tenantstr? = none
mfabool = false

Returns

str

Errors

  • SessionError @error
  • `SessionError` when `ttl` is outside 1 ms .. 30 days or the session store cannot be written.

Effects

db

Defined in: std/rpc/rpc.oxl:400

See also