|
|
Authentifizierung
|
|
|
======
|
|
|
|
|
|
Die Authenticator API erlaubt es Modulen, QUIQQER mit eigenen Authentifizierungsmethoden zu erweitern. QUIQQER bietet schon einige Authentifizierungsmethoden von Haus aus an.
|
|
|
|
|
|
- [QUIQQER Authentication with Google Authenticator](https://dev.quiqqer.com/quiqqer/authgoogle2fa)
|
|
|
- [QUIQQER Authentication via Facebook Login](https://dev.quiqqer.com/quiqqer/authfacebook)
|
|
|
|
|
|
|
|
|
Neuer Authenticator realisieren
|
|
|
------
|
|
|
|
|
|
Ein Authenticator ist eine Authentifzierungsklasse welche einen Benutzer am QUIQQER System über externe Services anmeldet.
|
|
|
|
|
|
**Vorgehensweise:**
|
|
|
|
|
|
1. Authenticator Provider registrieren
|
|
|
2. Authenticator Provider realisieren
|
|
|
|
|
|
### Authenticator Provider registrieren
|
|
|
|
|
|
Erweitern Sie die [package.xml](/Package-Xml) um einen `<auth>` Provider Eintrag. Das `src` Attribut gibt an, wo Ihr neuer Authenticator zu finden ist.
|
|
|
|
|
|
```xml
|
|
|
<quiqqer>
|
|
|
<package>
|
|
|
|
|
|
<!-- .... PAKET DATEN -->
|
|
|
|
|
|
<provider>
|
|
|
<auth src="\QUI\NameSpace\NameSpace\MyAuthenticator" />
|
|
|
</provider>
|
|
|
|
|
|
</package>
|
|
|
</quiqqer>
|
|
|
```
|
|
|
|
|
|
### Authenticator Provider realisieren
|
|
|
|
|
|
Ein Authenticator muss das `QUI\Users\AuthenticatorInterface` implementieren. Die einfachste Methode mit einem Authenticator anzufangen ist es, vom `QUI\Users\AbstractAuthenticator` zu erben. So müssen Sie nicht alle Methoden die das `QUI\Users\AuthenticatorInterface` vorgibt selbst implementieren.
|
|
|
|
|
|
```php
|
|
|
<?php
|
|
|
|
|
|
namespace QUI\NameSpace\NameSpace;
|
|
|
|
|
|
use QUI;
|
|
|
|
|
|
/**
|
|
|
* Class MyAuthenticator
|
|
|
*/
|
|
|
class MyAuthenticator extends QUI\Users\AbstractAuthenticator
|
|
|
{
|
|
|
public function __construct($username= '')
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
public function auth($authData)
|
|
|
{
|
|
|
// $authData = Authenzifizierungsdaten / password, Hashes oder ähnliches
|
|
|
// HIer findet der Authenzifizierungsprozess statt
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param null|\QUI\Locale $Locale
|
|
|
* @return string
|
|
|
*/
|
|
|
public function getTitle($Locale = null)
|
|
|
{
|
|
|
return 'Title';
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param null|\QUI\Locale $Locale
|
|
|
* @return string
|
|
|
*/
|
|
|
public function getDescription($Locale = null)
|
|
|
{
|
|
|
return 'Description';
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
Dem Konstruktur wird zu Anfang der Benutzername übergeben welche sich am System anmelden möchten über die `auth` Methode wird der Benutzer am System authentifiziert. Diese zwei Methoden bilden das grundsätzliche Vorgehen für den Authentifizierungsprozesses.
|
|
|
|
|
|
Ist der Authentifizierungsprozesses nicht erfolgreich muss die `auth` methode ein Exception vom Typ `QUI\Users\Exception` werfen.
|
|
|
|
|
|
```php
|
|
|
<?php
|
|
|
|
|
|
public function auth($password)
|
|
|
{
|
|
|
if (!is_string($this->username) || empty($this->username)) {
|
|
|
throw new QUI\Users\Exception(
|
|
|
array('quiqqer/system', 'exception.login.fail.wrong.username.input'),
|
|
|
401
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|
|
|
Für Funktionalität wie, Passwort vergessen, Registrierung, Login oder Einstellungen kann der Authenticator eigene `QUI\Controls` mitbringen.
|
|
|
Hierzu können folgende Methoden im eigenen Authenticator überschrieben werden:
|
|
|
|
|
|
```php
|
|
|
<?php
|
|
|
|
|
|
public static function getLoginControl()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
public static function getRegisterControl()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
public static function getPasswordResetControl()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
public static function getSettingsControl()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
#### Beispiel für ein eigenes Login
|
|
|
|
|
|
```php
|
|
|
<?php
|
|
|
|
|
|
/**
|
|
|
* This file contains QUI\Users\Auth\QUIQQER
|
|
|
*/
|
|
|
namespace QUI\Users\Auth;
|
|
|
|
|
|
use QUI;
|
|
|
use QUI\Users\AbstractAuthenticator;
|
|
|
use QUI\Utils\Security\Orthos;
|
|
|
|
|
|
/**
|
|
|
* Class Auth
|
|
|
* Standard QUIQQER Authentication
|
|
|
*
|
|
|
* @package QUI\Users
|
|
|
*/
|
|
|
class QUIQQER extends AbstractAuthenticator
|
|
|
{
|
|
|
|
|
|
public function __construct($username = '')
|
|
|
{
|
|
|
// construct
|
|
|
}
|
|
|
|
|
|
public function auth($password)
|
|
|
{
|
|
|
// auth
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Controls
|
|
|
*/
|
|
|
|
|
|
/**
|
|
|
* @return Controls\QUIQQERLogin
|
|
|
*/
|
|
|
public static function getLoginControl()
|
|
|
{
|
|
|
return new Controls\QUIQQERLogin();
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
- [Login Control Übersicht](https://dev.quiqqer.com/quiqqer/quiqqer/tree/dev/lib/QUI/Users/Auth/Controls)
|
|
|
- [Login Control](https://dev.quiqqer.com/quiqqer/quiqqer/blob/dev/lib/QUI/Users/Auth/Controls/QUIQQERLogin.php)
|
|
|
- [Login Control HTML](https://dev.quiqqer.com/quiqqer/quiqqer/blob/dev/lib/QUI/Users/Auth/Controls/QUIQQERLogin.html)
|
|
|
|
|
|
Das Login Control von QUIQQER ist ein einfaches Beispiel wie ein normale Login über Benutzername und Passwort realisiert werden kann. |