Immich_auth.SessionSession management for Immich CLI with profile support.
This module provides session persistence for Immich authentication, supporting both JWT tokens and API keys. Sessions are stored in profile-specific directories under ~/.config/immich/profiles/<profile>/session.json.
~/.config/immich/
config.json # Stores current_profile setting
profiles/
default/
session.json # Session for "default" profile
home/
session.json # Session for "home" profile
work/
session.json # Session for "work" profileImmich supports two authentication methods:
(* Login with API key *)
let session = Session.create
~server_url:"https://immich.example.com"
~auth:(Api_key { key = "xxx"; name = Some "cli" })
() in
Session.save fs ~profile:"home" sessionval create : server_url:string -> auth:auth_method -> unit -> tcreate ~server_url ~auth () creates a new session with the current timestamp.
val server_url : t -> stringserver_url t returns the server URL.
val auth : t -> auth_methodauth t returns the authentication method.
val created_at : t -> stringcreated_at t returns the creation timestamp (RFC 3339).
val get_current_profile : Eio.Fs.dir_ty Eio.Path.t -> stringget_current_profile fs returns the current profile name. Returns default_profile if no profile has been set.
val set_current_profile : Eio.Fs.dir_ty Eio.Path.t -> string -> unitset_current_profile fs profile sets the current profile.
val list_profiles : Eio.Fs.dir_ty Eio.Path.t -> string listlist_profiles fs returns all profiles that have sessions. Returns profile names sorted alphabetically.
val base_config_dir : Eio.Fs.dir_ty Eio.Path.t -> Eio.Fs.dir_ty Eio.Path.tbase_config_dir fs returns the base config directory (~/.config/immich), creating it if needed.
val config_dir :
Eio.Fs.dir_ty Eio.Path.t ->
?profile:string ->
unit ->
Eio.Fs.dir_ty Eio.Path.tconfig_dir fs ?profile () returns the config directory for a profile, creating it if needed.
val save : Eio.Fs.dir_ty Eio.Path.t -> ?profile:string -> t -> unitsave fs ?profile session saves the session.
val load : Eio.Fs.dir_ty Eio.Path.t -> ?profile:string -> unit -> t optionload fs ?profile () loads a saved session.
val clear : Eio.Fs.dir_ty Eio.Path.t -> ?profile:string -> unit -> unitclear fs ?profile () removes the saved session.
is_jwt_expired ?leeway token returns true if the JWT token is expired.
val is_expired : ?leeway:int -> t -> boolis_expired ?leeway session returns true if the session is expired. API key sessions never expire.