Skip to content

Commit ab10858

Browse files
committed
feat(accessTokens): first draft
1 parent a56df84 commit ab10858

File tree

1 file changed

+238
-0
lines changed

1 file changed

+238
-0
lines changed
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
---
2+
title: Access Tokens
3+
description: Grant to your users, devices, tenant, access to SQLite Cloud services.
4+
category: platform
5+
status: publish
6+
slug: access-tokens
7+
---
8+
9+
# Access Token API
10+
11+
Access Tokens let backend systems securely grant users, devices, tenants, etc. access to SQLite Cloud services (SQLite Sync, Weblite, etc.). These endpoints enable full token lifecycle management: creation, inspection, validation, update, and revocation.
12+
All endpoints require authentication. Use an **API Key** or an **Access Token** via the `Authorization` header.
13+
14+
---
15+
16+
## Create a New Access Token
17+
18+
### `POST /v2/tokens`
19+
20+
Creates a new Access Token for a specific entity.
21+
The `entityId` refers to any kind of resource you want to associate the Access Token with. It must be a unique ID in your system.
22+
The `expiresAt` is a date time value to set an expiration, or `null` if it doesn't expire.
23+
24+
>[!note] Store the Access Token securely. It will not be shown again.
25+
26+
- **Authentication**: API Key
27+
28+
#### Example
29+
30+
```bash
31+
curl -X 'POST' \
32+
'https://<your-project-id>.sqlite.cloud:443/v2/tokens' \
33+
-H 'Content-Type: application/json' \
34+
-H 'Authorization: Bearer sqlitecloud://<your-project-id>.sqlite.cloud:8860?apikey=<your-api-key>' \
35+
-d '{
36+
"entityId": "0195fc5b-96a6-7000-8b17-fd2420499c2c",
37+
"name": "user-token",
38+
"expiresAt": "2023-10-01 10:11:12"
39+
}'
40+
```
41+
42+
#### Example Response
43+
44+
```json
45+
{
46+
"data": {
47+
"token": "134|sqla_abcdeabcdeabcdeabcdeabcdeabcde",
48+
"access_token_id": 134,
49+
"entityId": "0195fc5b-96a6-7000-8b17-fd2420499c2c",
50+
"name": "user-token",
51+
"expiresAt": "2023-10-01 10:11:12",
52+
"createdAt": "2023-09-01 10:11:12"
53+
}
54+
}
55+
```
56+
57+
---
58+
59+
## Get Current Token Details (Access Token Only)
60+
61+
### `GET /v2/tokens/details`
62+
63+
Retrieves metadata about the token used to authenticate the request.
64+
65+
- **Authentication**: Access Token
66+
67+
#### Example
68+
69+
```bash
70+
curl -X 'GET' \
71+
'https://<your-project-id>.sqlite.cloud:443/v2/tokens/details' \
72+
-H 'accept: application/json' \
73+
-H 'Authorization: Bearer 134|sqla_abcdeabcdeabcdeabcdeabcdeabcde'
74+
```
75+
76+
#### Example Response
77+
78+
```json
79+
{
80+
"data": {
81+
"access_token_id": 134,
82+
"entityId": "0195fc5b-96a6-7000-8b17-fd2420499c2c",
83+
"name": "user-token",
84+
"expiresAt": "2023-10-01 10:11:12",
85+
"createdAt": "2023-09-01 10:11:12"
86+
}
87+
}
88+
```
89+
90+
---
91+
92+
## Get Token Details (Using API Key)
93+
94+
### `POST /v2/tokens/details`
95+
96+
Lets you inspect an Access Token using your API Key.
97+
98+
- **Authentication**: API Key
99+
100+
#### Example
101+
102+
```bash
103+
curl -X 'POST' \
104+
'https://<your-project-id>.sqlite.cloud:443/v2/tokens/details' \
105+
-H 'Content-Type: application/json' \
106+
-H 'Authorization: Bearer sqlitecloud://<your-project-id>.sqlite.cloud:8860?apikey=<your-api-key>' \
107+
-d '{
108+
"token": "134|sqla_abcdeabcdeabcdeabcdeabcdeabcde"
109+
}'
110+
```
111+
112+
#### Example Response
113+
114+
```json
115+
{
116+
"data": {
117+
"access_token_id": 134,
118+
"entityId": "0195fc5b-96a6-7000-8b17-fd2420499c2c",
119+
"name": "user-token",
120+
"expiresAt": "2023-10-01 10:11:12",
121+
"createdAt": "2023-09-01 10:11:12"
122+
}
123+
}
124+
```
125+
126+
---
127+
128+
## Check Token Validity
129+
130+
### `GET /v2/tokens/authorized`
131+
132+
Checks whether the provided Access Token is valid and not expired.
133+
134+
- **Authentication**: API Key or Access Token
135+
136+
#### Example
137+
138+
```bash
139+
curl -X 'GET' \
140+
'https://<your-project-id>.sqlite.cloud:443/v2/tokens/authorized' \
141+
-H 'accept: application/json' \
142+
-H 'Authorization: Bearer 134|sqla_abcdeabcdeabcdeabcdeabcdeabcde'
143+
```
144+
145+
---
146+
147+
## Update an Access Token
148+
149+
### `PATCH /v2/tokens`
150+
151+
Updates information of an Access Token.
152+
The The `token` field is required; it specifies the Access Token to update.
153+
Fields that can be updated:
154+
- `name`.
155+
- `expiresAt`: date time value or `null` to set no expiration.
156+
157+
- **Authentication**: API Key
158+
159+
#### Example
160+
161+
```bash
162+
curl -X 'PATCH' \
163+
'https://<your-project-id>.sqlite.cloud:443/v2/tokens' \
164+
-H 'accept: application/json' \
165+
-H 'Content-Type: application/json' \
166+
-H 'Authorization: Bearer sqlitecloud://<your-project-id>.sqlite.cloud:8860?apikey=<your-api-key>' \
167+
-d '{
168+
"token": "134|sqla_abcdeabcdeabcdeabcdeabcdeabcde",
169+
"name": "updated-user-token",
170+
"expiresAt": "2024-12-31T23:59:59"
171+
}'
172+
```
173+
174+
---
175+
176+
## Revoke a Token
177+
178+
### `DELETE /v2/tokens`
179+
180+
Revokes the given token, making it immediately unusable.
181+
182+
- **Authentication**: API Key, Access Token
183+
184+
The `token` in the request is optional when the Access Token is used for the authentication.
185+
186+
#### Example
187+
188+
```bash
189+
curl -X 'DELETE' \
190+
'https://<your-project-id>.sqlite.cloud:443/v2/tokens' \
191+
-H 'accept: application/json' \
192+
-H 'Content-Type: application/json' \
193+
-H 'Authorization: Bearer sqlitecloud://<your-project-id>.sqlite.cloud:8860?apikey=<your-api-key>' \
194+
-d '{
195+
"token": "134|sqla_abcdeabcdeabcdeabcdeabcdeabcde"
196+
}'
197+
```
198+
199+
---
200+
201+
## List Tokens by Entity
202+
203+
### `GET /v2/tokens/entities/{entityId}`
204+
205+
Returns all non-expired tokens associated with the specified entity.
206+
207+
- **Authentication**: API Key
208+
- **Path Parameter**: `entityId`
209+
210+
#### Example
211+
212+
```bash
213+
curl -X 'GET' \
214+
'https://<your-project-id>.sqlite.cloud:443/v2/tokens/entities/0195fc5b-96a6-7000-8b17-fd2420499c2c' \
215+
-H 'accept: application/json' \
216+
-H 'Authorization: Bearer sqlitecloud://<your-project-id>.sqlite.cloud:8860?apikey=<your-api-key>'
217+
```
218+
219+
#### Example Response
220+
221+
```json
222+
{
223+
"data": [
224+
{
225+
"name": "sqlitesync-user",
226+
"expiresAt": "2024-11-01 00:00:00",
227+
"createdAt": "2024-10-01 10:11:12"
228+
},
229+
{
230+
"name": "sqlitesync-user",
231+
"expiresAt": null,
232+
"createdAt": "2024-09-01 10:11:12"
233+
}
234+
]
235+
}
236+
```
237+
238+
---

0 commit comments

Comments
 (0)