-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.php
More file actions
102 lines (88 loc) · 3.12 KB
/
Copy pathrouter.php
File metadata and controls
102 lines (88 loc) · 3.12 KB
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
<?php
/**
* Tuurio Auth Studio — PHP built-in dev server router.
*
* Usage: php -S localhost:8080 router.php
*
* Routes requests to the appropriate handler and serves static
* assets from the public/ directory with correct MIME types.
*
* @author Tuurio GmbH, Berlin
* @version 1.0.0 (2026-03-07)
* @see https://id.tuurio.com
*/
declare(strict_types=1);
// Load config once so route handling and startup logging use the same values.
$config = require __DIR__ . '/src/config.php';
$webhookPath = $config['webhook_listen_path'] ?? '/webhooks/tuurio';
// Log config once per server process (sanitized) to help verify env setup.
$configPrintedFlag = sys_get_temp_dir() . '/tuurio_auth_samples_config_printed';
if (!file_exists($configPrintedFlag)) {
$safeConfig = $config;
if (!empty($safeConfig['client_secret'])) {
$secret = (string) $safeConfig['client_secret'];
$safeConfig['client_secret'] = '[set]';
$safeConfig['client_secret_len'] = strlen($secret);
$safeConfig['client_secret_sha256_prefix'] = substr(hash('sha256', $secret), 0, 8);
}
if (!empty($safeConfig['webhook_api_key'])) {
$apiKey = (string) $safeConfig['webhook_api_key'];
$safeConfig['webhook_api_key'] = '[set]';
$safeConfig['webhook_api_key_len'] = strlen($apiKey);
$safeConfig['webhook_api_key_sha256_prefix'] = substr(hash('sha256', $apiKey), 0, 8);
}
error_log('Tuurio config: ' . json_encode($safeConfig, JSON_UNESCAPED_SLASHES));
@file_put_contents($configPrintedFlag, "1");
}
$path = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/';
$publicRoot = __DIR__ . '/public';
if ($path === '/auth/callback') {
require $publicRoot . '/auth/callback/index.php';
return true;
}
if ($path === '/' && (isset($_GET['code']) || isset($_GET['error']))) {
require $publicRoot . '/auth/callback/index.php';
return true;
}
if ($path === '/login') {
require $publicRoot . '/login.php';
return true;
}
if ($path === '/logout') {
require $publicRoot . '/logout.php';
return true;
}
if ($path === '/logout/callback') {
require $publicRoot . '/logout/callback/index.php';
return true;
}
if ($path === $webhookPath) {
require $publicRoot . '/webhook.php';
return true;
}
if ($path === '/' || $path === '' || $path === '/index.php') {
require $publicRoot . '/home.php';
return true;
}
$target = realpath($publicRoot . $path);
if ($target && strpos($target, realpath($publicRoot)) === 0 && is_file($target)) {
$ext = strtolower(pathinfo($target, PATHINFO_EXTENSION));
$mimeTypes = [
'css' => 'text/css',
'js' => 'application/javascript',
'svg' => 'image/svg+xml',
'png' => 'image/png',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'gif' => 'image/gif',
'ico' => 'image/x-icon',
'woff' => 'font/woff',
'woff2' => 'font/woff2',
'json' => 'application/json',
];
header('Content-Type: ' . ($mimeTypes[$ext] ?? 'application/octet-stream'));
readfile($target);
return true;
}
require $publicRoot . '/404.php';
return true;