(sessions)
The Session object is an abstraction over an HTTP session. It models the period of information exchange between a user and the server. Sessions are created when a user successfully goes through the sign in or sign up flows. https://clerk.com/docs/reference/clerkjs/session
- list - List all sessions
- get - Retrieve a session
- revoke - Revoke a session
verify- Verify a session⚠️ Deprecated- createTokenFromTemplate - Create a session token from a jwt template
Returns a list of all sessions.
The sessions are returned sorted by creation date, with the newest sessions appearing first.
Deprecation Notice (2024-01-01): All parameters were initially considered optional, however
moving forward at least one of client_id
or user_id
parameters should be provided.
declare(strict_types=1);
require 'vendor/autoload.php';
use Clerk\Backend;
use Clerk\Backend\Models\Operations;
$security = '<YOUR_BEARER_TOKEN_HERE>';
$sdk = Backend\ClerkBackend::builder()->setSecurity($security)->build();
$request = new Operations\GetSessionListRequest();
$response = $sdk->sessions->list(
request: $request
);
if ($response->sessionList !== null) {
// handle response
}
Parameter | Type | Required | Description |
---|---|---|---|
$request |
Operations\GetSessionListRequest | ✔️ | The request object to use for the request. |
?Operations\GetSessionListResponse
Error Type | Status Code | Content Type |
---|---|---|
Errors\ClerkErrors11 | 400, 401, 422 | application/json |
Errors\SDKException | 4XX, 5XX | */* |
Retrieve the details of a session
declare(strict_types=1);
require 'vendor/autoload.php';
use Clerk\Backend;
$security = '<YOUR_BEARER_TOKEN_HERE>';
$sdk = Backend\ClerkBackend::builder()->setSecurity($security)->build();
$response = $sdk->sessions->get(
sessionId: '<id>'
);
if ($response->session !== null) {
// handle response
}
Parameter | Type | Required | Description |
---|---|---|---|
sessionId |
string | ✔️ | The ID of the session |
?Operations\GetSessionResponse
Error Type | Status Code | Content Type |
---|---|---|
Errors\ClerkErrors12 | 400, 401, 404 | application/json |
Errors\SDKException | 4XX, 5XX | */* |
Sets the status of a session as "revoked", which is an unauthenticated state. In multi-session mode, a revoked session will still be returned along with its client object, however the user will need to sign in again.
declare(strict_types=1);
require 'vendor/autoload.php';
use Clerk\Backend;
$security = '<YOUR_BEARER_TOKEN_HERE>';
$sdk = Backend\ClerkBackend::builder()->setSecurity($security)->build();
$response = $sdk->sessions->revoke(
sessionId: '<id>'
);
if ($response->session !== null) {
// handle response
}
Parameter | Type | Required | Description |
---|---|---|---|
sessionId |
string | ✔️ | The ID of the session |
?Operations\RevokeSessionResponse
Error Type | Status Code | Content Type |
---|---|---|
Errors\ClerkErrors13 | 400, 401, 404 | application/json |
Errors\SDKException | 4XX, 5XX | */* |
Returns the session if it is authenticated, otherwise returns an error. WARNING: This endpoint is deprecated and will be removed in future versions. We strongly recommend switching to networkless verification using short-lived session tokens, which is implemented transparently in all recent SDK versions (e.g. NodeJS SDK). For more details on how networkless verification works, refer to our Session Tokens documentation.
⚠️ DEPRECATED: This will be removed in a future release, please migrate away from it as soon as possible.
declare(strict_types=1);
require 'vendor/autoload.php';
use Clerk\Backend;
use Clerk\Backend\Models\Operations;
$security = '<YOUR_BEARER_TOKEN_HERE>';
$sdk = Backend\ClerkBackend::builder()->setSecurity($security)->build();
$requestBody = new Operations\VerifySessionRequestBody();
$response = $sdk->sessions->verify(
sessionId: '<id>',
requestBody: $requestBody
);
if ($response->session !== null) {
// handle response
}
Parameter | Type | Required | Description |
---|---|---|---|
sessionId |
string | ✔️ | The ID of the session |
requestBody |
?Operations\VerifySessionRequestBody | ➖ | Parameters. |
?Operations\VerifySessionResponse
Error Type | Status Code | Content Type |
---|---|---|
Errors\ClerkErrors14 | 400, 401, 404, 410 | application/json |
Errors\SDKException | 4XX, 5XX | */* |
Creates a JSON Web Token(JWT) based on a session and a JWT Template name defined for your instance
declare(strict_types=1);
require 'vendor/autoload.php';
use Clerk\Backend;
$security = '<YOUR_BEARER_TOKEN_HERE>';
$sdk = Backend\ClerkBackend::builder()->setSecurity($security)->build();
$response = $sdk->sessions->createTokenFromTemplate(
sessionId: '<id>',
templateName: '<value>'
);
if ($response->object !== null) {
// handle response
}
Parameter | Type | Required | Description |
---|---|---|---|
sessionId |
string | ✔️ | The ID of the session |
templateName |
string | ✔️ | The name of the JWT Template defined in your instance (e.g. custom_hasura ). |
?Operations\CreateSessionTokenFromTemplateResponse
Error Type | Status Code | Content Type |
---|---|---|
Errors\ClerkErrors15 | 401, 404 | application/json |
Errors\SDKException | 4XX, 5XX | */* |