PHP code example of p4bgroup / ldap-jwt-authentication
1. Go to this page and download the library: Download p4bgroup/ldap-jwt-authentication library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
p4bgroup / ldap-jwt-authentication example snippets
$ldap = new Laminas\Ldap\Ldap([..]);
$authService = new AuthenticationService($ldap);
$jwtTokensService = new JWTTokensService($algorithm, $encodeKey, $decodeKey);
/** @param P4BGroup\Authentication\User $user */
$user = $authService->authenticateUser($username, $password, $userBaseDn);
$claims = new P4BGroup\Authentication\Claims();
$claims->setData($user->toArray())
->setSubject(Claims::SUBJECT_REFRESH)
->setExpirationTime(new DateTime("+10 minutes"))
$accessToken = $jwtTokensService->encode($claims);
$refreshToken = $jwtTokensService->encode($claims->setSubject(Claims::SUBJECT_REFRESH)->setExpirationTime(new DateTime("+1 hour"));