forked from nkuntz1934/matrix-workers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversions.ts
More file actions
196 lines (178 loc) · 5.63 KB
/
versions.ts
File metadata and controls
196 lines (178 loc) · 5.63 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
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
// Matrix Client-Server API version endpoints
import { Hono } from 'hono';
import type { AppEnv } from '../types';
const app = new Hono<AppEnv>();
// GET /.well-known/matrix/client
app.get('/.well-known/matrix/client', (c) => {
const serverName = c.env.SERVER_NAME;
const baseUrl = `https://${serverName}`;
const response: Record<string, unknown> = {
'm.homeserver': {
base_url: baseUrl,
},
// Native sliding sync support - no proxy needed
'org.matrix.msc3575.proxy': {
url: baseUrl,
},
};
// Add MatrixRTC (LiveKit) focus if configured
if (c.env.LIVEKIT_URL && c.env.LIVEKIT_API_KEY) {
response['org.matrix.msc4143.rtc_foci'] = [
{
type: 'livekit',
livekit_service_url: `${baseUrl}/livekit/get_token`,
},
];
}
return c.json(response);
});
// GET /.well-known/matrix/server
app.get('/.well-known/matrix/server', (c) => {
const serverName = c.env.SERVER_NAME;
return c.json({
'm.server': `${serverName}:443`,
});
});
// GET /.well-known/openid-configuration - OIDC Discovery endpoint
// This is required for Element Web OIDC-native authentication
// See: https://spec.matrix.org/v1.17/client-server-api/#oauth-20-api
app.get('/.well-known/openid-configuration', (c) => {
const serverName = c.env.SERVER_NAME;
const baseUrl = `https://${serverName}`;
// Return standard OIDC discovery document
// Element Web requires all these fields to be present
return c.json({
issuer: baseUrl,
authorization_endpoint: `${baseUrl}/oauth/authorize`,
token_endpoint: `${baseUrl}/oauth/token`,
userinfo_endpoint: `${baseUrl}/oauth/userinfo`,
jwks_uri: `${baseUrl}/.well-known/jwks.json`,
registration_endpoint: `${baseUrl}/oauth/register`,
revocation_endpoint: `${baseUrl}/oauth/revoke`,
introspection_endpoint: `${baseUrl}/oauth/introspect`,
scopes_supported: [
'openid',
'profile',
'email',
'urn:matrix:org.matrix.msc2967.client:api:*',
'urn:matrix:org.matrix.msc2967.client:device:*',
],
response_types_supported: ['code'],
response_modes_supported: ['query', 'fragment'],
grant_types_supported: ['authorization_code', 'refresh_token'],
token_endpoint_auth_methods_supported: ['client_secret_basic', 'client_secret_post', 'none'],
code_challenge_methods_supported: ['S256', 'plain'],
subject_types_supported: ['public'],
id_token_signing_alg_values_supported: ['RS256', 'ES256'],
claims_supported: ['sub', 'iss', 'aud', 'exp', 'iat', 'name', 'email'],
// Matrix-specific extension
'org.matrix.matrix-authentication-service': {
graphql_endpoint: null,
account: {
issuer: baseUrl,
},
},
});
});
// GET /.well-known/jwks.json - JSON Web Key Set for token verification
app.get('/.well-known/jwks.json', (c) => {
// Return an empty JWKS - clients can't verify our tokens without keys
// In a real implementation, you'd generate and store RSA keys
// For now, returning a placeholder that indicates we use opaque tokens
return c.json({
keys: [],
});
});
// GET /.well-known/matrix/support - Server support contact information
// Spec: https://spec.matrix.org/v1.17/client-server-api/#getwell-knownmatrixsupport
app.get('/.well-known/matrix/support', (c) => {
const contacts: Array<{
role: string;
email_address?: string;
matrix_id?: string;
}> = [];
// Add admin contact if configured
if (c.env.ADMIN_CONTACT_EMAIL || c.env.ADMIN_CONTACT_MXID) {
contacts.push({
role: 'm.role.admin',
email_address: c.env.ADMIN_CONTACT_EMAIL,
matrix_id: c.env.ADMIN_CONTACT_MXID,
});
}
const response: {
contacts: typeof contacts;
support_page?: string;
} = {
contacts,
};
if (c.env.SUPPORT_PAGE_URL) {
response.support_page = c.env.SUPPORT_PAGE_URL;
}
return c.json(response);
});
// GET /_matrix/client/versions
app.get('/_matrix/client/versions', (c) => {
return c.json({
versions: [
'r0.0.1',
'r0.1.0',
'r0.2.0',
'r0.3.0',
'r0.4.0',
'r0.5.0',
'r0.6.0',
'r0.6.1',
'v1.1',
'v1.2',
'v1.3',
'v1.4',
'v1.5',
'v1.6',
'v1.7',
'v1.8',
'v1.9',
'v1.10',
'v1.11',
'v1.12',
],
unstable_features: {
'org.matrix.label_based_filtering': true,
'org.matrix.e2e_cross_signing': true,
'org.matrix.msc2432': true,
'org.matrix.msc3440.stable': true,
'uk.half-shot.msc2666.query_mutual_rooms': true,
'io.element.e2ee_forced.public': false,
'io.element.e2ee_forced.private': false,
'io.element.e2ee_forced.trusted_private': false,
'org.matrix.msc3026.busy_presence': false,
'org.matrix.msc2285.stable': true,
'org.matrix.msc3827.stable': true,
'org.matrix.msc3881': true,
'org.matrix.msc3882': false,
// MatrixRTC - VoIP calls with LiveKit (MSC3401, MSC4143)
'org.matrix.msc3401': true,
'org.matrix.msc4143': true,
// Sliding Sync (MSC3575) - native implementation
'org.matrix.msc3575': true,
// Simplified Sliding Sync (MSC4186)
'org.matrix.simplified_msc3575': true,
// Additional sliding sync related features
'org.matrix.msc3575.e2ee': true,
'org.matrix.msc3575.to_device': true,
'org.matrix.msc3575.account_data': true,
'org.matrix.msc3575.receipts': true,
'org.matrix.msc3575.typing': true,
'org.matrix.msc3575.presence': true,
},
});
});
// GET /_matrix/federation/v1/version
app.get('/_matrix/federation/v1/version', (c) => {
return c.json({
server: {
name: 'matrix-worker',
version: c.env.SERVER_VERSION,
},
});
});
export default app;