mirror of
https://github.com/getnamingo/registry.git
synced 2025-06-29 23:53:17 +02:00
More WebAuthn updates
This commit is contained in:
parent
5b18318ab6
commit
480a3c3f2f
2 changed files with 10 additions and 17 deletions
|
@ -112,12 +112,11 @@ class AuthController extends Controller
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$db = $container->get('db');
|
$db = $container->get('db');
|
||||||
$user = $db->selectValue('SELECT id FROM users WHERE email = ?', [$data['email']]);
|
$userId = $db->selectValue('SELECT id FROM users WHERE email = ?', [$data['email']]);
|
||||||
|
|
||||||
if ($user) {
|
if ($userId) {
|
||||||
// User found, get the user ID
|
// User found, get the user ID
|
||||||
$userId = $user;
|
$registrations = $db->select('SELECT id,credential_id FROM users_webauthn WHERE user_id = ?', [$userId]);
|
||||||
$registrations = $db->select('SELECT id,credential_id FROM users_webauthn WHERE user_id = ?', [$user]);
|
|
||||||
|
|
||||||
if ($registrations) {
|
if ($registrations) {
|
||||||
foreach ($registrations as $reg) {
|
foreach ($registrations as $reg) {
|
||||||
|
@ -141,8 +140,7 @@ class AuthController extends Controller
|
||||||
$getArgs = $this->webAuthn->getGetArgs($ids, 60*4, true, true, true, true, true, 'required');
|
$getArgs = $this->webAuthn->getGetArgs($ids, 60*4, true, true, true, true, true, 'required');
|
||||||
|
|
||||||
$response->getBody()->write(json_encode($getArgs));
|
$response->getBody()->write(json_encode($getArgs));
|
||||||
$challenge = $this->webAuthn->getChallenge();
|
$_SESSION['challenge'] = $this->webAuthn->getChallenge();
|
||||||
$_SESSION['challenge_data'] = $challenge->getBinaryString();
|
|
||||||
|
|
||||||
return $response->withHeader('Content-Type', 'application/json');
|
return $response->withHeader('Content-Type', 'application/json');
|
||||||
}
|
}
|
||||||
|
@ -151,8 +149,7 @@ class AuthController extends Controller
|
||||||
{
|
{
|
||||||
global $container;
|
global $container;
|
||||||
|
|
||||||
$challengeData = $_SESSION['challenge_data'];
|
$challenge = $_SESSION['challenge'];
|
||||||
$challenge = new \lbuchs\WebAuthn\Binary\ByteBuffer($challengeData);
|
|
||||||
$credentialPublicKey = null;
|
$credentialPublicKey = null;
|
||||||
|
|
||||||
$data = json_decode($request->getBody()->getContents(), null, 512, JSON_THROW_ON_ERROR);
|
$data = json_decode($request->getBody()->getContents(), null, 512, JSON_THROW_ON_ERROR);
|
||||||
|
@ -185,7 +182,7 @@ class AuthController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
// process the get request. throws WebAuthnException if it fails
|
// process the get request. throws WebAuthnException if it fails
|
||||||
$this->webAuthn->processGet($clientDataJSON, $authenticatorData, $signature, $credentialPublicKey, $challengeData, null, 'required');
|
$this->webAuthn->processGet($clientDataJSON, $authenticatorData, $signature, $credentialPublicKey, $challenge, null, 'required');
|
||||||
|
|
||||||
$return = new \stdClass();
|
$return = new \stdClass();
|
||||||
$return->success = true;
|
$return->success = true;
|
||||||
|
|
|
@ -148,17 +148,13 @@ class ProfileController extends Controller
|
||||||
$createArgs = $this->webAuthn->getCreateArgs(\hex2bin($hexUserId), $userEmail, $userName, 60*4, null, 'required', null);
|
$createArgs = $this->webAuthn->getCreateArgs(\hex2bin($hexUserId), $userEmail, $userName, 60*4, null, 'required', null);
|
||||||
|
|
||||||
$response->getBody()->write(json_encode($createArgs));
|
$response->getBody()->write(json_encode($createArgs));
|
||||||
$challenge = $this->webAuthn->getChallenge();
|
$_SESSION['challenge'] = $this->webAuthn->getChallenge();
|
||||||
$_SESSION['challenge_data'] = $challenge->getBinaryString();
|
|
||||||
|
|
||||||
return $response->withHeader('Content-Type', 'application/json');
|
return $response->withHeader('Content-Type', 'application/json');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function verifyRegistration(Request $request, Response $response)
|
public function verifyRegistration(Request $request, Response $response)
|
||||||
{
|
{
|
||||||
$challengeData = $_SESSION['challenge_data'];
|
|
||||||
//$challenge = new \lbuchs\WebAuthn\Binary\ByteBuffer($challengeData);
|
|
||||||
|
|
||||||
global $container;
|
global $container;
|
||||||
$data = json_decode($request->getBody()->getContents(), null, 512, JSON_THROW_ON_ERROR);
|
$data = json_decode($request->getBody()->getContents(), null, 512, JSON_THROW_ON_ERROR);
|
||||||
$userName = $_SESSION['auth_username'];
|
$userName = $_SESSION['auth_username'];
|
||||||
|
@ -171,10 +167,10 @@ class ProfileController extends Controller
|
||||||
$attestationObject = base64_decode($data->attestationObject);
|
$attestationObject = base64_decode($data->attestationObject);
|
||||||
|
|
||||||
// Retrieve the challenge from the session
|
// Retrieve the challenge from the session
|
||||||
//$challenge = $_SESSION['challenge'];
|
$challenge = $_SESSION['challenge'];
|
||||||
|
|
||||||
// Process the WebAuthn response
|
// Process the WebAuthn response
|
||||||
$credential = $this->webAuthn->processCreate($clientDataJSON, $attestationObject, $challengeData, 'required', true, false);
|
$credential = $this->webAuthn->processCreate($clientDataJSON, $attestationObject, $challenge, 'required', true, false);
|
||||||
|
|
||||||
// add user infos
|
// add user infos
|
||||||
$credential->userId = $userId;
|
$credential->userId = $userId;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue