Skip to content

Commit 5d6e136

Browse files
committed
Add token generation endpoint and update sharing sidebar for token management
Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
1 parent da647a3 commit 5d6e136

4 files changed

Lines changed: 239 additions & 56 deletions

File tree

docs/API_v3.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,21 @@ Update a single or all properties of an option-object
674674
"data": 5
675675
```
676676

677+
### Generate a new Share Token
678+
679+
Generates a new random token that can be used as a custom share link token. This endpoint is used when custom public share tokens are enabled by the admin setting _allowCustomPublicShareTokens_.
680+
681+
- Endpoint: `/api/v3/token`
682+
- Method: `GET`
683+
- Parameters: None
684+
- Response: **Status-Code OK**, as well as the generated token string.
685+
686+
```
687+
"data": {
688+
"token": "abcdefghijklmn1234567890"
689+
}
690+
```
691+
677692
## Submission Endpoints
678693

679694
### Get Form Submissions

lib/Controller/ShareApiController.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,32 @@ public function deleteShare(int $formId, int $shareId): DataResponse {
395395
return new DataResponse($shareId);
396396
}
397397

398+
/**
399+
* Get a unique share token
400+
*
401+
* @throws OCSForbiddenException Custom public share tokens are not allowed
402+
*
403+
* @return DataResponse<Http::STATUS_OK, array{token: string}, array{}>
404+
*
405+
* 200: Token generated successfully
406+
*/
407+
#[ApiRoute(verb: 'GET', url: '/api/v3/token')]
408+
#[NoAdminRequired]
409+
public function generateToken(): DataResponse {
410+
if (!$this->configService->getAllowCustomPublicToken()) {
411+
$this->logger->debug('Custom public share tokens are not allowed.');
412+
throw new OCSForbiddenException('Custom public share tokens are not allowed.');
413+
}
414+
415+
$token = $this->secureRandom->generate(
416+
24,
417+
ISecureRandom::CHAR_HUMAN_READABLE
418+
);
419+
return new DataResponse([
420+
'token' => $token,
421+
]);
422+
}
423+
398424
private function removeUploadedFilesShare(Form $form, Share $formShare): void {
399425
if (!in_array($formShare->getShareType(), [IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_USERGROUP, IShare::TYPE_CIRCLE], true)) {
400426
return;

openapi.json

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5596,6 +5596,131 @@
55965596
}
55975597
}
55985598
}
5599+
},
5600+
"/ocs/v2.php/apps/forms/api/v3/token": {
5601+
"get": {
5602+
"operationId": "share_api-generate-token",
5603+
"summary": "Get a unique share token",
5604+
"tags": [
5605+
"share_api"
5606+
],
5607+
"security": [
5608+
{
5609+
"bearer_auth": []
5610+
},
5611+
{
5612+
"basic_auth": []
5613+
}
5614+
],
5615+
"parameters": [
5616+
{
5617+
"name": "OCS-APIRequest",
5618+
"in": "header",
5619+
"description": "Required to be true for the API request to pass",
5620+
"required": true,
5621+
"schema": {
5622+
"type": "boolean",
5623+
"default": true
5624+
}
5625+
}
5626+
],
5627+
"responses": {
5628+
"403": {
5629+
"description": "Custom public share tokens are not allowed",
5630+
"content": {
5631+
"application/json": {
5632+
"schema": {
5633+
"type": "object",
5634+
"required": [
5635+
"ocs"
5636+
],
5637+
"properties": {
5638+
"ocs": {
5639+
"type": "object",
5640+
"required": [
5641+
"meta",
5642+
"data"
5643+
],
5644+
"properties": {
5645+
"meta": {
5646+
"$ref": "#/components/schemas/OCSMeta"
5647+
},
5648+
"data": {}
5649+
}
5650+
}
5651+
}
5652+
}
5653+
}
5654+
}
5655+
},
5656+
"200": {
5657+
"description": "Token generated successfully",
5658+
"content": {
5659+
"application/json": {
5660+
"schema": {
5661+
"type": "object",
5662+
"required": [
5663+
"ocs"
5664+
],
5665+
"properties": {
5666+
"ocs": {
5667+
"type": "object",
5668+
"required": [
5669+
"meta",
5670+
"data"
5671+
],
5672+
"properties": {
5673+
"meta": {
5674+
"$ref": "#/components/schemas/OCSMeta"
5675+
},
5676+
"data": {
5677+
"type": "object",
5678+
"required": [
5679+
"token"
5680+
],
5681+
"properties": {
5682+
"token": {
5683+
"type": "string"
5684+
}
5685+
}
5686+
}
5687+
}
5688+
}
5689+
}
5690+
}
5691+
}
5692+
}
5693+
},
5694+
"401": {
5695+
"description": "Current user is not logged in",
5696+
"content": {
5697+
"application/json": {
5698+
"schema": {
5699+
"type": "object",
5700+
"required": [
5701+
"ocs"
5702+
],
5703+
"properties": {
5704+
"ocs": {
5705+
"type": "object",
5706+
"required": [
5707+
"meta",
5708+
"data"
5709+
],
5710+
"properties": {
5711+
"meta": {
5712+
"$ref": "#/components/schemas/OCSMeta"
5713+
},
5714+
"data": {}
5715+
}
5716+
}
5717+
}
5718+
}
5719+
}
5720+
}
5721+
}
5722+
}
5723+
}
55995724
}
56005725
},
56015726
"tags": []

0 commit comments

Comments
 (0)