ProtoRune.Atproto.Session (proto_rune v0.3.0)

Copy Markdown

An authenticated AT Protocol session.

Returned by ProtoRune.login/2 and ProtoRune.refresh_session/1. Carries the access and refresh JWTs, the account's handle and did, and the service_url of the PDS resolved from the DID document, so requests are routed to the right server.

Treat it as an opaque value: pass it as the first argument to any function that requires authentication, and refresh it with ProtoRune.refresh_session/1 when the access token expires.

Summary

Functions

Normalizes a service URL into an XRPC base URL.

Parses session data from the server response.

Types

t()

@type t() :: %ProtoRune.Atproto.Session{
  access_jwt: String.t(),
  active: boolean() | nil,
  did: String.t(),
  did_doc: map() | nil,
  email: String.t() | nil,
  email_auth_factor: boolean() | nil,
  email_confirmed: boolean() | nil,
  handle: String.t(),
  refresh_jwt: String.t(),
  service_url: String.t() | nil
}

Functions

normalize_service_url(url)

@spec normalize_service_url(String.t()) :: String.t()

Normalizes a service URL into an XRPC base URL.

DID documents list the PDS endpoint without the /xrpc path that XRPC methods are served under, so it is appended when missing.

iex> Session.normalize_service_url("https://bsky.social")
"https://bsky.social/xrpc"

iex> Session.normalize_service_url("https://bsky.social/xrpc")
"https://bsky.social/xrpc"

parse(data)

Parses session data from the server response.

Extracts the service URL from the DID document if available, allowing the session to carry its own service endpoint.

Examples

{:ok, session} = Session.parse(%{
  access_jwt: "...",
  refresh_jwt: "...",
  did: "did:plc:...",
  handle: "alice.bsky.social"
})