NAME

Mojo::ATProto::OAuth::SessionStore::Memory - in-memory reference implementation of Mojo::ATProto::OAuth's session store interface

SYNOPSIS

use Mojo::ATProto::OAuth;

# short-name resolution - Mojo::ATProto::OAuth loads and
# instantiates this class for you
my $oauth = Mojo::ATProto::OAuth->new(
    client_id    => 'https://example.com/oauth/client-metadata.json',
    callback_url => 'https://example.com/oauth/callback',
    store        => 'Memory',
);

# or construct it directly
use Mojo::ATProto::OAuth::SessionStore::Memory qw//;
my $store = Mojo::ATProto::OAuth::SessionStore::Memory->new;
my $oauth2 = Mojo::ATProto::OAuth->new(..., store => $store);

DESCRIPTION

A plain in-process hashref implementation of the duck-typed store interface Mojo::ATProto::OAuth expects - see that module's own "THE STORE INTERFACE" section for the full contract this class implements. Nothing is persisted beyond the life of the process: a restart loses every in-flight auth request and every session. This makes it a reasonable choice for a single-process script or a test suite, but not for a real deployment, where a restart-surviving backend (e.g. Postgres) implementing the same interface is what you want instead.

Mojo::ATProto::OAuth->new(store => 'Memory') resolves to this class automatically via Mojo::ATProto::OAuth's own short class-name-string handling for store - see "store" in Mojo::ATProto::OAuth. Constructing it directly, as in the second "SYNOPSIS" example, works identically.

ATTRIBUTES

auth_requests

Hashref of persisted auth-request rows, keyed by state. Defaults to an empty hashref. Not part of the public interface - manipulate it only through the methods below.

auth_request_order

Arrayref recording the order state values were saved in, since a plain hash's own iteration order isn't reliable. Used by "last_state_for_issuer". Defaults to an empty arrayref.

sessions

Hashref of persisted session rows, keyed by "$account_did:$session_id". Defaults to an empty hashref.

METHODS

Implements the full sync + _p store contract described in "THE STORE INTERFACE" in Mojo::ATProto::OAuth:

get_auth_request / get_auth_request_p

my $info = $store->get_auth_request($state);

Fetches a persisted auth-request hashref by its PAR-generated state value. Dies (_p: rejects) with a message matching /no auth request found/ on a miss.

save_auth_request / save_auth_request_p

$store->save_auth_request($info);

Persists an auth-request hashref, keyed by its own state. Create- only, matching the store contract - a state value is never reused.

delete_auth_request / delete_auth_request_p

$store->delete_auth_request($state);

Deletes a persisted auth-request row by state. A no-op (not an error) if nothing is stored under that state.

get_session / get_session_p

my $session = $store->get_session($account_did, $session_id);

Fetches a persisted session hashref by the pair of $account_did and $session_id - not $session_id alone, since one account can have multiple concurrent sessions (e.g. multiple browsers/devices). Dies (_p: rejects) with a message matching /no session found/ on a miss.

save_session / save_session_p

$store->save_session($session_data);

Persists a session hashref, upserting by (account_did, session_id) - both an ordinary login and a scope-upgrade callback may call this on what's already an existing row (see "start_scope_upgrade" in Mojo::ATProto::OAuth), and the existing row is updated in place rather than duplicated.

delete_session / delete_session_p

$store->delete_session($account_did, $session_id);

Deletes a persisted session row by (account_did, session_id). A no-op (not an error) if nothing is stored under that pair.

SEE ALSO

Mojo::ATProto::OAuth