mirror of
https://github.com/etkecc/synapse-admin.git
synced 2024-11-24 00:25:31 +03:00
Allow providing login form details via GET params (#140)
* Allow providing login form details via GET params * add http:// to serverURL if it's only domian name * update readme
This commit is contained in:
parent
1570ca5485
commit
915e3564f8
3 changed files with 44 additions and 7 deletions
17
README.md
17
README.md
|
@ -23,6 +23,7 @@ This project is built using [react-admin](https://marmelab.com/react-admin/).
|
||||||
* [Changes](#changes)
|
* [Changes](#changes)
|
||||||
* [Development](#development)
|
* [Development](#development)
|
||||||
* [Configuration](#configuration)
|
* [Configuration](#configuration)
|
||||||
|
* [Prefilling login form](#prefilling-login-form)
|
||||||
* [Restricting available homeserver](#restricting-available-homeserver)
|
* [Restricting available homeserver](#restricting-available-homeserver)
|
||||||
* [Protecting appservice managed users](#protecting-appservice-managed-users)
|
* [Protecting appservice managed users](#protecting-appservice-managed-users)
|
||||||
* [Adding custom menu items](#adding-custom-menu-items)
|
* [Adding custom menu items](#adding-custom-menu-items)
|
||||||
|
@ -92,6 +93,7 @@ with a proper manifest.json generation on build)
|
||||||
* [Add option to set user's rate limits](https://github.com/etkecc/synapse-admin/pull/125)
|
* [Add option to set user's rate limits](https://github.com/etkecc/synapse-admin/pull/125)
|
||||||
* [Support configuration via /.well-known/matrix/client](https://github.com/etkecc/synapse-admin/pull/126)
|
* [Support configuration via /.well-known/matrix/client](https://github.com/etkecc/synapse-admin/pull/126)
|
||||||
* [Prevent accidental user overwrites](https://github.com/etkecc/synapse-admin/pull/139)
|
* [Prevent accidental user overwrites](https://github.com/etkecc/synapse-admin/pull/139)
|
||||||
|
* [Allow providing login form details via GET params](https://github.com/etkecc/synapse-admin/pull/140)
|
||||||
|
|
||||||
_the list will be updated as new changes are added_
|
_the list will be updated as new changes are added_
|
||||||
|
|
||||||
|
@ -129,6 +131,17 @@ services:
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Prefilling login form
|
||||||
|
|
||||||
|
You can prefill `username` and `homeserver` fields on the login page using GET parameters, example:
|
||||||
|
|
||||||
|
```
|
||||||
|
https://matrix.example.com/synapse-admin/?username=admin&server=matrix.example.com
|
||||||
|
```
|
||||||
|
|
||||||
|
That way `username` and `homeserver` fields will be pre-filled with `admin` and `https://matrix.example.com` respectively.
|
||||||
|
|
||||||
|
|
||||||
### Restricting available homeserver
|
### Restricting available homeserver
|
||||||
|
|
||||||
You can restrict the homeserver(s), so that the user can no longer define it himself.
|
You can restrict the homeserver(s), so that the user can no longer define it himself.
|
||||||
|
@ -137,7 +150,7 @@ Edit `config.json` to restrict either to a single homeserver:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"restrictBaseUrl": "https://your-matrixs-erver.example.com"
|
"restrictBaseUrl": "https://matrix.example.com"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -146,7 +159,7 @@ similar for `/.well-known/matrix/client`:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"cc.etke.synapse-admin": {
|
"cc.etke.synapse-admin": {
|
||||||
"restrictBaseUrl": "https://your-matrixs-erver.example.com"
|
"restrictBaseUrl": "https://matrix.example.com"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -8,7 +8,12 @@ import { AppContext } from "./AppContext";
|
||||||
import storage from "./storage";
|
import storage from "./storage";
|
||||||
|
|
||||||
// load config.json
|
// load config.json
|
||||||
let props: Config = {};
|
let props: Config = {
|
||||||
|
restrictBaseUrl: [],
|
||||||
|
asManagedUsers: [],
|
||||||
|
supportURL: "",
|
||||||
|
menu: [],
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
const resp = await fetch("config.json");
|
const resp = await fetch("config.json");
|
||||||
const configJSON = await resp.json();
|
const configJSON = await resp.json();
|
||||||
|
|
|
@ -96,6 +96,9 @@ const LoginPage = () => {
|
||||||
|
|
||||||
const handleSubmit = auth => {
|
const handleSubmit = auth => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
const cleanUrl = window.location.href.replace(window.location.search, "");
|
||||||
|
window.history.replaceState({}, "", cleanUrl);
|
||||||
|
|
||||||
login(auth).catch(error => {
|
login(auth).catch(error => {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
notify(
|
notify(
|
||||||
|
@ -166,6 +169,22 @@ const LoginPage = () => {
|
||||||
.catch(() => setSSOBaseUrl(""));
|
.catch(() => setSSOBaseUrl(""));
|
||||||
}, [formData.base_url, form]);
|
}, [formData.base_url, form]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
const username = params.get("username");
|
||||||
|
let serverURL = params.get("server");
|
||||||
|
if (username) {
|
||||||
|
form.setValue("username", username);
|
||||||
|
}
|
||||||
|
if (serverURL) {
|
||||||
|
const isFullUrl = serverURL.match(/^(http|https):\/\//);
|
||||||
|
if (!isFullUrl) {
|
||||||
|
serverURL = `https://${serverURL}`;
|
||||||
|
}
|
||||||
|
form.setValue("base_url", serverURL);
|
||||||
|
}
|
||||||
|
}, [window.location.search]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Tabs
|
<Tabs
|
||||||
|
@ -186,10 +205,10 @@ const LoginPage = () => {
|
||||||
source="username"
|
source="username"
|
||||||
label="ra.auth.username"
|
label="ra.auth.username"
|
||||||
autoComplete="username"
|
autoComplete="username"
|
||||||
disabled={loading || !supportPassAuth}
|
|
||||||
onBlur={handleUsernameChange}
|
onBlur={handleUsernameChange}
|
||||||
resettable
|
resettable
|
||||||
validate={required()}
|
validate={required()}
|
||||||
|
{...(loading || !supportPassAuth ? { disabled: true } : {})}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
<Box>
|
<Box>
|
||||||
|
@ -198,7 +217,7 @@ const LoginPage = () => {
|
||||||
label="ra.auth.password"
|
label="ra.auth.password"
|
||||||
type="password"
|
type="password"
|
||||||
autoComplete="current-password"
|
autoComplete="current-password"
|
||||||
disabled={loading || !supportPassAuth}
|
{...(loading || !supportPassAuth ? { disabled: true } : {})}
|
||||||
resettable
|
resettable
|
||||||
validate={required()}
|
validate={required()}
|
||||||
/>
|
/>
|
||||||
|
@ -209,7 +228,7 @@ const LoginPage = () => {
|
||||||
<TextInput
|
<TextInput
|
||||||
source="accessToken"
|
source="accessToken"
|
||||||
label="synapseadmin.auth.access_token"
|
label="synapseadmin.auth.access_token"
|
||||||
disabled={loading}
|
{...(loading ? { disabled: true } : {})}
|
||||||
resettable
|
resettable
|
||||||
validate={required()}
|
validate={required()}
|
||||||
/>
|
/>
|
||||||
|
@ -221,7 +240,7 @@ const LoginPage = () => {
|
||||||
label="synapseadmin.auth.base_url"
|
label="synapseadmin.auth.base_url"
|
||||||
select={allowMultipleBaseUrls}
|
select={allowMultipleBaseUrls}
|
||||||
autoComplete="url"
|
autoComplete="url"
|
||||||
disabled={loading}
|
{...(loading ? { disabled: true } : {})}
|
||||||
readOnly={allowSingleBaseUrl}
|
readOnly={allowSingleBaseUrl}
|
||||||
resettable={allowAnyBaseUrl}
|
resettable={allowAnyBaseUrl}
|
||||||
validate={[required(), validateBaseUrl]}
|
validate={[required(), validateBaseUrl]}
|
||||||
|
|
Loading…
Reference in a new issue