Atex.XRPC.LoginClient (atex v0.10.0)

View Source

Password/app-password based XRPC client for AT Protocol.

Creates a session via com.atproto.server.createSession and handles automatic token refresh on 401 responses. For OAuth-based authentication, see Atex.XRPC.OAuthClient.

Examples

{:ok, client} = Atex.XRPC.LoginClient.login("https://bsky.social", "user.bsky.social", "password")
{:ok, response, client} = Atex.XRPC.get(client, "app.bsky.actor.getProfile", params: [actor: "user.bsky.social"])

Summary

Functions

Create a new Atex.XRPC.LoginClient by logging in with an identifier and password to fetch an initial pair of access & refresh tokens.

Create a new Atex.XRPC.LoginClient from an endpoint, and optionally an existing access/refresh token.

Request a new refresh_token for the given client.

Types

t()

@type t() :: %Atex.XRPC.LoginClient{
  access_token: (String.t() | nil) | nil,
  endpoint: String.t(),
  refresh_token: (String.t() | nil) | nil
}

Functions

login(endpoint, identifier, password, auth_factor_token \\ nil)

@spec login(String.t(), String.t(), String.t(), String.t() | nil) ::
  {:ok, t()} | {:error, any()}

Create a new Atex.XRPC.LoginClient by logging in with an identifier and password to fetch an initial pair of access & refresh tokens.

Also supports providing a MFA token in the situation that is required.

Uses com.atproto.server.createSession under the hood, so identifier can be either a handle or a DID.

Examples

iex> Atex.XRPC.LoginClient.login("https://bsky.social", "example.com", "password123")
{:ok, %Atex.XRPC.LoginClient{...}}

new(endpoint, access_token \\ nil, refresh_token \\ nil)

@spec new(String.t(), String.t() | nil, String.t() | nil) :: t()

Create a new Atex.XRPC.LoginClient from an endpoint, and optionally an existing access/refresh token.

Endpoint should be the base URL of a PDS, or an AppView in the case of unauthenticated requests (like Bluesky's public API), e.g. https://bsky.social.

refresh(client)

@spec refresh(t()) :: {:ok, t()} | {:error, any()}

Request a new refresh_token for the given client.