Skip to content

Commit 884ca38

Browse files
authored
Merge pull request #5 from matrix-org/jaywink/support-many-homeservers
Support resolving OpenID tokens against any given homeserver
2 parents 487e1c5 + 5c703fd commit 884ca38

File tree

11 files changed

+664
-9
lines changed

11 files changed

+664
-9
lines changed

.env.default

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ UVS_HOMESERVER_URL=https://matrix.org
33
UVS_LISTEN_ADDRESS=127.0.0.1
44
UVS_PORT=3000
55
UVS_LOG_LEVEL=info
6+
UVS_OPENID_VERIFY_ANY_HOMESERVER=false

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@
22

33
## unreleased
44

5+
### Added
6+
7+
* Possibility to allow verifying any Matrix homeserver OpenID token. Default is still to
8+
only verify tokens against the configured homeserver. Room membership verification
9+
is still only done against the configured homeserver even if the token is for a user
10+
on another homeserver. ([related issue](https://github.com/matrix-org/matrix-user-verification-service/issues/3))
11+
12+
### Changes
13+
14+
* Better documentation in readme.
15+
516
## v1.1.0
617

7-
Added:
18+
### Added
819

920
* Logging, defaults to `info` level, set different level with `UVS_LOG_LEVEL`.
1021

README.md

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Matrix User Verification Service
22

3-
Service to verify details of a user based on a Open ID Connect token.
3+
Service to verify details of a user based on an Open ID Connect token.
44

55
Main features:
66

@@ -33,6 +33,136 @@ UVS_PORT=3000
3333
# (Optional) log level, defaults to 'info'
3434
# See choices here: https://github.com/winstonjs/winston#logging-levels
3535
UVS_LOG_LEVEL=info
36+
# (Optional) multiple homeserver mode, defaults to disabled
37+
# See below for more info.
38+
UVS_OPENID_VERIFY_ANY_HOMESERVER=false
39+
```
40+
41+
#### OpenID token verification
42+
43+
UVS can run in a single homeserver mode or be configured to trust any
44+
homeserver OpenID token. Default is to only trust the configured homeserver
45+
OpenID tokens.
46+
47+
To enable multiple homeserver mode:
48+
49+
UVS_OPENID_VERIFY_ANY_HOMESERVER=true
50+
51+
Note, room membership is still limited to only the configured `UVS_HOMESERVER_URL`.
52+
53+
When running with the multiple homeserver mode, `matrix_server_name` becomes
54+
a required request body item for all `/verify` verification API requests.
55+
56+
### API's available
57+
58+
#### Verify OpenID token
59+
60+
Verifies a user OpenID token.
61+
62+
POST /verify/user
63+
Content-Type: application/json
64+
65+
Request body:
66+
67+
```json
68+
{
69+
"token": "secret token"
70+
}
71+
```
72+
73+
If `UVS_OPENID_VERIFY_ANY_HOMESERVER` is set to `true`, the API also
74+
requires a `matrix_server_name`, becoming:
75+
76+
```json
77+
{
78+
"matrix_server_name": "domain.tld",
79+
"token": "secret token"
80+
}
81+
```
82+
83+
Successful validation response:
84+
85+
```json
86+
{
87+
"results": {
88+
"user": true
89+
},
90+
"user_id": "@user:domain.tld"
91+
}
92+
```
93+
94+
Failed validation:
95+
96+
```json
97+
{
98+
"results": {
99+
"user": false
100+
},
101+
"user_id": null
102+
}
103+
```
104+
105+
#### Verify OpenID token and room membership
106+
107+
Verifies a user OpenID token and membership in a room.
108+
109+
POST /verify/user_in_room
110+
Content-Type: application/json
111+
112+
Request body:
113+
114+
```json
115+
{
116+
"room_id": "!foobar:domain.tld",
117+
"token": "secret token"
118+
}
119+
```
120+
121+
If `UVS_OPENID_VERIFY_ANY_HOMESERVER` is set to `true`, the API also
122+
requires a `matrix_server_name`, becoming:
123+
124+
```json
125+
{
126+
"matrix_server_name": "domain.tld",
127+
"room_id": "!foobar:domain.tld",
128+
"token": "secret token"
129+
}
130+
```
131+
132+
Successful validation response:
133+
134+
```json
135+
{
136+
"results": {
137+
"room_membership": true,
138+
"user": true
139+
},
140+
"user_id": "@user:domain.tld"
141+
}
142+
```
143+
144+
Failed validation, in case token is not valid:
145+
146+
```json
147+
{
148+
"results": {
149+
"room_membership": false,
150+
"user": false
151+
},
152+
"user_id": null
153+
}
154+
```
155+
156+
In the token was validated but user is not in room, the failed response is:
157+
158+
```json
159+
{
160+
"results": {
161+
"room_membership": false,
162+
"user": true
163+
},
164+
"user_id": "@user:domain.tld"
165+
}
36166
```
37167

38168
### Running

package-lock.json

Lines changed: 48 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"chai": "^4.2.0",
2727
"eslint": "^7.7.0",
2828
"mocha": "^8.1.1",
29+
"mocked-env": "^1.3.2",
2930
"nodemon": "^2.0.4",
3031
"sinon": "^9.0.3"
3132
},

0 commit comments

Comments
 (0)