PHP code example of matthewslouismarie / auth-abstractor
1. Go to this page and download the library: Download matthewslouismarie/auth-abstractor 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/ */
matthewslouismarie / auth-abstractor example snippets
$kernel = new AuthenticationKernel(new ApplicationConfiguration(
'https://example.org', // HTTPS URL of your app (for U2F)
'https://example.org/assets', // Assets base URL
// This function is responsible for fetching members from the database.
// It must return null if the member does not exist.
function (string $username) use ($repo): ?IMember {
return $repo->findOneBy([
'username' => $username,
]);
}
));
$authProcess = $kernel
->getAuthenticationProcessFactory()
->createProcess([
CredentialChallenge::class, // class that is part of auth-abstractor
]
);
$authResponse = $kernel->processHttpRequest(
$httpRequest,
$authProcess, // The $authProcess object just created or retrieved from session
new Callback(
function ($authProcess) { // if the user fails authenticating
new Response('You tried too many login attempts!');
},
function ($authProcess) { // if the user succeeds logging in
$_SESSION['logged_in'] = true;
new Response('You\'re logged in!');
}
)
);
// store new auth_process in session
$_SESSION['auth_process'] = $response->getAuthenticationProcess();
// display http response to user
return $response->getHttpResponse();
foreach ($authProcess->getPersistOperations() as $operation) {
if ($operation->getType()->is(new Operation(Operation::CREATE))) {
$member = $operation->getObject();
if (is_a($member, IMember::class)) {
// Saves $member in the database
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.