-
-
Notifications
You must be signed in to change notification settings - Fork 2
Session Management
Efficient session management is a key feature of the SDK, enabling you to authenticate and reuse sessions seamlessly.
After authenticating a client, you can export the session to persist it for later use:
$saveToDatabase(json_encode($client->authenticated()));
To reuse a saved session, deserialize it and provide it to the client during authentication:
use Atproto\Responses\Com\Atproto\Server\CreateSessionResponse;
$savedSession = new CreateSessionResponse(json_decode($savedSessionJSON, true));
$client = new Client();
$client->authenticate(
getenv('BLUESKY_IDENTIFIER'),
getenv('BLUESKY_PASSWORD'),
$savedSession
);
When a session is used, the SDK validates it automatically following this workflow:
-
accessJwt
: Checks the validity of theaccessJwt
token.- If valid, the session is used.
- If invalid, it proceeds to the next step.
-
refreshJwt
: Validates therefreshJwt
token.- If valid, a new session is generated.
- If invalid, it proceeds to the next step.
-
Credentials: If tokens are invalid, the SDK uses the provided credentials to create a new session.
- If successful, the new session is used.
- If unsuccessful, an exception is thrown.
use Atproto\Client;
use Atproto\Responses\Com\Atproto\Server\CreateSessionResponse;
// Fetch session from storage
$savedSessionJSON = $fetchFromDatabase();
$savedSession = new CreateSessionResponse(json_decode($savedSessionJSON, true));
$client = new Client();
$client->authenticate(
getenv('BLUESKY_IDENTIFIER'),
getenv('BLUESKY_PASSWORD'),
$savedSession
);
// Automatically handles token validation and session refresh
$profile = bskyFacade($client)->getProfile()
->actor($client->authenticated()->handle())
->send();
echo $profile->displayName();
Important
If no session is provided, the SDK will always use credentials to create a new session.
Description | Link |
---|---|
Discord | You can join to Discord Server of the SDK |
Official Docs | AT Protocol Official Docs |
BlueSky Docs | BSky HTTP Reference Docs |
SDK Docs | SDK Official Docs |
Packagist | SDK available on Packagist |
Author | Created by @shahmal1yev with ❤️ |
Support | Support to my open source work on Github or Buymeacoffee |
Get started with BlueSky SDK today and integrate Bluesky into your projects! 🚀
-
🏠 Home
Introduction to the SDK and its features -
🚀 Quick Start
Get started quickly with the basics of using the Bluesky SDK -
⚙️ Installation
Step-by-step guide to installing the SDK -
🛠️ Architecture Overview
Learn about the SDK's structure and design principles -
📖 BskyFacade
Simplify API interactions with the facade -
💾 Serialization
Serialize and deserialize data effectively -
🔄 Session Management
Manage authentication and session reuse -
🧹 Casting
Explore type-safe response casting in the SDK -
💡 Examples
Practical usage examples for various features