View Source Charon.Models.Session (Charon v1.1.0-beta)
A session.
Link to this section Summary
Functions
Deserialize a session, without breaking for structural changes in the session struct.
Create a new session from config values and overrides.
Serialize a session.
Link to this section Types
@type t() :: %Charon.Models.Session{ created_at: integer(), expires_at: integer() | :infinite, extra_payload: map(), id: String.t(), refresh_token_id: String.t(), refreshed_at: integer(), type: atom(), user_id: pos_integer() | binary(), version: pos_integer() }
Link to this section Functions
Deserialize a session, without breaking for structural changes in the session struct.
doctests
DocTests
@charon_config Charon.Config.from_enum(token_issuer: "local")
# serialization is reversible
iex> %Session{} = @charon_config |> new() |> serialize() |> deserialize()
# old version - without the :version field - is deserialized without error
iex> serialized = "g3QAAAAIZAAKY3JlYXRlZF9hdGJjdlx6ZAAKZXhwaXJlc19hdGJlV4/6ZAANZXh0cmFfcGF5bG9hZHQAAAAAZAACaWRtAAAAFk1xMk0xRUlJUTFKV1dMTEZBSnk2YndkABByZWZyZXNoX3Rva2VuX2lkbQAAAANhYmNkAAxyZWZyZXNoZWRfYXRhAGQABHR5cGVkAARmdWxsZAAHdXNlcl9pZGEB"
iex> serialized |> Base.decode64!() |> deserialize()
%Charon.Models.Session{created_at: 1668701306, id: "Mq2M1EIIQ1JWWLLFAJy6bw", user_id: 1, expires_at: 1700237306, refresh_token_id: "abc", refreshed_at: 0, type: :full, extra_payload: %{}, version: 1}
# old version - with :expires_at = nil - is deserialized without error
iex> %Session{expires_at: :infinite} = @charon_config |> new(expires_at: nil) |> serialize() |> deserialize()
@spec new(Charon.Config.t(), keyword() | map()) :: t()
Create a new session from config values and overrides.
Provides defaults for :id
, :created_at
and :expires_at
.
Serialize a session.