Added session details/fingerprint (w/ icons)
This commit is contained in:
@ -35,14 +35,36 @@ function authenticateLDAP (string $username, string $password) {
|
||||
if (@ldap_bind($ds, $qualifiedUsername, utf8_encode($_POST['password']))) {
|
||||
// Successful authentication; get additional userdetails from authenticationsource
|
||||
$ldapSearchResults = ldap_search($ds, $settings->LDAP['BaseDN'], "sAMAccountName=$sanitizedUsername");
|
||||
$commonName = ldap_get_entries($ds, $ldapSearchResults)[0]['cn'][0];
|
||||
// Create JWT-payload
|
||||
$commonName = ldap_get_entries($ds, $ldapSearchResults)[0]['cn'][0];
|
||||
|
||||
$browserDetails = get_browser(null, True);
|
||||
$geoLocation = json_decode(file_get_contents("http://ip-api.com/json/{$_SERVER['HTTP_X_REAL_IP']}"));
|
||||
if ($geoLocation->status === 'fail') {
|
||||
switch ($geoLocation->message) {
|
||||
case 'private range':
|
||||
case 'reserved range':
|
||||
$geoLocation = json_decode(file_get_contents("http://ip-api.com/json/" . trim(file_get_contents('https://api.ipify.org')) ));
|
||||
break;
|
||||
case 'invalid query':
|
||||
default:
|
||||
$geoLocation->city = null;
|
||||
$geoLocation->countryCode = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Create JWT-payload
|
||||
$jwtPayload = [
|
||||
'iat' => time(), // Issued at: time when the token was generated
|
||||
'iss' => $_SERVER['SERVER_NAME'], // Issuer
|
||||
'sub' => $qualifiedUsername, // Subject (ie. username)
|
||||
'name' => $commonName, // Common name (as retrieved from AD)
|
||||
'fp' => base64_encode(json_encode(get_browser(null, True))) // Fingerprint (based on `HTTP_USER_AGENT`)
|
||||
'iat' => time(), // Issued at: time when the token was generated
|
||||
'iss' => $_SERVER['SERVER_NAME'], // Issuer
|
||||
'sub' => $qualifiedUsername, // Subject (ie. username)
|
||||
'name' => $commonName, // Common name (as retrieved from AD)
|
||||
'fp' => base64_encode(json_encode((object) [ // Fingerprint
|
||||
'browser' => $browserDetails['browser'],
|
||||
'platform' => $browserDetails['platform'],
|
||||
'city' => $geoLocation->city,
|
||||
'countrycode' => $geoLocation->countryCode
|
||||
]))
|
||||
];
|
||||
|
||||
$secureToken = JWT::encode($jwtPayload, base64_decode($settings->JWT['PrivateKey_base64']));
|
||||
|
Reference in New Issue
Block a user