auth#

Functions and classes for performing and storing user authentication operations.

Classes:

AuthSession

A cryosparc-tools CLI session from a successful call to python -m cryosparc.tools login.

InstanceAuthSessions

Dictionary of CLI multiple user sessions for multiple instances, organized by instance URL.

UserAuthSessions

Dictionary of CLI login sessions for a single instance organized by user ID.

class AuthSession#

A cryosparc-tools CLI session from a successful call to python -m cryosparc.tools login.

class InstanceAuthSessions#

Dictionary of CLI multiple user sessions for multiple instances, organized by instance URL. Stored in ~/.config directory.

Example

>>> {
...     "https://cryosparc.example.com": {
...         "ali@example.com": {
...             "token": {
...                 "access_token": "abc123",
...                 "token_type": "bearer"
...             },
...             "expires": "2025-01-31T12:00:00.000000Z"
...         }
...     }
... }

Methods:

find(url[, email])

Find the first available token for the given instance URL and email.

insert(url, email, token, expires)

Add or replace a new token for the given instance and user email.

load([path])

Read all auth tokens from the given path.

save([path])

Write all auth tokens to the given path.

find(url: str, email: str | None = None) AuthSession | None#

Find the first available token for the given instance URL and email. If an email is not specified, returns the first existing session

insert(url: str, email: str, token: Token, expires: AwareDatetime)#

Add or replace a new token for the given instance and user email.

classmethod load(path: Path | None = None)#

Read all auth tokens from the given path. Loads from the user config directory if path is unspecified.

save(path: Path | None = None)#

Write all auth tokens to the given path. Writes to the user config directory if path is unspecified.

class UserAuthSessions#

Dictionary of CLI login sessions for a single instance organized by user ID. Only one session is allowed per-user.