Skip to content

Commit 247f653

Browse files
committed
feat: Serve well-known assetlinks json
Signed-off-by: Christopher Ng <chrng8@gmail.com>
1 parent 728c46d commit 247f653

7 files changed

Lines changed: 94 additions & 2 deletions

File tree

apps/settings/.editorconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ end_of_line = lf
77
insert_final_newline = true
88
trim_trailing_whitespace = true
99

10-
[{package.json,.travis.yml,webpack.config.js}]
10+
[{package.json,.travis.yml,webpack.config.js,assetlinks-template.json}]
1111
indent_style = space
12-
indent_size = 2
12+
indent_size = 2

apps/settings/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
'OCA\\Settings\\SetupChecks\\Woff2Loading' => $baseDir . '/../lib/SetupChecks/Woff2Loading.php',
127127
'OCA\\Settings\\UserMigration\\AccountMigrator' => $baseDir . '/../lib/UserMigration/AccountMigrator.php',
128128
'OCA\\Settings\\UserMigration\\AccountMigratorException' => $baseDir . '/../lib/UserMigration/AccountMigratorException.php',
129+
'OCA\\Settings\\WellKnown\\AssetLinksHandler' => $baseDir . '/../lib/WellKnown/AssetLinksHandler.php',
129130
'OCA\\Settings\\WellKnown\\ChangePasswordHandler' => $baseDir . '/../lib/WellKnown/ChangePasswordHandler.php',
130131
'OCA\\Settings\\WellKnown\\SecurityTxtHandler' => $baseDir . '/../lib/WellKnown/SecurityTxtHandler.php',
131132
);

apps/settings/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class ComposerStaticInitSettings
141141
'OCA\\Settings\\SetupChecks\\Woff2Loading' => __DIR__ . '/..' . '/../lib/SetupChecks/Woff2Loading.php',
142142
'OCA\\Settings\\UserMigration\\AccountMigrator' => __DIR__ . '/..' . '/../lib/UserMigration/AccountMigrator.php',
143143
'OCA\\Settings\\UserMigration\\AccountMigratorException' => __DIR__ . '/..' . '/../lib/UserMigration/AccountMigratorException.php',
144+
'OCA\\Settings\\WellKnown\\AssetLinksHandler' => __DIR__ . '/..' . '/../lib/WellKnown/AssetLinksHandler.php',
144145
'OCA\\Settings\\WellKnown\\ChangePasswordHandler' => __DIR__ . '/..' . '/../lib/WellKnown/ChangePasswordHandler.php',
145146
'OCA\\Settings\\WellKnown\\SecurityTxtHandler' => __DIR__ . '/..' . '/../lib/WellKnown/SecurityTxtHandler.php',
146147
);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"relation": [
4+
"delegate_permission/common.handle_all_urls"
5+
],
6+
"target": {
7+
"namespace": "android_app",
8+
"package_name": "",
9+
"sha256_cert_fingerprints": []
10+
}
11+
}
12+
]

apps/settings/lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
use OCA\Settings\SetupChecks\WellKnownUrls;
9595
use OCA\Settings\SetupChecks\Woff2Loading;
9696
use OCA\Settings\UserMigration\AccountMigrator;
97+
use OCA\Settings\WellKnown\AssetLinksHandler;
9798
use OCA\Settings\WellKnown\ChangePasswordHandler;
9899
use OCA\Settings\WellKnown\SecurityTxtHandler;
99100
use OCP\AppFramework\App;
@@ -136,6 +137,7 @@ public function register(IRegistrationContext $context): void {
136137
// Register well-known handlers
137138
$context->registerWellKnownHandler(SecurityTxtHandler::class);
138139
$context->registerWellKnownHandler(ChangePasswordHandler::class);
140+
$context->registerWellKnownHandler(AssetLinksHandler::class);
139141

140142
/**
141143
* Core class wrappers
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2024 Christopher Ng <chrng8@gmail.com>
7+
*
8+
* @author Christopher Ng <chrng8@gmail.com>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\Settings\WellKnown;
28+
29+
use OCP\AppFramework\Http\JSONResponse;
30+
use OCP\Http\WellKnown\GenericResponse;
31+
use OCP\Http\WellKnown\IHandler;
32+
use OCP\Http\WellKnown\IRequestContext;
33+
use OCP\Http\WellKnown\IResponse;
34+
use OCP\IConfig;
35+
36+
class AssetLinksHandler implements IHandler {
37+
38+
public function __construct(
39+
private IConfig $config,
40+
) {
41+
}
42+
43+
public function handle(string $service, IRequestContext $context, ?IResponse $previousResponse): ?IResponse {
44+
if ($service !== 'assetlinks.json') {
45+
return $previousResponse;
46+
}
47+
48+
$data = json_decode(file_get_contents(__DIR__ . '/../../data/assetlinks-template.json'), true);
49+
$data[0]['target']['package_name'] = $this->config->getSystemValueString('assetlinks_package_name', 'com.nextcloud.client');
50+
$data[0]['target']['sha256_cert_fingerprints'] = $this->config->getSystemValue(
51+
'assetlinks_sha256_cert_fingerprints',
52+
[
53+
'59:BF:BB:8A:5C:17:53:D6:69:AE:C0:D8:CC:D0:DA:82:76:FE:8E:AC:81:A4:45:22:AE:68:0E:A7:74:81:A3:32',
54+
],
55+
);
56+
return new GenericResponse(new JSONResponse($data));
57+
}
58+
}

config/config.sample.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,24 @@
11211121
'https://itunes.apple.com/us/app/nextcloud/id1125420102?mt=8',
11221122
'customclient_ios_appid' =>
11231123
'1125420102',
1124+
1125+
/**
1126+
* This configures the package name in assetlinks.json for the Android client.
1127+
*
1128+
* Defaults to ``com.nextcloud.client``
1129+
*/
1130+
'assetlinks_package_name' => 'com.nextcloud.client',
1131+
1132+
/**
1133+
* This configures the sha256 certificate fingerprints in assetlinks.json for the Android client.
1134+
*
1135+
* Defaults to an array with:
1136+
* - ``59:BF:BB:8A:5C:17:53:D6:69:AE:C0:D8:CC:D0:DA:82:76:FE:8E:AC:81:A4:45:22:AE:68:0E:A7:74:81:A3:32``
1137+
*/
1138+
'assetlinks_sha256_cert_fingerprints' => [
1139+
'59:BF:BB:8A:5C:17:53:D6:69:AE:C0:D8:CC:D0:DA:82:76:FE:8E:AC:81:A4:45:22:AE:68:0E:A7:74:81:A3:32',
1140+
],
1141+
11241142
/**
11251143
* Apps
11261144
*

0 commit comments

Comments
 (0)