not traking certs folder
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
certs/
|
||||
35
app-code/api/login/create_passkey.php
Normal file
35
app-code/api/login/create_passkey.php
Normal file
@@ -0,0 +1,35 @@
|
||||
// registration.php
|
||||
|
||||
session_start();
|
||||
|
||||
use Webauthn\PublicKeyCredentialCreationOptions;
|
||||
use Webauthn\PublicKeyCredentialRpEntity;
|
||||
use Webauthn\PublicKeyCredentialUserEntity;
|
||||
use Webauthn\AuthenticatorSelectionCriteria;
|
||||
use Webauthn\AuthenticatorAttestationResponseValidator;
|
||||
|
||||
// Server configuration
|
||||
$rpEntity = new PublicKeyCredentialRpEntity('Example App', 'example.com');
|
||||
|
||||
// Fetch or create user
|
||||
$userId = bin2hex(random_bytes(16)); // Use a unique identifier per user
|
||||
$_SESSION['user_id'] = $userId; // Save it for verification
|
||||
$user = new PublicKeyCredentialUserEntity($userId, 'username', 'User Display Name');
|
||||
|
||||
// Generate options
|
||||
$options = new PublicKeyCredentialCreationOptions(
|
||||
$rpEntity,
|
||||
$user,
|
||||
random_bytes(16), // Challenge
|
||||
[
|
||||
['type' => 'public-key', 'alg' => -7], // Algorithms
|
||||
],
|
||||
new AuthenticatorSelectionCriteria(),
|
||||
PublicKeyCredentialCreationOptions::ATTESTATION_CONVEYANCE_PREFERENCE_NONE
|
||||
);
|
||||
|
||||
// Save options in session for later verification
|
||||
$_SESSION['creation_options'] = serialize($options);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($options, JSON_UNESCAPED_SLASHES);
|
||||
45
app-code/api/login/test.html
Normal file
45
app-code/api/login/test.html
Normal file
@@ -0,0 +1,45 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Passkey Login</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Passkey Login</h1>
|
||||
<form id="register-form">
|
||||
<button type="button" id="register">Register Passkey</button>
|
||||
</form>
|
||||
<form id="login-form">
|
||||
<button type="button" id="login">Login with Passkey</button>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
async function registerPasskey() {
|
||||
const res = await fetch('/registration.php');
|
||||
const options = await res.json();
|
||||
|
||||
// Convert the challenge and user ID to ArrayBuffer
|
||||
options.challenge = new Uint8Array(Object.values(options.challenge)).buffer;
|
||||
options.user.id = new Uint8Array(Object.values(options.user.id)).buffer;
|
||||
|
||||
const credential = await navigator.credentials.create({ publicKey: options });
|
||||
console.log(credential);
|
||||
}
|
||||
|
||||
async function loginPasskey() {
|
||||
const res = await fetch('/login.php');
|
||||
const options = await res.json();
|
||||
|
||||
// Convert challenge to ArrayBuffer
|
||||
options.challenge = new Uint8Array(Object.values(options.challenge)).buffer;
|
||||
|
||||
const assertion = await navigator.credentials.get({ publicKey: options });
|
||||
console.log(assertion);
|
||||
}
|
||||
|
||||
document.getElementById('register').addEventListener('click', registerPasskey);
|
||||
document.getElementById('login').addEventListener('click', loginPasskey);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
17
app-code/api/login/verify_passkey.php
Normal file
17
app-code/api/login/verify_passkey.php
Normal file
@@ -0,0 +1,17 @@
|
||||
// login.php
|
||||
|
||||
session_start();
|
||||
|
||||
use Webauthn\PublicKeyCredentialRequestOptions;
|
||||
use Webauthn\AuthenticatorAssertionResponseValidator;
|
||||
use Webauthn\PublicKeyCredentialLoader;
|
||||
|
||||
// Fetch stored credential information for the user
|
||||
$storedCredentialId = $_SESSION['credential_id']; // Replace with DB fetch
|
||||
$storedPublicKey = $_SESSION['public_key']; // Replace with DB fetch
|
||||
|
||||
$options = new PublicKeyCredentialRequestOptions(random_bytes(16)); // Challenge
|
||||
$_SESSION['request_options'] = serialize($options);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($options, JSON_UNESCAPED_SLASHES);
|
||||
Reference in New Issue
Block a user