aboutsummaryrefslogtreecommitdiffstats
path: root/meta.sr.ht/user-api.md
blob: 36ceac8d8807f977016a7314c9cb540db07c10dd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# meta.sr.ht user API

The meta.sr.ht API allows you to view and edit user information on meta.sr.ht
programmatically. This API follows the [standard sourcehut API
conventions](../api-conventions.md).

## Authentication

Authentication is done via the [meta.sr.ht OAuth
flow](oauth-api.md). The following OAuth scopes are available for meta.sr.ht:

- **audit:read**: read the security audit log
- **keys:read**, **keys:write**: read & update user SSH & PGP keys
- **profile:read**, **profile:write**: read & update profile information

## Resources

### User resource

meta.sr.ht expands on the [standard user
resource](../api-conventions.md#user-resource).

```json
{
  "canonical_name": "~username",
  "name": "username",
  "email": "email",
  "url": "url" or null,
  "location": "location" or null,
  "bio": "bio" or null,
  "use_pgp_key": pgp key resource ID
}
```

- **use\_pgp\_key** is the ID of the user's preferred PGP key, which can be
  found via [`GET /api/user/pgp-keys/:id`](#get-apiuserpgp-keysid).

### Audit log entry resource

```json
{
  "id": integer,
  "ip": "IP address",
  "action": "event type",
  "details": "event details",
  "created": "timestamp"
}
```

### SSH key resource

```json
{
  "id": integer,
  "authorized": "timestamp",
  "comment": "SSH key comment",
  "fingerprint": "SSH key fingerprint",
  "key": "SSH key (authorized_keys format)",
  "owner": short-form user resource,
  "last_used": "timestamp"
}
```

- **last_used** is omitted when viewing an SSH key which is not owned by the
  authorized user.

### PGP key resource

```json
{
  "id": integer,
  "key": "armored PGP key",
  "key_id": "PGP key fingerprint",
  "email": "First email found in the PGP key",
  "authorized": "timestamp",
  "owner": short-form user resource
}
```

## Endpoints

### GET /api/user/profile

Returns the authenticated user's [user resource](#user-resource).

**OAuth scope**: `profile:read`

### PUT /api/user/profile

Updates the authenticated user's profile.

**OAuth scope**: `profile:update`

**Request body**

```json
{
  "url": "url" or null, (optional)
  "location": "location" or null, (optional)
  "bio": "bio" or null, (optional)
  "email": "email" (optional)
}
```

**Response**

Updated [user resource](#user-resource).

**Notes**

- When updating **email**, the returned user resource will not reflect the
  update. The user must click the confirmation link which is sent to their new
  email address before the update will take effect.

### GET /api/user/audit-log

List of [audit log entry resources](#audit-log-entry-resource).

**OAuth scope**: `audit-log:read`

### GET /api/user/ssh-keys

List of [SSH key resources](#ssh-key-resource).

**OAuth scope**: `keys:read`

### POST /api/user/ssh-keys

Creates a new [SSH key resource](#ssh-key-resource).

**OAuth scope**: `keys:write`

**Request body**

```json
{
  "ssh-key": "SSH key (authorized_keys format)"
}
```

**Response**

The new [SSH key resource](#ssh-key-resource).

### GET /api/user/ssh-keys/:id

Retrieves an [SSH key resource](#ssh-key-resource). 

**OAuth scope**: `keys:read`

### PUT /api/user/ssh-keys/:id

Updates the "last_used" time of this SSH key resource.

**OAuth scope**: `keys:write`

**Response**

The updated [SSH key resource](#ssh-key-resource).

### DELETE /api/user/ssh-keys/:id

Deletes this SSH key resource.

**OAuth scope**: `keys:write`

### GET /api/user/pgp-keys

List of [PGP key resources](#pgp-key-resource).

**OAuth scope**: `keys:read`

### POST /api/user/pgp-keys

Creates a new [PGP key resource](#pgp-key-resource).

**OAuth scope**: `keys:write`

**Request body**

```json
{
  "pgp-key": "armored PGP key"
}
```

**Response**

The new [PGP key resource](#pgp-key-resource).

### GET /api/user/pgp-keys/:id

Retrieves a [PGP key resource](#pgp-key-resource).

**OAuth scope**: `keys:read`

### DELETE /api/user/pgp-keys/:id

Deletes this PGP key resource.

**OAuth scope**: `keys:write`

## Webhooks

### /api/user/...

Webhook for user events. Includes the [standard webhook
endpoints](../api-conventions.md#webhooks)

#### profile:update

Issued when the user's profile (bio, email, etc) is updated.

**OAuth scope**: `profile:read`

**Request body**

The updated [user resource](#user-resource).

#### ssh-key:add

Issued when the user adds an SSH key to their account.

**OAuth scope**: `keys:read`

**Request body**

The new [SSH key resource](#ssh-key-resource).

#### ssh-key:remove

Issued when the user removes an SSH key from their account.

**OAuth scope**: `keys:read`

**Request body**

```json
{
  "id": integer ID of the affected SSH key resource
}
```

#### pgp-key:add

Issued when the user adds a PGP key to their account.

**OAuth scope**: `keys:read`

**Request body**

The new [PGP key resource](#pgp-key-resource).

#### pgp-key:remove

Issued when the user removes a PGP key from their account.

**OAuth scope**: `keys:read`

**Request body**

```json
{
  "id": integer ID of the affected PGP key resource
}
```