mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 03:06:31 -05:00
Feature/ldap sign in (#27)
* reworked via-ldap component * added username i18nkey * added customAuthNames to backend config * added postLdapLogin api call Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
fbd29c0338
commit
5eb8ab7517
7 changed files with 99 additions and 26 deletions
|
@ -12,6 +12,9 @@
|
||||||
"oauth2": false,
|
"oauth2": false,
|
||||||
"email": true
|
"email": true
|
||||||
},
|
},
|
||||||
|
"customAuthNames": {
|
||||||
|
"ldap": "FooBar"
|
||||||
|
},
|
||||||
"specialLinks": {
|
"specialLinks": {
|
||||||
"privacy": "test",
|
"privacy": "test",
|
||||||
"termsOfUse": "test",
|
"termsOfUse": "test",
|
||||||
|
|
|
@ -122,5 +122,6 @@
|
||||||
"errorEmailLogin": "E-Mail oder Passwort nicht korrekt",
|
"errorEmailLogin": "E-Mail oder Passwort nicht korrekt",
|
||||||
"errorLdapLogin": "Benutzername oder Passwort nicht korrekt",
|
"errorLdapLogin": "Benutzername oder Passwort nicht korrekt",
|
||||||
"email": "E-Mail",
|
"email": "E-Mail",
|
||||||
"password": "Passwort"
|
"password": "Passwort",
|
||||||
|
"username": "Benutzername"
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,5 +122,6 @@
|
||||||
"errorEmailLogin": "Invalid email or password",
|
"errorEmailLogin": "Invalid email or password",
|
||||||
"errorLdapLogin": "Invalid username or password",
|
"errorLdapLogin": "Invalid username or password",
|
||||||
"email": "Email",
|
"email": "Email",
|
||||||
"password": "Password"
|
"password": "Password",
|
||||||
|
"username": "Username"
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,3 +23,23 @@ export const postEmailLogin = async (email: string, password: string) => {
|
||||||
.then(expectResponseCode())
|
.then(expectResponseCode())
|
||||||
.then(response => response.json());
|
.then(response => response.json());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const postLdapLogin = async (username: string, password: string) => {
|
||||||
|
return fetch(getBackendUrl() + "/auth/ldap", {
|
||||||
|
method: 'POST',
|
||||||
|
mode: 'cors',
|
||||||
|
cache: 'no-cache',
|
||||||
|
credentials: 'same-origin',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
redirect: 'follow',
|
||||||
|
referrerPolicy: 'no-referrer',
|
||||||
|
body: JSON.stringify({
|
||||||
|
username: username,
|
||||||
|
password: password,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(expectResponseCode())
|
||||||
|
.then(response => response.json());
|
||||||
|
}
|
||||||
|
|
|
@ -1,30 +1,70 @@
|
||||||
import React, {Fragment} from "react";
|
import React, {Fragment, useState} from "react";
|
||||||
import {Trans} from "react-i18next";
|
import {Trans, useTranslation} from "react-i18next";
|
||||||
import {Button, Form} from "react-bootstrap";
|
import {Alert, Button, Form} from "react-bootstrap";
|
||||||
|
import {postLdapLogin} from "../../../../../api/user";
|
||||||
|
import {getAndSetUser} from "../../../../../utils/apiUtils";
|
||||||
|
import {useSelector} from "react-redux";
|
||||||
|
import {ApplicationState} from "../../../../../redux";
|
||||||
|
|
||||||
const ViaLdap: React.FC = () => {
|
const ViaLdap: React.FC = () => {
|
||||||
|
const {t} = useTranslation();
|
||||||
|
const ldapCustomName = useSelector((state: ApplicationState) => state.backendConfig.customAuthNames.ldap);
|
||||||
|
const [username, setUsername] = useState("");
|
||||||
|
const [password, setPassword] = useState("");
|
||||||
|
const [error, setError] = useState(false);
|
||||||
|
const login = (event: any) => {
|
||||||
|
postLdapLogin(username, password)
|
||||||
|
.then(loginJson => {
|
||||||
|
console.log(loginJson)
|
||||||
|
getAndSetUser();
|
||||||
|
}).catch(_reason => {
|
||||||
|
setError(true);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
const name = ldapCustomName ? `${ldapCustomName} (LDAP)` : "LDAP";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<h5 className="center">
|
<h5 className="center">
|
||||||
<Trans i18nKey="signInVia" values={{service: "LDAP"}}/>
|
<Trans i18nKey="signInVia" values={{service: name}}/>
|
||||||
</h5>
|
</h5>
|
||||||
<Form>
|
<Form onSubmit={login}>
|
||||||
<Form.Group controlId="formBasicUsername">
|
<Form.Group controlId="email">
|
||||||
<Form.Control type="text" size="sm" placeholder="Username" />
|
<Form.Control
|
||||||
|
isInvalid={error}
|
||||||
|
type="text"
|
||||||
|
size="sm"
|
||||||
|
placeholder={t("username")}
|
||||||
|
onChange={(event) => setUsername(event.currentTarget.value)}
|
||||||
|
/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
|
|
||||||
<Form.Group controlId="formBasicPassword">
|
<Form.Group controlId="password">
|
||||||
<Form.Control type="password" size="sm" placeholder="Password" />
|
<Form.Control
|
||||||
|
isInvalid={error}
|
||||||
|
type="password"
|
||||||
|
size="sm"
|
||||||
|
placeholder={t("password")}
|
||||||
|
onChange={(event) => setPassword(event.currentTarget.value)}
|
||||||
|
/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
|
|
||||||
|
<Alert className="small" show={error} variant="danger">
|
||||||
|
<Trans i18nKey="errorLdapLogin"/>
|
||||||
|
</Alert>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
type="submit"
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="primary"
|
variant="primary">
|
||||||
>
|
|
||||||
<Trans i18nKey="signIn"/>
|
<Trans i18nKey="signIn"/>
|
||||||
</Button>
|
</Button>
|
||||||
</Form>
|
</Form>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
)
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export { ViaLdap }
|
export { ViaLdap }
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {BackendConfigActions, BackendConfigState, SET_BACKEND_CONFIG_ACTION_TYPE
|
||||||
export const initialState: BackendConfigState = {
|
export const initialState: BackendConfigState = {
|
||||||
allowAnonymous: true,
|
allowAnonymous: true,
|
||||||
authProviders: {
|
authProviders: {
|
||||||
facebook: true,
|
facebook: false,
|
||||||
github: false,
|
github: false,
|
||||||
twitter: false,
|
twitter: false,
|
||||||
gitlab: false,
|
gitlab: false,
|
||||||
|
@ -15,6 +15,9 @@ export const initialState: BackendConfigState = {
|
||||||
oauth2: false,
|
oauth2: false,
|
||||||
email: false
|
email: false
|
||||||
},
|
},
|
||||||
|
customAuthNames: {
|
||||||
|
ldap: ""
|
||||||
|
},
|
||||||
specialLinks: {
|
specialLinks: {
|
||||||
privacy: "",
|
privacy: "",
|
||||||
termsOfUse: "",
|
termsOfUse: "",
|
||||||
|
|
|
@ -5,20 +5,25 @@ export const SET_BACKEND_CONFIG_ACTION_TYPE = 'backend-config/set';
|
||||||
export interface BackendConfigState {
|
export interface BackendConfigState {
|
||||||
allowAnonymous: boolean,
|
allowAnonymous: boolean,
|
||||||
authProviders: AuthProvidersState,
|
authProviders: AuthProvidersState,
|
||||||
|
customAuthNames: CustomAuthNames,
|
||||||
specialLinks: SpecialLinks,
|
specialLinks: SpecialLinks,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AuthProvidersState {
|
export interface AuthProvidersState {
|
||||||
facebook: true,
|
facebook: boolean,
|
||||||
github: false,
|
github: boolean,
|
||||||
twitter: false,
|
twitter: boolean,
|
||||||
gitlab: false,
|
gitlab: boolean,
|
||||||
dropbox: false,
|
dropbox: boolean,
|
||||||
ldap: false,
|
ldap: boolean,
|
||||||
google: false,
|
google: boolean,
|
||||||
saml: false,
|
saml: boolean,
|
||||||
oauth2: false,
|
oauth2: boolean,
|
||||||
email: false,
|
email: boolean,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CustomAuthNames {
|
||||||
|
ldap: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SpecialLinks {
|
export interface SpecialLinks {
|
||||||
|
|
Loading…
Reference in a new issue