(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
- CreateToken - 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.
using Clerk.BackendAPI;
using Clerk.BackendAPI.Models.Operations;
using Clerk.BackendAPI.Models.Components;
var sdk = new ClerkBackendApi(bearerAuth: "<YOUR_BEARER_TOKEN_HERE>");
GetSessionListRequest req = new GetSessionListRequest() {
ClientId = "client_123",
UserId = "user_456",
Status = Clerk.BackendAPI.Models.Operations.Status.Active,
Limit = 20,
Offset = 10,
};
var res = await sdk.Sessions.ListAsync(req);
// handle response
Parameter |
Type |
Required |
Description |
request |
GetSessionListRequest |
✔️ |
The request object to use for the request. |
GetSessionListResponse
Error Type |
Status Code |
Content Type |
Clerk.BackendAPI.Models.Errors.ClerkErrors |
400, 401, 422 |
application/json |
Clerk.BackendAPI.Models.Errors.SDKError |
4XX, 5XX |
*/* |
Retrieve the details of a session
using Clerk.BackendAPI;
using Clerk.BackendAPI.Models.Operations;
using Clerk.BackendAPI.Models.Components;
var sdk = new ClerkBackendApi(bearerAuth: "<YOUR_BEARER_TOKEN_HERE>");
var res = await sdk.Sessions.GetAsync(sessionId: "sess_1234567890abcdef");
// handle response
Parameter |
Type |
Required |
Description |
Example |
SessionId |
string |
✔️ |
The ID of the session |
sess_1234567890abcdef |
GetSessionResponse
Error Type |
Status Code |
Content Type |
Clerk.BackendAPI.Models.Errors.ClerkErrors |
400, 401, 404 |
application/json |
Clerk.BackendAPI.Models.Errors.SDKError |
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.
using Clerk.BackendAPI;
using Clerk.BackendAPI.Models.Operations;
using Clerk.BackendAPI.Models.Components;
var sdk = new ClerkBackendApi(bearerAuth: "<YOUR_BEARER_TOKEN_HERE>");
var res = await sdk.Sessions.RevokeAsync(sessionId: "sess_1234567890abcdef");
// handle response
Parameter |
Type |
Required |
Description |
Example |
SessionId |
string |
✔️ |
The ID of the session |
sess_1234567890abcdef |
RevokeSessionResponse
Error Type |
Status Code |
Content Type |
Clerk.BackendAPI.Models.Errors.ClerkErrors |
400, 401, 404 |
application/json |
Clerk.BackendAPI.Models.Errors.SDKError |
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.
using Clerk.BackendAPI;
using Clerk.BackendAPI.Models.Operations;
using Clerk.BackendAPI.Models.Components;
var sdk = new ClerkBackendApi(bearerAuth: "<YOUR_BEARER_TOKEN_HERE>");
var res = await sdk.Sessions.VerifyAsync(
sessionId: "sess_w8q4g9s60j28fghv00f3",
requestBody: new VerifySessionRequestBody() {
Token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzZXNzaW9uX2lkIjoic2Vzc193OHF4ZzZzNm9qMjhmZ2h2MDBmMyIsImlhdCI6MTU4MjY0OTg2Mn0.J4KP2L6bEZ6YccHFW4E2vKbOLw_mmO0gF_GNRw-wtLM",
}
);
// handle response
Parameter |
Type |
Required |
Description |
Example |
SessionId |
string |
✔️ |
The ID of the session |
sess_w8q4g9s60j28fghv00f3 |
RequestBody |
VerifySessionRequestBody |
➖ |
Parameters. |
|
VerifySessionResponse
Error Type |
Status Code |
Content Type |
Clerk.BackendAPI.Models.Errors.ClerkErrors |
400, 401, 404, 410 |
application/json |
Clerk.BackendAPI.Models.Errors.SDKError |
4XX, 5XX |
*/* |
Creates a JSON Web Token(JWT) based on a session and a JWT Template name defined for your instance
using Clerk.BackendAPI;
using Clerk.BackendAPI.Models.Operations;
using Clerk.BackendAPI.Models.Components;
var sdk = new ClerkBackendApi(bearerAuth: "<YOUR_BEARER_TOKEN_HERE>");
var res = await sdk.Sessions.CreateTokenAsync(
sessionId: "ses_123abcd4567",
templateName: "custom_hasura"
);
// handle response
Parameter |
Type |
Required |
Description |
Example |
SessionId |
string |
✔️ |
The ID of the session |
ses_123abcd4567 |
TemplateName |
string |
✔️ |
The name of the JWT Template defined in your instance (e.g. custom_hasura ). |
custom_hasura |
CreateSessionTokenFromTemplateResponse
Error Type |
Status Code |
Content Type |
Clerk.BackendAPI.Models.Errors.ClerkErrors |
401, 404 |
application/json |
Clerk.BackendAPI.Models.Errors.SDKError |
4XX, 5XX |
*/* |